ESPresense and Home Assistant – The Adventure Continues

Home Assistant main screen

To avoid repeating myself, look at other articles in here where I realised that Home Assistant was for me to be the successor to my long-cherished Node-Red-based home automation system (especially as they’ve now formally discontinued support for my beloved NR-UI v 1). Little did I realise just how much farther I’d take HA now I don’t have to do all the heavy lifting (thanks Claude AI – my new deeply flawed technical assistant).

The article is about this week’s successes with Home Assistant, ESPresense and Claude AI. I hope you find it interesting.

To cut to the quick, while waiting for some BT beacons, tiny ESP32 boards and a new Smart Band (Mi 8) to arrive from AliExpress, I’ve been having a play. What I wanted was person detection in my living room and Office. I’ve just added bedroom with more to come, second person etc., but that’s just a detail and having gotten the detection working in ESPresence and Home Assistant, the next step was what to DO with that. Oh – Xiaomi Mi 7 – you have to turn advertise on and kill the random MAC addressing – 2 button presses.

LEDs on ESP32

But what to do with that? I stumbled on the reality that my Atom Lite (ESP32 and hence Bluetooth) board has a single RGB serial LED which can be accessed in ESPresense (not in the documentation online but in the actual downloaded code). It turns out that the GRB (not RGB) option is the one I needed – so then I took my generic ESP32 board (livingroom) and added a single RGB serial LED from a strip – straight onto a GPIO.

M5Stack atom Matrix

Stop press: I just found my M5stack Atom, Matrix. Read about this further down.

Here I describe what I’ve done with the code: Having powered the two ESPresense devices (a large ESP32 NodeMCU module (all I had handy) and the tiny, neat M5Stack Atom Lite (beware of Amazon pricing for the latter – it’s a complete RIP – even M5STACK charge a FRACTION of the Amazon price), Home Assistant magically became aware of “sensor_petes_mi” (I just called the device “Petes Mi” and depending which of the ESP32s my wrist was nearest (bench testing) would return the name of the “office” ESP unit or the “livingroom” unit – or “not_home” etc. Adding another person in is just a matter of degree – no more than that.

So what to do with that (yes I know I’ll have to do more than just light something up but this is good enough to prove the point)?

Not expecting it to work first time I fired the following EXACT question at Claude AI:

“In Home Assistant write a simple automation: if sensor.petes_mi = “office”, set light.espresense_office_led_1 to 100% green else if if sensor.petes_mi = “livingroom”, set light.espresense_office_led_1 to 100% red else set light.espresense_office_led_1 to off”

Yes I’ve just spotted the two IFs in a row – thankfully Claude AI was sharp enough to realise what I wanted and here’s what it fired back at me… no editing or changes.. it even came up with the title for Home Assistant. Amazing – and you know what… IT WORKS.

alias: Pete's Location Indicator
description: "Change office LED color based on Pete's location"
trigger:
  - platform: state
    entity_id: sensor.petes_mi
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: sensor.petes_mi
            state: "office"
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.espresense_office_led_1
            data:
              rgb_color: [0, 255, 0]  # Green
              brightness: 255
      - conditions:
          - condition: state
            entity_id: sensor.petes_mi
            state: "livingroom"
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.espresense_office_led_1
            data:
              rgb_color: [255, 0, 0]  # Red
              brightness: 255
    default:
      - service: light.turn_off
        target:
          entity_id: light.espresense_office_led_1
mode: single

And to prove the point I’m including a short video I made for you.. This was fun.

I am SO SICK of useless IR detectors turning off my lights every time I sit still writing for 15 minutes (my chosen timeout) – as soon as this is fully tested and we have the other Mi band so my wife can have hers back – this new person sensing is going IN and the IR sensors are coming out.

M5Stack Matrix

I imagine my wife or I coming into my office, lights, monitors, aircon ON – the cats coming in (as they do, frequently) – NOTHING. I can’t wait.

I’ve just added in the “bedroom” SPresense device – a handy M5Stack Matrix I’d forgotten all about – I’ve shown a stock photo of the Atom Matrix further up. Ok, ESPresense and HA can’t control the individual LEDs, but CAN turn the lot on and off (any colour you like, any brightness) this just keeps getting better.

No box needed – something like 22 Euros from AliExpress all in – but having wasted ages trying to scale then 3D print a base for an ESP32 NodeMCU board unsuccessfully… I’m tempted to get more of these pretty units. (Scaling failure was obvious in hindsight – scaling the box down also made the walls thinner – you can imagine the outcome).

Now all I have to do is adjust the BT sensitivity and position these units in the actual bedroom, livingroom and of course my office.

At the end of this I expect my office lights (on most of the time as I can’t work in natural sunlight) to turn off when I’m not in the office. As a fallback in case I leave the Mi band 7 in the office on charge, I also have HA phone detection which turns everything off when neither of us is at home.

One thought on “ESPresense and Home Assistant – The Adventure Continues

Leave a Reply

Your email address will not be published. Required fields are marked *

Leave the field below empty!


The maximum upload file size: 512 MB. You can upload: image, audio, video, document, spreadsheet, interactive, text, archive, code, other. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here