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

We are running monitor with 3 nodes, 1 with -tadr and 2 with -tad. All monitor nodes will report only home and not_home. All monitors are part of Person component with nmap presence detection. We have 3 doors leading to outside, so any door opening will trigger automation publishing depart script publishing to mqtt. Also, if nmap reports not_home for 15 seconds, automation will be triggered to run a script publising depart scan with (and if nmap changes from not home to home, arrival script is run). This gives us about 30 seconds delay leaving the house before we are reported as not_home (yard is quite big, so monitors will report not_home long before nmap does, but nmap will keep us home if we are home, but at yard). Coming home is about 15 seconds delay (nmap detects us first) and nmap detects us home from parking lot. As a backup I have automation running every 30 mins, scanning arrive + depart from monitors (if one of other scannings fail for some reason).

With this setup we are getting reliable precense detection. It is a bit of hack and it is not as fast it could be, but it works for us. Only using monitor, we had a lot of false not_home reports, also we were reported not home when at yard, so motion sensors for cameras etc were on, it was not good for us. Only using nmap we were also reported not_home, when phone was not connected to wifi for some reason. With -r flag our Neato vacuum and all monitor nodes were offline most of the time (too much interference to 2,4 ghz wifi) so I had to rethink the system. My phone is OnePlus 6 and wife has 5t (so only periodical scan or manually triggered will work).

1 Like

Been using Monitor for a week or so now I have a Pi3 and a Pi zeroā€¦Main floor and Basement. Im using as a peson home presence not room presence. For the most part its working but im noticing that it sometimes just stops scanning or not responding. Like example, I woke up this morning, im sitting in the same room as the pi3 and it shows me 0% confidence. Watching the mqtt activity nothing is happening untill I run the mqtt restart command.

Looking at the docs on guthub Im wondering in my case should I be using the -r flag to constantly monitor the area? Is it fine to use on both devices? I using my unifi aps as presence detection but plan to use all sensors in a bayesian sensor. As of right now Im not fully confidant using it with monitor. Any ideas or tips?

I just have finished the installation of monitor.sh on my seperate pi. But I am lost what to do next to get it integrated into home assistant. The target I want to achieve is to know when one of my family enters the room where the PI is. Only thing I configured is the mqtt config on the bluetooth pi so far. Any tips are welcome. I am very new in mqtt/home assist integration. So I dont know what exactly I have to do now.

" When I run sudo bash monitor.sh -b none of my iOS devices are showing up in the scans, though several items say they are are apple devices. I ran the following using my iPad MAC address
hcitool name 88:AE:07:79:FF:A0
And it returned iPad . I suppose I should add my devices to known devices, but why isnā€™t this and my other devices showing up with the monitor command? Where are the MAC addresses that are showing up in -b coming from?"

Hey, did you ever solve this? I think Iā€™m running into the same issue. name call returns the name, but no iOS devices are showing up in the scan/on MQTT. I can get the neighborā€™s AppleTV and Samsung TV, but not my iphone.

Thanks!

The usual way is to follow the instructions GitHub - andrewjfreyer/monitor: Distributed advertisement-based BTLE presence detection reported via mqtt

The usual way is to follow the instructions GitHub - andrewjfreyer/monitor: Distributed advertisement-based BTLE presence detection reported via mqtt

yeahā€¦Iā€™m pretty new to this whole thing too and I can attest to what lweberru is saying. The instructions are great, up to a point and then itā€™s pretty confusing and assumes a lot of knowledge on the part of the user. Not that this kind of thing isnā€™t specifically for a very particular audience who generally know these thingsā€¦

But yeah. just ā€œread the instructionsā€ isnā€™t helpful in this case.

1 Like

Yes but pointing to the instructions (as I did) is helpful. There is a section there in the link I gave that is clearly labelled ā€œHome Assistant Exampleā€. If that isnā€™t understood or is unclear, ask away, but donā€™t come here without having read and attempting to understand.

I read the instructions. Before I addressed here, that I have no clue, about how to continue. As Fart mentioned. The docu and the examples assumes a lot of knowedge on the part of the user. So lets assume the following:

  • I have the monitor.sh running as service - log says all is fine. The mqtt integration also works (hopefully), but I dont know how to test even that. So How can I test it.
  • I want to detect at least one single device if it is ā€œnearā€ the PI, or want to know the distance or whatever it can tell me.

So an explanation what to do next is missing for me.

Lets take the given example there:

- platform: mqtt
  state_topic: 'monitor/first floor/alias'
  value_template: '{{ value_json.confidence }}'
  unit_of_measurement: '%'
  name: 'First Floor'

Which parts of the ā€œstate_topicā€ is a fixed string, which is a variable I have to replace which something different?
Where do I define the name of the location - here ā€œFirst Floorā€. I think I have to tell it the pi with the running monitor.sh?

I hope its now clearer, why I dont know how to proceed

1 Like

If it helps, this is what I did: Bluetooth LE Tracker issues

Hi John. Yes this helps me a lot. The feature ā€œPREF_DEVICE_TRACKER_REPORT=trueā€, does this prevent the monitor from pushing these % values or is this just an additional feature to get a clear home/not home message? Also unclear is the need to use this known_static_addresses or what happens if I let it empty

I left known_static_addresses empty because when I inputted my Tileā€™s MAC in there it would scan my Tile twice and give a home message followed by a not_home message, thus rendering it useless. Left empty, it works fine, HA knows what MACs to look for via what I wrote in configuration.yaml

And yes, if you want percentages my setup might not be what youā€™re looking for, via PREF_DEVICE_TRACKER_REPORT I forced it to give me an ā€œall or nothingā€ messageā€¦in any case, I am not sold on whether the percentages given are good enough for room detection (at least not without multiple Pis) and for ā€œbeing homeā€ detection a simple yes/no should suffice, no?

This setup + a Tile on my keychain means that I get recognized as Home as soon as I walk within BLE range (usually the front door of my apartment building, since I live on the ground floor) and get set to Not Home a few hundred meters down the street (which actually is very handy to not be set as Not Home when simply taking out the trash).

Hi,

I got the system runnning now. But all I get is always a 100% confidence or a 0%. The pi is in my living room, target was to detect if someone is inside the living room, but whenever someone is inside the house (at nearly all locations there) the confidence is 100%. If I go away fast far enough, the value switches to 0%. So my problem is that there is no real benefit using the tool, because it is just a home/not_home detection. What I need is a real value of the signal strength to decide how near some device is.

Is there a way to make the system having values between 0 and 100% to give me more details about the signal strength or something like this? Even I would install several PIs all would just say 100% whenever someone is in the house :frowning:

Looking inside the logs I see that there is a ā€œdBmā€ value, but that value seems to be ignoredā€¦

I am also still a bit unsure which switches to use as parameters for monitor.sh

If you pair the Pi with the Bluetooth device, it will be able to give you RSSI values which you can then use to do what you want.

Regards

Ah cool, thank you, will try that.
Do I need to change any settings within monitor.sh to send these values to mqtt?
How can I catch these values within home assistant best (in parallel to the confidence)?
I saw the following inside the mqtt platform documentation. But not sure how to configure it for monitor.sh:

sensor:
  - platform: mqtt
    name: "RSSI"
    state_topic: "home/sensor1/infojson"
    unit_of_measurement: 'dBm'
    value_template: "{{ value_json.RSSI }}"
    availability_topic: "home/sensor1/status"
    payload_available: "online"
    payload_not_available: "offline"
    json_attributes_topic: "home/sensor1/attributes"

If I try the following:

  - platform: mqtt
    state_topic: 'monitor/wohnzimmer/<MAC>'
    value_template: '{{ value_json.rssi }}'
    unit_of_measurement: 'dBm'
    name: 'Mobile RSSI'

I am not getting values (device is paired).

Also tried to have to sensors running on the same state_topic -> also not working.

Hello @lweberru,

I donā€™t use the sensors in HA for my RSSI, but your example will not work as it just sends a string value. So based on that, this should work:

sensor:
  - platform: mqtt
    name: "RSSI"
    state_topic: "monitor/Living Room/<device>/rssi"
    unit_of_measurement: 'dBm'
    availability_topic: "monitor/Living Room/status"
    payload_available: "online"
    payload_not_available: "offline"

Hope this helps

This cant work, because, the sensor cant know that I want to get the RSSI attribute out of the messageā€¦

Apologies made a mistake with the state topic, I have edited it to reflect what I think you should use.

Regards

Still dont think, that this will work, according to the docu, the message should look like that:

topic: monitor/{{name of monitor install}}/{{mac address or ibeacon uuid}}
message: {
    "id":"{{mac address or ibeacon uuid}}",
    "report_delay":"{{delay from first detection to this message in seconds}}",
    "flags":"{{GAP flags}}",
    "movement":"stationary",
    "confidence":"{{ranging from 0-100}}",
    "name":"{{if available}}",
    "power":"{{if available}}",
    "rssi":"{{if available}}",
    "mac":"{{if ibeacon, the current mac address associated with the uuid}}",
    "manufacturer":{{if available}}",
    "type":"{{GENERIC_BEACON_PUBLIC or APPLE_IBEACON}},
    "retained":"{{message retained?}}",
    "timestamp":"{{formatted date at which message is sent}}",
    "version":"{{monitor version}}"
 }

so the topic stays in the format without the rssi ending and rssi is just part of the message as it is confidence (which works). So in my oppinion there is something else wrong.

I just registered an mqtt listener to one of my devices with the format:

monitor/{{name of monitor install}}/{{mac address or ibeacon uuid}}

and I am getting this:

{  
   "id":"10:8E:E0:14:2D:8D",
   "confidence":"100",
   "name":"Lukas_Uhr",
   "manufacturer":"Samsung Electronics CoLtd",
   "type":"KNOWN_MAC",
   "retained":"false",
   "timestamp":"Mi Jul 10 2019 16:26:01 GMT+0200 (CEST)",
   "version":"0.2.197"
}

Also registered:

monitor/{{name of monitor install}}/{{mac address or ibeacon uuid}}/rssi

and all I get is -99

So somehow your idea ā€œworksā€ without beeing documented. But also provides no valid data.

So the monitor.sh is the issue. It just does not send the rssi data. So home assistant has no chance to read it.

Which parameters are needed within monitor.sh, to get the things up and running?

The rssi should work, without any special flags.

Yes sometimes it just sends -99, but after a while it will send the right value. Just ensure it is paired to the device.

U can send multiple arrival scans to it without restarting it, and see if the rssi changes.

For me to update time, I just send it arrival scans instructions, as there is no special topic to activate that yet.

Regards