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. Little did I realise just how much farther I’d take the idea now I don’t have to do all the heavy lifting. You’ll also see if you go looking that I’ve been tinkering with ChatGPT4 and now Claude AI to get some help with coding – with mixed results.
The article is about this weekend’s complete success 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’ll eventually add bedroom, 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.
But what to do with that? I stumbled on the reality that my Atom Lite 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 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.
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 a tiny, neat M5Stack Atom Lite (beware of Amazon pricing for the latter – it’s a complete RIP – 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”. 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 wit 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 if I sit still writing for 15 minutes – as soon as this is tested and we have the other band – it’s going IN – IR sensors coming out.
My wife or I come into my office, lights, monitors, aircon ON – if the cats come in – NOTHING. I can’t wait.
Just added in “bedroom” – a handy M5Stack Matrix I’d forgotten all about – I showed a stock phot 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 3D print a base for an ESP32 NodeMCU board unsuccessfully… I’m tempted to get more of these pretty units.
![Share on Facebook Facebook](https://tech.scargill.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/48x48/facebook.png)
![Share on Twitter twitter](https://tech.scargill.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/48x48/twitter.png)
![Pin it with Pinterest pinterest](https://tech.scargill.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/48x48/pinterest.png)
![Share on Linkedin linkedin](https://tech.scargill.net/wp-content/plugins/social-media-feather/synved-social/image/social/regular/48x48/linkedin.png)