ESPHome room presence detection with Bermuda BLE Trilateration
Room-based location detection lets your smart home know exactly who is in what room, which you can use to trigger bespoke automations. For example, depending on who is in a room and their preferences, you could automatically show different photographs on a smart display, play different music on the smart speakers, or set the thermostat to a person's preferred temperature.
In my previous smart home I used a platform called ESPresense, which used ESP devices to sniff out the Bluetooth addresses of my and my partners mobile phones. The phones were configured to transmit Bluetooth Low Energy (BLE) beacons at regular intervals, which ESPresence would listen out for. Based on the signal strength of each of these BLE beacons it could roughly determine which phone, and therefore which person, was in each room.
This worked great, but it had one major drawback: I had to dedicate a whole ESP32 device to running ESPresense. I use ESP32 devices all over my home to do various jobs, and these run ESPHome. I have Everything Presence One’s and Lites doing presence detection, I have an ESP32 bed sensor that detects if we’re in bed, and I’d like to be able to use these existing ESPHome devices to do the tracking alongside whatever other job they’re already doing.
Thankfully, you can achieve this using Bermuda BLE. Bermuda BLE is a HACS integration that lets you use some ESPHome Bluetooth Proxies to set up tracker nodes that you can place in each room. I’ve been using it for a while now and it’s been working great.
To use this in your smart home you will need:
Home Assistant with HACS installed
Some ESP32 devices that have Bluetooth support
The Home Assistant companion app installed on your Android phone or some sort of other Bluetooth beacon.
Installing the Bermuda integration
Bermuda is a HACS integration. You can install it by following by either using this button
Or by the instructions on the Bermuda GitHub page.
You should now be able to install the integration from the HACS Integrations page. If it’s not listed, press refresh or clear your cache.
You should now see Bermuda listed on your Integrations page and you can click Configure to add it.
Creating an ESP32 Tracker Node
Now that we have the integration installed, we can create our first ESP32 tracker node. For this you’ll need an ESP32 device and a USB data cable. I really like these M5 Stack Atom developer modules, because they come inside a case and are relatively affordable.
Plug it into your computer and go to https://web.esphome.io in either Chrome or Edge.
Click the Connect button and select the right device in the serial port popup.
Once it’s connected, click the Prepare for First Use link to install the default ESPHome firmware to the device.
When it's finished installing, you can use this link to connect it to your home Wifi network. Be aware that this usually needs to be a 2.4Ghz Wifi network.
Once you’ve connected it to your Wifi network it will hopefully be autodiscovered in your ESPHome dashboard. Click Adopt to bring it into your console so you can manage it and update the code.
Click the Edit button under the device you just imported so that we can add the bluetooth proxy code.
Simply paste this into the bottom of the ESPHome code that is already in place.
bluetooth_proxy:
You should now be able to install this new code to your ESP device by clicking the Install button on the top right. If everything worked correctly it should upload the firmware.
Now you can take this ESP32 device and plug it in somewhere near the center of the room you want to track presence in.
You can do follow these instructions again and again with other ESP devices until you have one in each room you want to track.
Make sure that you assign any of your Bluetooth proxy devices to an area in Home Assistant, as this is what Bermuda uses to determine the location of each beacon.
Lastly, you need to set up some BLE transmitters to track.
Home Assistant Companion App BLE Transmitter on Android
Like most people these days, I tend to have my mobile phone on me (or near me) at all times. It’s pretty reliable that I’ll be in whatever room my phone is in, especially for most use cases. The same goes for my partner.
We both have Android mobile phones, and we both have the Home Assistant app installed on them. This app can act as a Bluetooth Low Energy transmitter, which can be detected by your ESPHome Tracker nodes to determine what room the phone is in.
If you’re using an iPhone, there are options on the Bermuda BLE FAQ page. To turn on this tracking for Android, open up the Home Assistant mobile app.
BLE Beacon Tags
You can track the location of other objects, such as keys or pets, using BLE beacons like this one I bought on Amazon.
I really like its small size, the fact that it is waterproof, and that you can replace the battery when you need to. So many of these beacons don’t have replaceable batteries which I find terrible from an eWaste point of view.
This is roughly the same size as an Apple AirTag, and I’ve managed to put it on my dog's collar with a silicon tag holder that fits on the collar.
To track this beacon you’ll need to put a battery into it and use a BLE scanning app to find the MAC address of the tag itself. I use an Android app called LightBlue.
Open the LightBlue app and it will scan for all BLE devices nearby, and show you their signal strength in dBm. Higher the number (So -80 is lower than -40), the closer the beacon is to your phone.
You can use the filter tool to filter out weaker signals so the list is easier to navigate.
Tracking the devices in Home Assistant using Bermuda
Now that you have all your parts and items set up, you can start tracking the Home Assistant mobile app beacon, or the BLE tags, inside Home Assistant.
To add beacons to track, go to the Integrations page and click on Bermuda.
Here you can change some global options to tweak how Bermuda works, and select which devices you want to track.
Select the UUID and MAC addresses of the beacon devices you set up earlier
This will create new devices for each of these beacons.
You should now have a new Home Assistant device with the name you specified. If you put that BLE beacon or device near one of your ESP32 room tracker devices the Area entity should reflect the room it is detected in.
I highly recommend changing the name and entityID of your sensor entities to reflect the person or object you’re actually tracking, because the default is the UUID or MAC address and makes it a bit difficult to find when using in your automations.
Once you have everything dialed in, you should be able to see the entity changing as you move from room to room!
Bonus Tip: Template sensor that combines room and Device Tracker presence
The problem with the Bermuda sensor is that it switches to an Unknown state when it can’t detect what room you’re in, such as when you leave the house. To detect if I’m home or away I use a Device Tracker, which meant I ended up with two sensors for tracking myself. The BLE sensor for the room, and the device tracker for home or away.
I combined these into a single Template sensor, which I added to my configuration.yaml file, that shows the room I’m in if it knows, or the Home/Away status in case it doesn’t. This means I can put one clean sensor on my dashboards that shows if I’m away or home, and if I’m home the room I’m in.
template: - sensor: - unique_id: "alan_location" attributes: friendly_name: "Alan's Location" entity_picture: "/local/img/alan.jpg" state: >- {% if states('sensor.alan_current_room') != 'unknown' and states('sensor.alan_current_room') != 'unavailable'%} {{ states('sensor.alan_current_room') }} {% else %} {{ states('person.alan').replace('not_home', 'Away').title() }} {% endif %}