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

I’ve squashed a number of bugs over the past weekend and evenings. Quite possible at least one of those was impacting interoperation of these modes.

I have moved from presence to monitor. Everything is set up and I’ve not had a crash yet (2 days) however unlike presence it hasn’t once found and reported my Tile. Do I need to do anything special for it to find it? I have tried running the script with -b. This hasn’t worked.

1 Like

@andrewjfreyer I just installed monitor yesterday (updated to todays version) and it works. I have home assistant reporting the confidence level but am finding that it takes 2.5 minutes or so to register that I have arrived. Being new to this is that reasonable? I was hoping that it would be faster so I could use the arrival to turn lights on when pulling in the driveway. I currently have 5 android phones listed in my known devices file and am only running this on one pi near my front door. Confused by recent post which says you can run multiple switches…what would the recommended switches be for my use case? I also see the behaviors file which has some timers and # retries, etc…should I look to adjust these? Not worried about the departure as much as the arrival. Thanks!

Try the -g flag.

Cheers @Cain thats not worked either. Are you using Tiles sucessfully?

1 Like

Afraid not, I will be looking to buy some beacons soon though so would appreciate an update if you do get it to work.

1 Like

Tiles may be among the group of bluetooth devices that require pairing. I’ll see if I can pick some up for testing purposes. Any hcidump logs that anyone could provide would be helpful in the interim.

I’d suggest cutting back the number of devices that you’re trying to detect as an initial test. Once a new scan for device arrival is initiated all devices in that state will be sequentially scanned. If you have five known devices, and none of those devices are home, your worst case scenario with default could be as bad as 40 seconds or so. I’m not sure why we’d see 2.5 minutes in normal circumstances given what you’ve said here, unless your devices have particularly weak BT radios and do not respond well to name requests.

That said, it can take a while to recognize your entire bluetooth environment when you run the script - in other words, it may take 2.5 minutes to determine the status of all devices. Does the 2.5 minutes remain true if you run the script, leave, and return?

So presence was finding your Tile? Interesting. Can you run this command for about 15 seconds (stop it with command + C) and post the output once you see Tile output? Feel free to redact the MAC addresses if you like:

sudo hcitool lescan --duplicates

Ok I THINK I have it setup and working now but still testing. The update frequency seems to be slower that presence but that could just be me.

What’s the best way to update monitor to the latest version while keeping all configs intact?

git pull

This will leave your configs alone.

So I brought it down to one device and then noticed that it was picking up a samsung device that I did not recognize the bluetooth mac id…I believe it is my television. Is there a way to exclude this device? Do I just do monitor.sh -r -u

Am I correct that adding the -u writes the -r flag so that on subsequent reboots this option is applied?

Thanks
Dan

1 Like

OK, here are the results from hcidump…

HCI Event: LE Meta Event (0x3e) plen 40
    LE Advertising Report
      ADV_IND - Connectable undirected advertising (0)
      bdaddr D7:1F:41:1B:6D:28 (Random)
      Complete local name: 'nut'
      Flags: 0x06
      Complete service classes: 0x1803
      Unknown type 0xff with 4 bytes data
      Unknown type 0x16 with 8 bytes data
      RSSI: -60
HCI Event: LE Meta Event (0x3e) plen 12
    LE Advertising Report
      SCAN_RSP - Scan Response (4)
      bdaddr D7:1F:41:1B:6D:28 (Random)
      RSSI: -59

Hope that helps :slight_smile:

1 Like

Excludable devices will be in the next release

2 Likes

Thanks! I do see the problem, and I can probably account for it quickly.

This is very helpful!

1 Like

Hey! I’m trying to get this working, but I have run out of luck it seems. I followed the guideline and set everything up on my Pi Zero, but I can’t get it to find my iPhone (7)

The Pi is sending MQTT-messages like this:

{"confidence":"0","name":"Invalid device: No such device","scan_duration_ms":"5066","timestamp":"Fri Sep 07 2018 09:12:15 GMT+0200 (CEST)"}

So it seems it not finding my iPhone?

My owner_devices file looks like this:

48:4B:AA:59:XX:XX  #Fredrik iPhone  ("Wi-Fi address" from Settings>General>About)

Output from sudo service bluetooth status:

bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; enabled; vendor preset
   Active: active (running) since Fri 2018-09-07 09:09:30 CEST; 11min ago
 Docs: man:bluetoothd(8)
 Main PID: 376 (bluetoothd)
   Status: "Running"
   CGroup: /system.slice/bluetooth.service
       └─376 /usr/lib/bluetooth/bluetoothd

Sep 07 09:09:30 pZero1 systemd[1]: Starting Bluetooth service...
Sep 07 09:09:30 pZero1 bluetoothd[376]: Bluetooth daemon 5.43
Sep 07 09:09:30 pZero1 systemd[1]: Started Bluetooth service.
Sep 07 09:09:30 pZero1 bluetoothd[376]: Starting SDP server
Sep 07 09:09:30 pZero1 bluetoothd[376]: Bluetooth management interface 1.14 initialized
Sep 07 09:09:30 pZero1 bluetoothd[376]: Failed to obtain handles for ""Service Changed" characteristic
Sep 07 09:09:30 pZero1 bluetoothd[376]: Sap driver initialization failed.
Sep 07 09:09:30 pZero1 bluetoothd[376]: sap-server: Operation not permitted (1)
Sep 07 09:09:30 pZero1 bluetoothd[376]: Failed to set privacy: Rejected (0x0b)

Is there something I have obvious I have missed (do I need to do something with my phone?)? How can I troubleshoot? Sorry if I have missed if there is a solution earlier in the thread (I did my best trying to find the solution before writing…)

Sorry if this is covered further up the chain. I’m looking to track iBeacons. They are showing on the mac with Beacon Scanner but I’m not sure why they aren’t popping up on the pi in monitor.sh.

I see them in x and x as x and x

sudo hcitool lescan
...
C1:00:E2:00:00:13 MiniBeacon_00019
sudo hcidump -a
...
> HCI Event: LE Meta Event (0x3e) plen 42
    LE Advertising Report
      SCAN_RSP - Scan Response (4)
      bdaddr C1:00:E2:00:00:13 (Random)
      TX power level: 0
      Unknown type 0x16 with 7 bytes data
      Complete local name: 'MiniBeacon_00019'
      RSSI: -94

Maybe I’m just over-expecting from this to see iBeacons?

EDIT The above response is of the same beacon but I’m not sure its trackable with a random bdaddr?

1 Like

You need the bluetooth MAC address, not the WI-FI

It is often one digit increment on the WI-FI (although not always)

Should be in the same place you found the WIFI MAC address

I have been testing the new monitor.sh script, with very unreliable results.

I just want to detect some bluetooth devices (android phones) home or away, what is the recommended parameter to monitor.sh?
I have reinstalled to latest(yesterday’s) version, edited the mqtt_preferences, known_static_addresses and reviewed the behaviour_preferences

I guessed a mqtt topic change running monitor.sh -a , have changed in my mqtt sensor but no luck, having the bluetooth always on, leaving the house sometimes is not detected. Arriving is a bit more reliable.
After restarting HA also is giving unresponsive problems.

Is there a “magical” formula to have it running?

Thanks in advance!

EDIT: I noticed that the mqtt topic has changed:
from topic_user1: “location/owner/downstairs/xx:xx:xx:xx:xx:xx”
to topic_user1: “location/downstairs/xx:xx:xx:xx:xx:xx”

1 Like

Are you trying to monitor script or the presence script? With monitor, iBeacons are detected with -b

I would strongly recommend using monitor for Beacon detection