I recently installed a Wink Relay in my office and “hacked” it to work with Home Assistant. This completed one of my home automation goals: all of my office’s lighting and its ceiling fan are accessible to Home Assistant for automating tasks.
Ever since first installing up Home Assistant, I’ve been wanting to automate turning on my ceiling fan. I very easily threw together this Node-RED flow. On each update of the temperature from office’s Zooz 4-in-1 sensor, it will use the temperature to decide whether to turn the fan on or turn it off.
There’s a shortcoming with this flow, though. Turning on a fan doesn’t lower the temperature in the room, it only makes it feel cooler thanks to the evaporative effect of air moving over your skin. The only time this automation would be beneficial was if someone (me) was already in the room.
Room-Specific Presence Detection in Home Assistant
Thanks to the Home Assistant iOS App and the GPS features in my iPhone 12 Pro Max, my Home Assistant installation has a pretty good idea of when I’m home. For the longest time, I’ve used this as a condition to either turn the lights on or off inside my office.
But my phone doesn’t necessarily know what room I’m in. I don’t think the GPS is accurate enough, and I definitely don’t want to try and figure out the GPS coordinates for the boundaries of each of the rooms in my house. This is problematic, but even more problematic is the fact that my phone isn’t always near me. I routinely leave my phone in other rooms as I nomadically wander around my house during the day.
I was in need of an easier—and better—method to implement room-specific presence detection inside Home Assistant.
Thanks to a reply to one of my tweets from @HolgBarath, I learned of the existence of the project, ESPresense. After it caught my attention, I took a look at the ESPresense website, the ESPresense GitHub repository, and watched a few videos on YouTube. I immediately knew that I wanted to give it a closer look.
What is ESPresense? On their website, they say it’s “An ESP32 based presence detection node for use with the Home Assistant mqtt_room component for localized device presence detection.”
ESPresense accomplishes its goal by providing an interface to easily flash their firmware onto an ESP32 development board, which enables the ESP32 board to monitor nearby Bluetooth low-energy devices. Scatter a few of those ESP32 devices across your house and set up the Bluetooth device(s) in Home Assistant you want to track and you’re ready to unlock the room presence achievement!
I have two Bluetooth devices that are pretty much attached to me all the time: my Apple Watch SE and my Medtronic 770G Insulin Pump. Of those two devices, I figured the watch was the better device to use ESPresense to track.
Brian implements ESPresense at home
I am relieved to report that setting up ESPresense was easy enough and well-documented enough that I don’t think there’s much need for this blog to turn into a how-to guide. The ESPresense install page has all the information you need to get started, including Everything Smart Home’s excellent video on ESPresense embedded in the page.
The software prerequisites for ESPresense are pretty straightforward. I already had my own functional Home Assistant installation, which includes a MQTT server. For the hardware, I decided that I’d use the following hardware to build my ESPresense base stations:
- D1 Mini NodeMCU ESP32 ESP-WROOM-32 Development board (5 pieces) ($34.99)
- UorMe 1A 5V Single Port USB Power Adapters (6 pieces) ($10.96)
- Spater 6” Micro USB Sync Cable (5 pieces) ($7.98)
- MH-ET Live D1 mini ESP32 Case
Altogether, I wound up spending $60 and some time on my 3D printer to add Bluetooth tracking to 5 different rooms in my house. I definitely could’ve done it cheaper too. I didn’t really need all the USB power adapters or cables, as I probably have plenty of both stashed somewhere in the house.
Flashing ESPresense onto my ESP32 boards was a snap from their Install page. Their website allows you to flash the ESP32 with the latest version of ESPresense from right inside the browser and to open a serial terminal connection to the ESP32 after it is done flashing.
For the most part, everything went as smoothly as I expected from the documentation. I thought I’d share a few things that I encountered along the way that might have made it even smoother.
Bluetooth Chatter: I have a lot of Bluetooth devices in my office: my insulin pump, watch, phone, work laptop, personal laptop, smart speaker, etc.. Figuring out the Bluetooth details to create the sensor in Home Assistant wound up being a bit of a challenge. I used a couple different methods to try and sort that out.
- MQTT Explorer, connected to my MQTT server on Home Assistant, and monitored the espresense\devices topic.
- Took my laptop, watch, and an ESP32 board to a room with no BLE devices and used the ESPresense Terminal to determine the Bluetooth IDs
- Bluetooth Scanner Apps were recommended a couple different places, and I expected them to be helpful. But I didn’t exactly find them to be especially useful—but everyone’s mileage may vary!
ESPresense’s very active development and automatic updates: By default, the auto-update feature is enabled on the ESPresense base station. It is also a very active project on GitHub. The combination of these two factors might occasionally work against you. On the day I was setting everything up for the first time, a release happened that caused my ESP32s to repeatedly crash and be quite unreliable. I wound up disabling the auto-update and using the ESPHome-Flasher to flash an earlier, more stable, version.
Each base station required calibration: This should be expected—especially in areas of the house where there were base stations near each other. I had to fine-tune each base station’s Maximum Distance to Report (in meters). It’s good to point out that this is an approximation based on the Bluetooth signals RSSI (Received Signal Strength Indicator). I ended up using Home Assistant’s developer tools to monitor the state and attributes of the sensor I created while I walked around each room.
When it was all said and done, I had ESPresense base stations in my office, the master bedroom, the living room, and our dining room.
What about that Ceiling Fan Automation?
Incorporating presence condition into the automation was a snap! I wound up adding a node to that flow to check which room ESPresense detected my watch was in. In order for the fan to get turned on in my office, two conditions would now need to be met: the temperature would need to be over 75 degrees and my watch would need to be nearest to the ESPresense base station in my office.
We had a rather warm day last week, and the automation worked great. I was working on writing this blog and noticed that the fan turned on. As the day progressed, I wandered in and out of my office to do other tasks. It was awesome to see that the ceiling fan was on when I was in the office—but off when I was somewhere else.
I enjoyed implementing ESPresense enough that I went ahead and ordered another 5-pack of the D1 Mini ESP32 boards. I don’t necessarily need them, but I like the idea that we could have ESPresense base stations in every room in our house. Adding presence detection in Home Assistant for about $12 per room is a tremendous value!
Reliable room-based presence detection is going to open the door for creating better automation that hasn’t been available to me before:
- Motion detection and room presence to turn the lights on in my office, keep them on, and turn them off shortly after I leave the office.
- Create new automation to automatically turn off the lights in my office when it’s empty
- Using my iPhone’s charging status and room presence in the bedroom to deduce whether I’m in bed.
- Personalize automations for other members of the household.
What other kinds of ideas am I overlooking? If you had presence detection enabled in your smart home, what kind of Bluetooth devices would you use for presence detection? What kind of tasks would you automate using presence detection? I’d love to hear what you think; share your ideas in the comments below!