One of the key differences between a smart home and a home with smart devices is automation. When smart homes are done poorly, you can tell because people are using their smart phones to turn on a light when the switch is more convenience, or worse yet, if you use the switch the light is no longer smart.

However…

I’m somewhere between the two states. Automating lights is hard when you only want a light on when someone is in the room; how do you know someone is in there without them telling you? You can do motion sensors, and in the right setting it works well. Like our walk-in closet; we’re using an Ikea Tradfri smart bulb and motion sensor. When you open the door, the light comes on. When there isn;t motion for 1 minute, it turns off. The caveat is that the switch must always be left on, a training exercise that was frustrating to say the least. It is also annoying that when you don’t want to light to turn on, like when your partner is still sleeping, you don’t really have any options other than partially opening the door and awkwardly flicking the switch off before the motion sensor triggers.

All that said, I’m not looking to fix the closet situation right now, but would like to start laying the ground work for presence detection on the room scale. To do that, I’m looking at the MQTT_room integration in Home Assistant. On it’s own this doesn’t do anything, we need something to report status to this integration. For that, we have a few options:

  1. Room Assistant
  2. Happy Bubbles
  3. ESP32-MQTT-room
  4. Custom Software

I’d like to avoid writing my own software if possible, so I’m going to start with Room Assistant since it can run on a Raspberry Pi and I conveniently have one mounted to the wall by my front door acting as a dashboard. I do plan to try out ESP32-MQTT-room as well, especially because the ESP32 boards are super small and cheap, which is a must if we realistically want to track rooms throughout the house. But if I already have a Pi in a room, might as well use it.

Room Assistant

Aside

The instructions on the GitHub page look decent for building the server from scratch, but I’d rather use docker; in which case the documentation isn’t fool proof. I set out to use docker-compose, because I like the way your configuration lives in the docker-compose.yaml file. that way if you need to kill the container and create it again, you have everything you need still. Whereas when you run it straight from docker, you put your configuration settings in the command line. So if you need to kill the container and create it from scratch, you need to enter the full command rather than “docker-compose up”.

That being said… I got lost in debug land trying to get this working and ended up switching over to just using docker. I eventually got it working, but I’m not very happy with it at the moment. If I get it to do what I want, I might revisit docker-compose, but for now I’m writing this to just use docker.

Installation / Configuration

Before I can install room-assistant, I need to install docker. This is super easy if you trust running scripts from the web, just follow the first 3 steps from here.

Now I can create a folder for my docker project and set up some config files

mkdir room-assistant
cd room-assistant
mkdir config
cd config
nano local.json

Now paste the contents of the default.json file from the Git-Hub page and make any changes you require. Here is the baseline and afterwards is my final file.

{
  "services": [],
  "room": "default-room",
  "autoDiscovery": true,
  "mqtt": {
    "url": "mqtt://localhost",
    "username": "",
    "password": "",
    "rejectUnauthorized": true
  },
  "ble": {
    "channel": "room_presence",
    "useAddress": false,
    "whitelist": [],
    "whitelistRegex": false,
    "txPowerOverride": {},
    "maxDistance": 0,
    "updateFrequency": 0,
    "processIBeacon": true,
    "onlyIBeacon": false,
    "majorMask": "0xFFFF",
    "minorMask": "0xFFFF"
  },
  "d6t": {
    "channel": "d6t",
    "type": "D6T_44L_06",
    "interval": 500,
    "threshold": 21,
    "onlyChanges": true,
    "retain": true,
    "discoveryType": "binary_sensor",
    "discoveryConfig": {
      "name": "D6T Default",
      "payload_on": true,
      "payload_off": false,
      "device_class": "motion",
      "value_template": "{{ value_json.value }}"
    }
  },
  "gpio": [],
  "shell": [],
  "prometheus": {
    "port": "3030"
  }
}
{
  "services": [],
  "room": "entryway",
  "autoDiscovery": true,
  "mqtt": {
    "url": "mqtt://192.168.1.126:1883",
    "username": "",
    "password": "",
    "rejectUnauthorized": true
  },
  "ble": {
    "channel": "rooms",
    "useAddress": true,
    "whitelist": [],
    "whitelistRegex": false,
    "txPowerOverride": {},
    "maxDistance": 0,
    "updateFrequency": 5,
    "processIBeacon": true,
    "onlyIBeacon": false,
    "majorMask": "0xFFFF",
    "minorMask": "0xFFFF"
  }
}

Change your MQTT broker as required.

Now we can create the docker image and container. If you didn’t create the “room-assistant” folder in the “pi” user directory, update the following accordingly.

docker run --network=host --restart=unless-stopped -d --name  room-assistant -e SERVICES=ble,mqtt,console -v /home/pi/room-assistant/config:/room-assistant/config mkerix/room-assistant:latest-arm32

It takes a few minutes, but it should start working right away once it’s finished. To check on the progress, you can check the docker logs:

docker logs room-assistant

It should be filled with devices it’s seeing and how far away they are. If not, the logs will hopefully point out why it’s not working. The last line before the devices start showing up should say that it successfully connected to the MQTT broker.

If nothing is happening, you can remote into the container and see if it pulled in your local.json file.

docker exec -it room-assistance sh
room assistant# cd config
room assistant# ls -a

If you see a local.json file listed, it successfully pulled in your config folder.

Home Assistant

Room Assistant will report devices over MQTT using the channel/room as the topic, so in my example above they show up under “rooms/entryway”.

You can test that they’re coming through with the Developers/MQTT section by listening to the above topic.

Once you’re getting devices show up, you can take the IDs you want and put them into your configuration file as a sensor:

sensors:
  - platform: mqtt_room
    device_id: "XX:XX:XX:XX:XX:XX"
    name: Example device
    state_topic: "rooms"

This is actually really cool, because once you have your device set up for one instance of Room Assistant, it automatically works for the nest ones you set up in other rooms as long as you use the same ble channel.

Summary

Now that I have it setup, I’m kind of disappointed. What I wanted to happen was for Room Assistant to see my Garmin 245 running watch and report when I’m near one of those devices. Unfortunately when my watch is connected to my phone, it no longer advertises itself which is how Room Assistant sees it. So I can leave my watch unconnected to my phone and it’ll know where I am in the house, or I can keep it connected and get notifications.

I ALWAYS have my watch on, so this is disappointing since it seemed like such a great a simple solution, despite the trouble I had in getting Room Assistant set up. The next best option would be for Room Assistant to track my phone, I ALMOST always have my phone on me.

Unfortunately for this purpose, Android phones constantly rotate what they broadcast themselves as, this is to prevent businesses or other people from doing the same kind of thing and tracking you. However, you can download an app that will broadcast itself so that you can use it to track yourself. I tried the trial version of “Virtual Beacon” for this and it seems to work OK. Being the trial version, it only broadcasts for so long before it turns itself off, but that’s fair enough for testing purposes.

I’m not convinced I’m going to continue with this system just yet, but I wanted to at least document the process since it took a lot more effort than I was expected to get it sorted out.

There will either be another post on Room Assistant, or one on Find, or maybe both as I figure out which will work better for my goal of having a decent smart home rather than a home with smart stuff.

1 Comment

  1. Paul Malik

    Reply

    Hi,
    Thanks for this write up. It really cleared up a few things for me. The one thing I’m struggling with though, is setting up ‘mqtt_room’. I’m running core Home Assistant in Docker, and can’t for the life of me get a valid configuration. When I set up mqtt_room as you have in my configuration.yaml it is throwing an error: “message”: “Value is not accepted. Valid values: \”mqtt\”.”,
    I get the same error when I set it up in my sensors.yaml file too.
    I understand you may not be using room-assistant as you have indicated, but if you can shed some light I would appreciate it.

Leave a Reply to Paul Malik Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.