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

Sure you can use these. :slight_smile: I wouldnā€™t use it, if something already on the Pi(s) uses/need BT. Other than that, go for it! :wink:

1 Like

Noob question - I feel like Iā€™m nearly there just missing one piece of the puzzle.

If I start monitor with -r flag and my phone bluetooth is on, phone is picked up (confidence 100).

If I turn bluetooth off on the phone, confidence goes 90, 45, 0. All good.

Now if I turn the phone bluetooth back on, nothing happens unless I trigger an Arrive scan via MQTT.

What am I missing here? Should the scan not run by itself without me having to trigger it?

It will, when some device broadcasts its presence - see this description.

Iā€™ve read through several times but like I say, I think Iā€™m missing something.

I thought the device itself (my phone) would broadcast its presence via bluetooth? i.e. monitor is scanning at regular intervals for ā€˜known devicesā€™?

Like I said, it finds it on startup and detects when it has ā€˜departedā€™. Just doesnā€™t pick it up again when I turn bluetooth back on (ā€˜arrivesā€™)?

Iā€™ve got two rPi 3ā€™s running this. One is in my office (itā€™s a Pi that I use for my 3D printer) - running Jessie, and the other is in my living room (for RetroPi) - running Buster. Neither use BT for anything else.

Running ā€œbluetoothd -vā€ on both shows 5.43

I just set this up a couple of days ago, and - as I have time - Iā€™m tweaking the settings and getting HA set up. Iā€™ve noticed that the office pi seems to work fine. However, the living room pi doesnā€™t locate anything. Theyā€™re physically less than 20 feet apart. The office pi is at the front of the house, so Iā€™m hoping it will ā€œcatchā€ my son walking up the front path. The other pi is closer to the back yard, where we spend a considerable amount of time.

Iā€™ve got a pi zero coming, which Iā€™ll put in the garage. All of these will be pretty close to each other (small house), but we do alot outside, so Iā€™m trying to cover to the street for our corner lot.

Hereā€™s what Iā€™m seeing on the living room pi:

And then on the office pi. Note, I started these scripts a few seconds apart (living room first).

Possibilities:

  1. Youā€™ve configured monitor in such a way to exclude your phone from being able to trigger arrival scans
  2. Your phone isnā€™t broadcasting itā€™s presence
  3. Youā€™ve actually configure it to only do arrival scans on demand
  1. Monitor is currently configured with the default settings. I havenā€™t changed anything yet.
  2. Is that configurable? All of our phones are iphones, with the current IOS version. Though, different models (one iPhone 11, one 8, one 7)
  3. See #1

Both piā€™s are running the same files for preferences and known addresses. I may look into the differences of pi versions (Jessie vs Buster) to see if thatā€™s the issue, as thatā€™s really the only difference between the two.

I havenā€™t configured anything in HA yet; which leads me to another question. The author notes that he has HA configured to trigger a Depart scan 10 seconds after certain doors close. Whatā€™s the recommended trigger for instigating an arrival scan? Or is that something the device (phone, etc) does automatically when coming in range of other BT devices?

@Tinkererā€™s response was not to you.

Have not changed the config at all - just started it up with the -r flag after entering known devices and setting up MQTT.

If my phone is the issue why is it being picked up when I manually trigger the scan?

I restarted the Pi and that seemed to fix the problem initially, but it has now reverted back to not seeing the phone until I manually trigger the scan.

Because when you manually scan monitor asks the phone directly. It only scans automatically when something triggers that. Thatā€™s handled by the configuration option PREF_PASS_FILTER_MANUFACTURER_ARRIVE. At the default it should scan when any device announces itself.

I am having this same problem. Did you ever find a solution?

Thanks - appreciate the help.

So starting monitor with the -r flag does not make it automatically scan at regular intervals? Something else needs to trigger it? This is what Iā€™m not understanding I think.

I tried another Pi restart and once again it appears to be working (I havenā€™t changed anything and now my phone is being picked up arriving / departing).

As things are, I would say it is not responding to my arrival particularly quickly. Iā€™m usually well inside the house and definitely in BT range for up to a minute or 2 before Iā€™m picked up.

Is that normal?

Is there a way I can improve this?

Phone is Samsung Galaxy Note 8 Android 9 if there are settings that need to be changed.

Iā€™m trying to understand a few things here. Iā€™d appreciate some clarityā€¦

I have four devices configured in the static section of the configuration. From what Iā€™ve read, if all four devices are ā€œpresentā€, then issuing an arrival scan wonā€™t do anything, since they are all accounted for. Is that correct?

I thought the mqtt.publish topics were case sensitive. However, in the examples Iā€™ve seen, people are using the lower case (arrival / depart). But, when I ā€˜execute sudo bash monitor.sh -Vā€™ it shows the topics as monitor/device/DEPART etc. Does case matter?

I donā€™t understand the correlation between the service and the script. If I have monitor running as a service, what happens if I execute the script? Is there a way to tell that the service is running properly? Does it have any logging options?

Iā€™m not seeing -r as a valid option, but my version of monitor is slightly old. The scan behaviour though is in the docs Iā€™ve linked to, and I summarised it above :wink:

The problem is that scans wonā€™t happen until something triggers it. Personally I use a sensor on the front door (as discussed by others way up in this thread) to trigger arrival and departure scans. That way if it didnā€™t pick us up on the approach (one node is by the front, covering the approach), itā€™ll pick us up then.

Iā€™m interested in the rssi feature of monitor, but I have a few questions. Iā€™m new to the concept of RSSI, so Iā€™m trying to understandā€¦

I would presume that monitor would triangulate a physical position (room) with a device by rssi levels. Is that how this works? According the the guide, Iā€™m to run the script with the -c option to pair my phone with a node. Do I do that for each device and each node? How does Home Assistant know what rssi values match what room?

You may also enjoy this thread

Hi everyone, I tried this out a long time ago with several Pi-W and had it all functional but because I made mistakes with configuration it sort of messed up my 2,4 WiFi spectrum. Iā€™m wanting to give this another try again, there was documentation on how not to mess up and was wondering if anyone has any hints on how to avoid it again :slight_smile:

EDIT: Looks like the problem still exists, and itā€™s not a Monitor problem, I realize that. I was hoping to put the Wā€™s to good use!!! I suppose I can use the regular Pi I have.

Been using monitor for several years but for some time now it just started to be very unreliable and in the mqtt logs I see this.
Connecting and then disconnecting right after. Sometimes Iā€™ve tried an run a ā€œsudo bash monitor.sh -tad -uā€ and then it connects and updates the current status of my phone, but then disconnects. But sometimes works a couple of days after that anyway but last days itā€™s been totally off. Any idea how to troubleshoot/solve?

Imgur

Is anyone using RSSI for room detection, I can pair with my phone but then when I start monitor again I cant see any RSSI values and the bluetooth menu on my phone says not connected? Not sure if this is a silly question but can I use room assistant and monitor on the same pi?

Hi,
After a hiatus from this project I thought Iā€™d try again.

I have 2 devices, an apple watch and a fitbit Ace 2

Running this I can see the fitbit device:

sudo hcitool lescan
AA:AA:AA:AA:AA:AA Ace 2

The Mac for my watch is DD:DD:DD:DD:DD:DD (found in its settings)

I have successfully added DDā€¦ to the known_static_addresses, and the confidence rises and falls with itā€™s presence. Fabulous

When adding AA to known_static_addresses I see this output (but no change in the topic)

===================================================

              *** BETA/DEV BRANCH ***

===================================================
> starting monitor.sh (v. 0.2.200)...
> removing web request caches
> warning: monitor.service not installed. Install service? (y/n)
n
> AA:AA:AA:AA:AA:AA confidence topic: monitor/pi/fitbit (has not previously connected to hci0)
> DD:DD:DD:DD:DD:DD confidence topic: monitor/pi/apple_watch (has not previously connected to hci0)
[-] 0.2.200 21-08-2020 07:11:50 pm [CMD-MQTT]	monitor/pi/fitbit { ... confidence : 0 ... }
[-] 0.2.200 21-08-2020 07:11:56 pm [CMD-MQTT]	monitor/pi/apple_watch { ... confidence : 100 ... }
[-] 0.2.200 21-08-2020 07:11:57 pm [CMD-NAME]	DD:DD:DD:DD:DD:DD Ace 2  Unknown
[-] 0.2.200 21-08-2020 07:11:58 pm [CMD-NAME]	AA:AA:AA:AA:AA:AA Apple Watch  Apple Inc
[-] 0.2.200 21-08-2020 07:12:30 pm [CMD-NAME]	DD:DD:DD:DD:DD:DD Ace 2  Unknown

When adding AA to known_beacon_addresses I see this output (but no change in the topic)

===================================================

              *** BETA/DEV BRANCH ***

===================================================
> starting monitor.sh (v. 0.2.200)...
> removing web request caches
> warning: monitor.service not installed. Install service? (y/n)
n
> DD:DD:DD:DD:DD:DD confidence topic: monitor/officebt/phill_watch (has not previously connected to hci0)
> known beacon: AA:AA:AA:AA:AA:AA publishes to: monitor/pi/fitbit
[-] 0.2.200 21-08-2020 07:14:16 pm [CMD-MQTT]	monitor/pi/apple_watch { ... confidence : 100 ... }
...
[-] 0.2.200 21-08-2020 07:19:40 pm [CMD-MQTT]	monitor/pi/apple_watch { ... confidence : 100 ... }
[-] 0.2.200 21-08-2020 07:19:42 pm [CMD-NAME]	DD:DD:DD:DD:DD:DD Phillipā€™s Apple Watch  Apple Inc
[-] 0.2.200 21-08-2020 07:19:43 pm [CMD-MQTT]	monitor/pi/apple_watch { ... confidence : 100 ... }
[-] 0.2.200 21-08-2020 07:19:44 pm [CMD-NAME]	DD:DD:DD:DD:DD:DD Apple Watch  Apple Inc
[-] 0.2.200 21-08-2020 07:20:09 pm [CMD-RSSI]	PUBL AA:AA:AA:AA:AA:AA RSSI: -73 dBm (initial reading | 127 dBm)

Any ideas?