Today we are going to the next level of smart home presence detection by start tracking the room occupancy with great accuracy.
For that I will use the Bluetooth of a phone and a smart watch, Raspberry Pi and Room Assistant.
Table of Contents
Why you need Presence Detection?
The presence detection or the possibility to know “is anybody home” is crucial for a real Smart Home.
Base on that you can start a lot of really cool automations.
When you come back from work – to automatically unlock the doors, to turn the lights and TV on, to start the heating or cooling and respectively turn off and lock everything when you leave.
But imagine the following scenario:
You have a good WIFI signal and you get connected to your home network from across the street. So you will need a minute or two until you actually enter in your home.
In that case you will have to delay your Automation on purpose to catch the right moment and to hear the greeting from your Smart Speaker for example.
However you can first enter in different room like the bathroom and you will miss the whole magic.
The solution is Room-Assistant
To make this the right way I will hit the Subscribe button and then I will show you how to use room-assistant which is actually a really cool project that helps you track devices using the following integrations:
- Home Assistant (using MQTT),
- Bluetooth Low Energy,
- Bluetooth Classic,
- Omron D6T,
- GPIO (PIR motion sensors)
What you will learn?
I will quickly show you how to Install Room Assistant using Home Assistant Add-on Store. This method is great if your home assistant is installed on a Raspberry Pi.
Both ways are pretty easy.
Then I will show you how to configure Room Assistant and Home Assistant.
And at the end we will create an automation that will start the lights when you got home.
Apart from your phone or your smart watch you will need one or more raspberry pi version 3, 4 or Zero W now let’s go.
Room Assistant in Home Assistant
If you still don’t have Home Assistant and MQTT broker go check this tutorial of mine and then come back here.
Go to “Supervisor” menu in your Home Assistant and then choose “ADD-ON STORE“.
After that simply paste the URL in the “Add new repository by URL” field and click the “ADD” button
URL to paste:
Search for “Room Assistant” and install the Add-On. Be careful not to install the beta here, unless you know what are you doing.
After you see this screen you can continue to the configuration part.
IMPORTANT if you have issues finding your devices in Home Assistant you should enable MQTT auto discovery in your MQTT section within configuration.yaml file like so:
mqtt: discovery: true
Configuring Room Assistant on one host
I will focus on the Bluetooth Classic and Home Assistant, because I think that these are the most popular integrations.
Scroll down until you see the Config section of the Room-Assistant and paste the following configuration (of course you can adapt it to your needs).
global: instanceName: livingroom integrations: - homeAssistant - bluetoothClassic homeAssistant: mqttUrl: 'mqtt://YOUR_MQTT_BROKER:1883' mqttOptions: username: YOUR_USER password: YOUR_PASS bluetoothClassic: minRssi: -20 hciDeviceId: 0 addresses: - '01:02:03:04:05:06' - '06:05:04:03:02:01'
Probably you wish to change the instanceName with something that is more suitable for you (this is the room name).
As well as the mqttURL with username and password and definitely the addresses. The addresses should the be the Bluetooth MAC addresses of the devices that you want to track.
The only thing left to do is to scroll up and click the “START” button.
If there are no errors in the logs you can freely continue to the “Configuration” and then “Integrations” menus of the Home Assistant.
Here in MQTT section you can add your devices as Home Assistant sensors.
You should see here your devices that you configured earlier by typing their Bluetooth Mac addresses in the Room-Assistant configuration section.
Click on them and Add them to Lovelace
If everything is ok you should see something similar as below at the end:
You can test if everything is working by disabling the Bluetooth of the device and your sensor should become in “not_home” state.
Quick Hint: you can enable the “Flight Mode” if you have such, which will disable all of the device communications.
Question for You!
I have a quick question for you: What are you currently using for presence detection in your smart home? And if you still don’t have anything are you going to try Room Assistant?
Installation of Room-Assistant using Docker
You can use Docker to install Room-Assistant. To do that execute the following commands (assuming you are using Raspberry Pi).
Create a new folder for room-assistant configuration file.
mkdir -p ~/room-assistant/config
Then create the config file named local.yml using this:
paste the Room-Assistant configuration inside it (for example as described above) and save the file.
Then create a docker compose file by executing the following:
Paste this config inside the file:
version: '3' services: room-assistant: image: mkerix/room-assistant restart: unless-stopped network_mode: host volumes: - /var/run/dbus:/var/run/dbus - /home/pi/room-assistant/config:/room-assistant/config
The final step is to execute the docker-compose up command like so:
You should now check the logs for errors and if there aren’t any BIG RED ones you are good to go.
Creating a cluster of two Raspberry Pi
If you have more than one Raspberry Pi devices you can create a Room-Assistant cluster.
In that way you can detect where exactly in your Home is your tracked device. You need to place your Raspberries in different rooms.
This is actually the real beauty of this project. So let’s try it.
Room-Assistant cluster configuration
Add the following configuration on the first Raspberry PI (code name: corridor)
global: cluster: autoDiscovery: false port: 6425 peerAddresses: - 10.0.0.22:6425 instanceName: corridor integrations: - homeAssistant - bluetoothClassic homeAssistant: mqttUrl: 'mqtt://YOUR_MQTT_BROKER:1883' mqttOptions: username: YOUR_USER password: YOUR_PASS bluetoothClassic: minRssi: -20 hciDeviceId: 0 addresses: - '01:02:03:04:05:06' - '06:05:04:03:02:01'
On the second Raspberry PI (code name: livingroom) add the following configuration.
global: cluster: autoDiscovery: false networkInterface: eth0 port: 6425 peerAddresses: - 10.0.0.2:6425 instanceName: livingroom integrations: - homeAssistant - bluetoothClassic homeAssistant: mqttUrl: 'mqtt://YOUR_MQTT_BROKER:1883' mqttOptions: username: YOUR_USER password: YOUR_PASS bluetoothClassic: minRssi: -20 hciDeviceId: 0 addresses: - '01:02:03:04:05:06' - '06:05:04:03:02:01'
Don’t forget to change the following things with yours if needed: networkInterface, instanceName, mqttUrl, username, password and addresses.
Restart your Room-Assistant instances and give them a good test like this one below.
I’ve added my devices that I wanted to track let’s create an automation in Home Assistant.
Automation based on Room Assistant sensors
Add the following lines to your automations.yaml file in Home Assistant config folder:
# presence detection with room assistant - id: '1574110134678355' alias: Lights ON when I got home description: 'When Im home' trigger: platform: state entity_id: sensor.YOUR_DEVICE_HERE from: not_home to: corridor action: - data: entity_id: light.YOUR_LIGHT_HERE service: light.turn_on - data: entity_id: light.YOUR_2ND_LIGHT_HERE service: light.turn_on
The things that you should change are the entity_id with your Room Assistant sensor and the light switches.
Now when you go from ‘not_home‘ to ‘corridor‘ the lights should automagically turn on.
Support my work:
Any sort of engagement on this site or my YouTube channel does really help out a lot with the Google or YouTube algorithms.
So make sure you hit the subscribe, Like and Bell buttons If you enjoy this video.
Also feel free to add me on Twitter by searching for @KPeyanski.
I really hope that you find this information useful and you now know how to accurately track who is home using Home Assistant, Raspberry Pi and Room Assistant.
Thank you for watching/reading, stay safe and see you next time.