[monitor] Reliable, Multi-User, Distributed Bluetooth Occupancy/Presence Detection

Hi,

Thanks for making this project, appreciate the effort you’ve gone to.

I’m just trying to work out the best way to implement this into my home automation system. I’ve got a raspberrypi and my home assistant server running on a NUC, I have bluetooth on both of them and have set up monitor on the raspberry pi and bluetooth presence monitor on home assistant.

I’ve put the raspberrypi in the garage and envision using my front motion sensor to trigger arrival scans (and I guess I can’t really have it triggering depart scans as well?) My goal is to consistently open my garage, unlock the door and turn on the garage light when we pull into the driveway. I can do this now with location tracking but it is too inconsistent, and using wifi connection for home presence detection is also a bit inconsistent.

So what are the recommendations for setting this up? I have my iphone, apple watch and my wifes iphone and apple watch on both machines detecting presence, I’ve tried setting up a bluetooth tile but am not having any luck getting the confidence level > 0, so have just shelved that idea for the minute and will focus on getting the phones/watches working.

What ‘extra-parametres’ should I be running on each machine. How do I make the pi default to the extra parametres?

Sorry for the long post!

Yes! I need this too.

Hi,

I have some issues setting this up here. Following scenario : I have a long driveway. The idea is to have two Pi Zero W’s, one at each end of the driveway. Each of our cars here have a USB BTLE beacon connected to the cars USB port and set to a rather low tx power. Leaving or arriving is then determined by signal detection order by the two Pis. I’m only interested in tracking beacons, no phones or similar. Right now I’m trying to set this up with one Pi and a beacon sitting on my desk here.

  1. I start monitor with the V and b flags. PREF_BEACON_EXPIRATION is set to 30 secs. PREF_MINIMUM_TIME_BETWEEN_SCANS is set to 5 seconds. I need pretty high frequency scans, so that the system doesn’t miss the beacon signal from a car passing by. When I plug in the beacon, it is detected and a mqtt message is sent, confidence 100%. Good. However, shortly before the beacon expiration time is reached (30 secs), several messages are sent with decreasing confidence, to reach 0 confidence after roughly 30 seconds. Then a few seconds later, another message is sent with 100% confidence again, as if the beacon was newly detected, only to reach 0% confidence after 30 secs again. This repeats indefinitely. During all this time, the beacon is sitting happily next to the Pi on my desk, sending its advertisements. I tried the r option too (I added the beacon mac to known beacons), but it does not change anything.

  2. I would like to do only passive scans for the beacon advertisements, so to avoid interference on high scan frequencies. No name requests, or any kind of active communication with the beacon. Basically like the --passive option on hcitool. How can I configure this ?

Thanks a lot for your help !

I’ve been trying to figure that out as well.
That’s the main reason I wanted this, but I cant seem to find how to automatically populate the known_static_addresses, or otherwise.

same here, did you figure it out?

Everybody, have a look at the new appdaemon app Monitor-App
Makes monitor a lot better with auto-reboot if connection lost, devices can appear in HA as device_tracker etc

2 Likes

I’ve just recently moved my HA instance onto a NUC, and repurposed the RPi to be one of my Monitor nodes. I added my phone and the wife’s (both iphones) to the known static list, and additionally registered both for rssi readings.

Both phones work flawlessly for the confidence level detecting. And my phone works for the rssi feed. But the wife’s rssi feed works only while near the node, and as soon as she leaves the house, I see the rssi strength dropping, then it shoots back up to -99dBm when signal is lost (but confidence shows 0 correctly), and stays there until she returns home.

I’ve removed her address and re-added it but it doesn’t resolve it.

Any ideas?

Per the docs, -99dBm is what monitor will report when the device is not present and an RSSI value cannot be obtained.

So, when my iphone is closer to the RPi, I get closer to -100 dBm. Further away it is, I get closer to 0 dBm? Correct? So if there is no signal, device not present (I’m not home), -99dBm is used…hence indicating I am close to the RPi? So I need to use the confidence level in conjunction with the rssi value…

No, it’s the inverse. Note that the bluetooth hardware reports a negative value. The closer the RSSI is to zero, the closer you are to the BT hardware. The farther you are away, the “more negative” your number will be.

Really appreciate your time on this…I am not observing that. If you look at the attached screenshot.

  • The ‘top’ of the graph between midnight and 8am, is when I am in the bedroom which is one floor above the Monitor node.
  • 8am-9am is in kitchen…about 5m away.
  • After that I am in the study, within 3 feet of the Monitor.
  • That blip at 10am is when I moved our car.
  • At 11am is when I was in the garage, 10+m away.
  • From 11:30am - 12:30 I was back in study on a conference call.

So for me I get -99 when closer to the Monitor and towards 0 when further away. Is there a setting somewhere I got wrong?

As I wrote in the docs, RSSI is not a very reliable measure of distance. The reverse is also true - your distance to a monitor node is not a good predictor of RSSI. There are certainly some bugs to work out, but your -99s on the graph show when monitor cannot read an RSSI from your phone, whether you’re physically near or not.

Ok, understood. I’ll think I will add a PIR to the RPi in that room instead and use that for presence.

Hi, I installed the script on pi w zero with dietpi . Initially it works but after an hour or two I have no update on home assistant. What could be?
If a do a reboot it works again

There are a few open issues that may relate to this. I’m working them through trying to debug.

So i have been running monitor for a week now and its a hit and miss for me.
Setup:
Hassio on ubuntu server host
Pi Zero W with rasbian buster lite with Monitor installed trough the github installation page.

Run Monitor with sudo bash monitor.sh -tad -u and it picks up the devices i added to: known_static_addresses. Use HA device tracker route and get a nice tracker in HA to use with my automations.

So technically its working perfectly… Until i reboot my HA host… Now it looks like my automation cant trigger the mqtt arrive/depart message I got running in an automation used with my front-door sensor.

Automation:

  - alias: Monitor - Door Scan
    trigger:
    - platform: state
      entity_id: binary_sensor.xiaomi_door_sensor_1
      to: 'on'
    action:
      - service: mqtt.publish
        data:
          topic: monitor/scan/arrive
      - delay:
          seconds: 120
      - service: mqtt.publish
        data:
          topic: monitor/scan/depart

Devtools - mqtt and doing a manual monitor/scan/arrive or monitor/scan/depart doesn’t work neither.

Only way i can fix it is running the sudo bash monitor.sh -tad -u command on the pi zero again.

Any tips to fix this? I want it to scan when the front door opens and when HA restarts.

caaa is at {"id":"FC:58:RA:1B:28:B4","confidence":"0","last_seen":"1583500481","retained":"false","timestamp":"Fri Mar 06 2020 13:15:57 GMT+0000 (GMT)","version":"0.2.200"}

Just a query about the device_tracker preference, seems a bit odd to me, doesn’t seem to be working? Have I possibly given the config file the wrong topic?

asdasdas

I have installed Monitor on a RPi3, it is pushing messages to my MQTT broker which i have setup in a docker, however it appears that home assistant is not discovering the devices and adding them into the system. anyone run into this or have any suggestions?

I don’t believe monitor supports mqtt discovery. You will have to add them manually.

You can try my app @greenspace10 Home (Monitor) Presence App V2