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

One other question while I’m at it, does the echo command not work anymore? I used to be able to send to monitor/scan/echo and observe a reply at monitor/ha-monitor/echo but that hasn’t been working for a while now…

If I send a blank message to monitor/scan/echo, I get an “ok” reply back at monitor/pi/echo (where pi is my mqtt publisher identity).

Is there a way to see what options a monitor node is running with? I have three, two of them were running with the same options, but I’ve had to reinstall one of those two, and now I can’t remember what options I used…

This works for me.

 more /etc/systemd/system/monitor.service

Output:

bt-1~$ more /etc/systemd/system/monitor.service
[Unit]
Description=Monitor Service
After=network.target

[Service]
User=root
ExecStart=/bin/bash /home/pi/monitor/monitor.sh -b &
WorkingDirectory=/home/pi/monitor
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target network.target
1 Like

That’s exactly what I needed… thanks!

So I just got a Tile to try and I can’t get monitor to discover that one either. Just like the Nut. Something has to be up with my monitor service. It sees my Sony TV as a “generic beacon” all day every day but will not see the nut mini or the Tile. However, monitor does see something. They both occasionally show up like this:

0.2.015 06:08:42 pm [CMD-RAND]  [passed filter] data: CB:34:D7:2A:8E:B2 pdu: ADV_IND rssi: -64 dBm flags: 0x06 man: unknown delay: 3

That’s the address of the Tile. But it never shows up with any information like the Sony TV does. And I tried this a couple of different ways. One right out of the box, and one after pairing the Tile with my phone. The result was the same both ways.

Anyone have any ideas??

I put my Tile MACs in known_beacon_addresses.

monitor/bt-1/john_tile {"id":"AA:BB:CC:DD:EE:FF","confidence":"100","name":"Undeterminable","manufacturer":"Tile, Inc.","type":"GENERIC_BEACON_PUBLIC","report_delay":"1","rssi":"-67","observed_interval":"-1","flags":"0x06","movement":"none","oem_data":"Tile, Inc.","hex_data":"none","resolvable":"PUBLIC","retained":"true","timestamp":"Tue Oct 01 2019 19:55:28 GMT-0500 (CDT)","version":"0.2.197"}
monitor/bt-1/john_tile/device_tracker home

Nope. Tried that too. Get nothing.
Others report not having to put anything in the known beacon addresses.

Yes, I’m pretty sure monitor saw my Tile’s before I added them to known_beacon_addresses. I added them to assign aliases.

Anyway, sorry I couldn’t be more help.

– John

I have since added the MAC of my Nut Mini to known beacon addresses so that I could add an alias, and it’s still working fine. It is NOT in known static addresses. I have a second Nut Mini on the way - I hope that one works as simply as the first. In our situation, one Pi running monitor with tags on our keys is the simplest way to run presence detection - no phones and no multiple Pis running Monitor needed. I actually set a filter to ignore the phones, and I added MACs for things that showed up that I"m not interested in to the address_blacklist file.

I wish I had some other ideas for you, but hopefully someone else might come up with something…

That is the same setup Im running. A single pi for the whole house. Previously only tracking phones. Works great for phones, and apparently for my TV. Unfortunately I don’t need to track my TVs presence.

I’m really curious to know how your new nut works. Please post with the results. I got mine about a week and a half ago so it’s a new one.

SUCCESS!!!
All this time it was the VERSION OF MONITOR I was using. I figured I would just try to re-install monitor as a last resort. So I renamed my old directory, then pulled the latest files from git and re-added my statics and mqtt preferences. As soon as I ran it I noticed the output looked different. Similar to what someone else posted here. Much more condensed. Now both the Tile and the Nut show up as [CMD-PUBL] and the nut’s status was reported to HA!

And like others have stated, I do not have anything in my known beacon addresses file. I scrolled back to my previous commands, pre-reinstall, and saw this:

starting monitor.sh (v. 0.2.015)…

Now when I run it I see this:

starting monitor.sh (v. 0.2.197)…

Thanks for all the help! TLDR: I should have checked the version first.

1 Like

Hooray! Really glad you figured it out :slight_smile:

It took me awhile to figure it out. To change the source type to bluetooth, rather than GPS, you can change your customize.yaml to include the following:

device_tracker.name
  source_type: bluetooth

Or, alternatively, you can change the source type on the frontend by clicking Configuration>Customization then select the device tracker entity you want to change and add “bluetooth” (with quotes) under the source_type.

for anyone upgrading and it breaking see Installing mosquitto fails because service fails to start · Issue #1419 · eclipse/mosquitto · GitHub and run the below cmds

For anyone whose Raspberry Pi Zero with Monitor stopped working after an update, downgrade as @ledjee recommended:

sudo apt-get install mosquitto=1.6.4-0mosquitto1~stretch1

Additionally, I downgraded the libmosquitto1 and mosquitto-clients packages in that order as follows:
sudo apt-get install libmosquitto1=1.6.4-0mosquitto1~stretch1
sudo apt-get install mosquitto-clients=1.6.4-0mosquitto1~stretch1

Thanks for the assistance @simonk83 and @ledjee

2 Likes

How would I know if multiple instances are running at once?

For anyone having issues with previously connected devices (using monitor.sh -c XX:XX:XX:XX:XX) always showing not previously connected, I submitted a PR with the fix but wanted to post it here so you can make the change yourself until it gets merged.

On line #161 of monitor.sh, change echo "quit" to echo "paired-devices" as shown below


previously_connected_devices=$(echo "quit" | bluetoothctl | grep -Eio "Device ([0-9A-F]{2}:){5}[0-9A-F]{2}" | sed 's/Device //gi')


previously_connected_devices=$(echo "paired-devices" | bluetoothctl | grep -Eio "Device ([0-9A-F]{2}:){5}[0-9A-F]{2}" | sed 's/Device //gi')


Relevant PR:
https://github.com/andrewjfreyer/monitor/pull/253

I decided I didn’t want to be depended on phones, so after reading positive things about the Nut trackers, I went for those.

I have to say they work great. I’ve put their MACs in the known_beacon_addresses file, removed them from the app, and now monitor sees them. I expect them to run for months after I have to replace the batteries.

I have a couple of questions though:

  1. When I leave, it can easily take 2 minutes for monitor to get the confidence below 10%. The steps it takes every point where it isn’t detecting the Nut, are quite small. Just a couple percentages. Is there any way to get it to detect its state faster when I or my girlfriend leave?

  2. I have 2 Raspberry Pi’s in my house running monitor. I’m using the -x parameter so all MQTT messages are retained. I do this so that if I have to restart HA it automatically picks up the right home state. Is there any way to only retain the MQTT messages from my 2 Nuts (lol)?

  3. I’m running both monitor sessions (first and second floor) with just the -x -b parameters. -x for retained messages as mentioned earlier, and -b to scan (and report) beacon activity. Is this the ideal setup? I would prefer it to only scan for the 2 trackers I’ve setup in known_beacon_addresses. It gives a lot of noise adding -b. Is that possible?

I am using only Nut beacons, and running with -x -b. It’s working really well for me. I also have an automation to restart Monitor when HA restarts so that I have accurate data about Monitor being online in my HA frontend.

To address your questions: You can change the amount of time it takes to decide that you are gone (confidence=0) in the behavior_preferences file by changing the default 240 seconds to something smaller:

#SECONDS UNTIL A BEACON IS CONSIDERED EXPIRED
PREF_BEACON_EXPIRATION=240

To filter out the MQTT noise, I do a couple of things:

I use a filter as follows to filter out our phones, in the same behavior_preferences file, like this

PREF_FAIL_FILTER_MANUFACTURER_ARRIVE="Apple|Samsung

I also watched Monitor running by using the -V (verbose) flag for a while, and added a bunch of MAC addresses for things I didn’t want to see/track to the address_blacklist file. That really cut down on the messages being sent. I pretty much just see the Nut beacons now.

Hope that helps!

1 Like

Very fast and complete answer. Thank you so much! I’m sure this answers all my questions. I’ll try it all later. :slight_smile:

1 Like