offset \ˈȯf-ˌset\ noun

a force or influence that makes an opposing force ineffective or less effective

Room-Level Presence Tracking

While ordering PC components, I also ordered Raspberry PI Zero 2 W. Ideally I'd have one more so I can have three and a proper Paxos distribution, but they are notoriously difficult to obtain these days. In the end I used my original PI 4 and Zero 2 W to create a two-node system for room level presence detection. The third one will have to wait so I might go for it this year if it turns available.

I installed Raspbian on the PI Zero 2 W and connected it to the network. Then I made the IP static on the router so it's not changing anymore. The same is done for the Raspberry PI 4, but in reality, all the devices that are our own have a static IP in the network. It's easier to address them and the configuration is not always catering to the dynamic ones.

The project I used was room-assistant and I installed it to both devices via Docker. PI Zero 2 W only has room-assistant, and the PI 4 has Mosquitto, Home Assistant and Room Assistant. The Room Assistant describes that you should have local.yml configuration and mine is as follows on PI 4:

global:
  instanceName: "Living Room"
  integrations:
    - homeAssistant
    - bluetoothLowEnergy
cluster:
  autoDiscovery: false
  weight: 2
  port: 6425
  peerAddresses:
    - <IP_v4 of the Raspberry PI Zero 2 W>:6425
homeAssistant:
  mqttUrl: "mqtt://<IP_v4 of the Raspberry PI 4>:1883"
  mqttOptions:
    username: <mqtt username>
    password: <mqtt password>
bluetoothLowEnergy:
  maxDistance: 20
  allowedlist:
    # bluetooth mac of the device you want to track,
    # for example, phone. There's a chance LE physical address
    # is rotated, if that's the case, you can go into
    # Home Assistant Android app, go under:
    # Settings -> Companion App -> Manage Sensors -> BLE Transmitter
    # and enable it, the format will be
    # UUID_WITHOUT_DASHES-major-minor
    - 112233445566

PI Zero 2 W has the same configuration file, but with a different instanceName (being in bedroom), weight of 1 so it's not picked as the leader if possible (the higher the number, the bigger the chance it will be the leader, and also that's why I'd like to have three devices at least - Paxos, remember), peerAddresses has the IP of the Raspberry PI 4, but the rest are the same as the configuration above. Be sure to change the values where they are required.

As for the Mosquitto, it's an MQTT broker that is coming recommended for Home Assistant use. Room Assistant detects a Bluetooth device, then sends a message to the queue. After that, the Home Assistant picks it up.

I am not very happy with the devices reporting their location. It would depend on the load of the device and the quality as well. I tried using bluetoothClassic integration at first, but switched to bluetoothLowEnergy because it was more accurate. Still, I think I might have to change the devices themselves since the signal drops, or investigate more into it to tweak the configuration. The walls will also affect this.

On the other side, once the Home Assistant picks up the integration, all that is left is to detect the presence. The integration makes sensors out of your devices, for example: sensor.fairphone_3_ble_room_presence. To get it into automations, it's the easiest to create the template automation trigger somewhat like this:

{{ is_state("sensor.fairphone_3_ble_room_presence", "Living Room") }}

When the above triggers the automation, the action can follow. For instance, turn off the lights in the other parts of the apartment, start home theater if it's evening, things like that... That said, I'll keep using it and see if I can improve on it.