Room-level BLE-based presence detection
One of the sought-after inputs into a well-functioning smart home is presence detection of people (and pets). Presence or absence of occupants is an important input for triggering (or not trigger) an automation. These occupancy-triggered automations save energy when they turn off lights and keep HVAC idle while everyone is away. They also kick off things that are better done while no one is around such as robot vacuum runs.
The least granular and most fundamental level of presence detection in a smart home home/away detection. This helps ensure that tasks described in the last paragraph don’t happen at the wrong time and annoy the inhabitants. If you haven’t already, you’ll probably want to set that up before incorporating the room-based system that is the contents of this post.
Beyond home/away detection, some smart home enthusiasts that want to take automation to the next level also want to track occupancy at a finer level. They want to know not only whether anyone is home, but also who is at home, and where in the home they are located. This is what this post is about. Room-based location detection allows for automation using more granular information about home occupancy.
Use Cases
You may be wondering about the use cases that are unlocked by deploying this type of a solution at home. Why would this be worth the effort? Here are a few scenarios where I use it today.
- Keeping lights from turning off when there’s someone in the room. One of the most popular automations is to manage lights using motion sensors, door open/close sensors and timers. This allows for lights to turn on when someone enters the room, and to turn it off after a prior of inactivity. However, motion detectors often fail to detect presence in places like offices where you may be sitting without much movement. Room-based presence detection can keep lights from changing states when there’s someone in the room.
Room-based presence detection can keep lights from changing states when there’s someone in the room.
- Keeping the lights from turning on when you walk into an occupied room. Light automation based on a motion alone will turn lights on when someone walks into a room, even if someone is already there. This makes automation on motion alone not ideal for bedrooms where someone may have lights off because they are sleeping. Room-based presence detection can add additional smarts to these types of automation routines by taking into account whether a room is already occupied before executing a routine.
- Additional signal for reducing false negative rates for home/away detection. Room-based presence detection provides yet another signal that prevents the system from flipping overall home occupancy to ‘away’. Since presence detection works best when there are different types of sources for occupancy information, this can make your home/away system even more reliable. This can help ensure that unoccupied tasks do not kick off when they shouldn’t.
The setup
The setup is fairly inexpensive and straightforward assuming you already have Home Assistant and an MQTT broker running. If you don’t have an MQTT broker running, you can easily spin one up as it is available as an addon that can run on Home Assistant OS. The documentation for the Mosquitto addon should be sufficient to get started. You’ll need an ESP32 for each node you want to set up. You’ll probably want to deploy 3-5 or even more depending on the size of your home, but you can certainly start with one to kick the tires.
ESPresense project provides easy-to-follow instructions on their install page. Once an ESP32 is flashed with ESPresense, you’ll provide each node with the Wi-Fi configuration, MQTT info and a few other pieces of information via a web-based configuration page while the device is initial AP mode. You can also make changes once the device is on your Wi-Fi by pointing your web browser to the device’s IP address.
Once configured, your Home Assistant sensor config might look something like this for each ‘tracker’ such as your smartphone or smartwatch:
- platform: mqtt_room
device_id: "iBeacon:80c5g842-ed62-436c-6217-02aba49t3fd4-100-1"
name: "My Smartphone"
state_topic: "espresense/rooms"
timeout: 60
away_timeout: 300
And for every ESP32, you can monitor it’s online/offline status with a sensor like:
- platform: mqtt
name: Office MQTT room
state_topic: espresense/rooms/office/status
json_attributes_topic: espresense/rooms/office/telemetry
payload_on: online
payload_off: offline
device_class: connectivity
The result
Once up and running with a configuration above, your Home Assistant dashboard could be setup to show something like this:
At this point you can now incorporate these new sensors into your automations and make your smart home even smarter.
Projects used
- Home Assistant (Website, Repository) – The ‘brain’ behind my smart home and one of the larger open projects out there
- ESPresense (Website, Repository) – An open-source presence detection node for ESP32 + Home Assistant’s ‘mqtt_room’. Based on ESP32-mqtt-room.
- Eclipse Mosquitto (Website, Repository) – An open-source MQTT broker from the Eclipse Foundation.