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

I have confused myself. Can someone explain exactly what monitor.sh -tr does? Does it scan like normal, but will update the other devices that are using monitor.sh -t[ad]? I think that is what it does, but I have seen a few comments that have made me doubt myself.

From the built in help:

usage:

        monitor -h      show usage information
        monitor -R      redact private information from logs
        monitor -S      silent operation (no logging)
        monitor -c addr create connection to bluetooth device
        monitor -C      clean retained messages from MQTT broker

        monitor -V      print verbose/debug logging messages
        monitor -v      print version number
        monitor -d      restore to default behavior_preferences
        monitor -u      update 'monitor.service' to current command line settings
                        (excluding -u,-V, -F, and -d flags)

        monitor -s  report all mqtt messages to a single topic with
                                $mqtt_topicpath/$mqtt_publisher_identity  (defined in MQTT preferences file)

        monitor -f      format MQTT topics with only letters and numbers
        monitor -a      report all known device scan results, not just changes
        monitor -x      retain mqtt status messages
        monitor -b      report bluetooth beacon advertisements (e.g., generic beacons, ibeacons, and so on)
        monitor -t[adr] scan for known devices only on mqtt trigger messages:
                                a $mqtt_topicpath/scan/ARRIVE (defined in MQTT preferences file)
                                d $mqtt_topicpath/scan/DEPART (defined in MQTT preferences file)
                                r send ARRIVE or DEPART messages to trigger other devices to scan
        monitor -D [dir]        use alternative directory for configuration files

So, -tr says to automatically do arrival and departure scans, and to notify others when it does.

I read this, and maybe I am being dense, but where does it say it does automatic arrival and departure scans?

The implication is that the default is to scan for both automatically.

No real concern on the battery – so far so good!

Nice! Toying with moving away from my Unifi device_tracker and only to this one. Just need more time to play with it.

@davosian @rompca7 did you guys ever get this to work with your garmin watches? I’ve got a vivoactive3 and cant get it to work… Keep seeing messages like this:

Jun 23 12:09:58 pizero1 bash[16869]: [+] 0.2.197 23-06-2019 12:09:58 pm [CMD-NAME] F2:E4:81:91:B6:2E JonsGarmin Unknown

@andrewjfreyer

Thank you for all your work on this script! It´s amazing.

I just want to let you know that i have found what I believe is wrong behavior by the script. If i run ‘sudo bash monitor.sh -r’ (version 0.2.197) and only one phone is listed in ‘known_static_addresses’, this is what happens:

  1. The script does a fisrt arrival scan and detects the phone;
  2. The script then starts doing departure scans;
  3. If I now turn the phone´s bluetooth off, the script will detect it;
  4. However, the script will not do now any more arrival scans. If I turn on blueetooth on the phone, the script will not detect it.

In my case, I have solved this problem by modifying the beginning of the ‘perform_complete_scan’ function:

        #IF WE DO NOT RECEIVE A SCAN LIST, THEN RETURN 0
        if [ -z "$1" ]; then
                #SET DONE TO MAIN PIPE
                printf "%s\n" "DONE" > main_pipe

                #log "${GREEN}[CMD-INFO]        ${GREEN}**** Rejected group scan. No devices in desired state. **** ${NC}"
                return 0
        fi

I do not know if this is the right way to solve the problem, but I hope it is been helpful. Let me know if you have any questions.

Once again thank for your hard work.

Any luck finding an answer to this? I was wondering the same thing

@coolguymatt

That’s from the dev …I think this indicates that no automatic scans occur with -t. Which brings to mind the question of a situation I have where it takes a while for one of the two Pi’s at each end of the house to pick me up. I think when I walk from one end of the house to the other one loses me but it takes awhile for the other to find me. This shows me away which is a problem. I thought maybe the -r option might help but idk if I want all the scans to be triggered. I think somethings have changed and it’s a bit confusing heck the -r flag had a different purpose in the beginning but was deprecated to the newer purpose

I believe you can use the -u flag to update the service script. So with -ux flag update the script to run with x flag @ boot up

Lots of confusion. Really what I want to know is which flag(s) I need to use to “act like default, but trigger other devices that are setup to only respond to arrival and departure triggers (-tad)”. Maybe that is how default works and I am complicating things.

Yes I agree the -r flag would seem what we want in order to “relay” to other pi’s running the script to scan. Problem is unless I’m reading the developers post incorrectly it cant be run without -t which is a purely triggered mode and so no scans on random advertisements etc.from that original pi. It seems we both want the one pi to keep scanning as per default and cut down the scans of the others. Ive read alot of this thread and the dev was really helpful but then you know probably life lol

For this you want -tr as the flags for your ‘main’ device. That means act normally and send triggers to other -tad instances whenever you perform an ARRIVE or DEPART scan.

After the demise of Google Home presence detector, I have decided to give this a try on my spare Raspberry Pi 3.

I manage to get it working with my Mi Band 3 (BLE device).

However, after testing this for few hours, I notice that the coverage area is quite big. It spans across few rooms and floors making it unsuitable for room based presence detection. I am wondering is it possible to adjust the sensitivity so that it covers smaller area thus more suitable for room sized presence detection?

Maybe this has been discussed before but it’s very hard to find answer in more than 1415 messages. Appreciate it if someone can help me out. Thanks.

when i woke up this morning, the whole thing has stopped working.

Master @masterkenobi,

Stable it is, and confirm I can that I do room presence with its level of force. I have two running on the same Pis I have Kodi (OSMC). The dark side, resist you must, to think stable it is not. For fear leads to hate, and hate leads to suffering.

This I do with the rssi value I get from it, and room detect you get using it.

Rudimentary it is, but it still works with some mathematical modelling; which perfection I am still working out.

Helps, hope this does.

3 Likes

@shbatm
?sure,maybe but based on what. Please point this out where it says this. You can see in my previous post that the dev states -t is triggered mode only. -r is maybe for “relay” to the rest of the machines running the monitor script

The ‘Example with Home Assistant’ section of the readme.

The -t flag is supposed to require one or more of rad -r is a different flag. -tr != -t -r in this case (or at least that’s how it’s supposed to work; I’ve found a few bugs around flags elsewhere in this script).

So I have went a bit overkill and both 2 raspberry pi zero w + 1 raspberry pi 3b+ which I plan to use with Monitor.

However im struggling with when I boot up all three then they all will report condidence of 0, but If I only keep one up at the time than it works fine.

Any ideas?