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

Thank you, I’ve commented out the api request lines. I will let you know if I experience any issues.

1 Like

I made it working like this:

  • add NUT MAC address in known_beacon_address
  • known_static_address contains phone MAC addresses
  • run script with -g switch

Log file:

0.1.667 12:25:41 pm monitor/pizerow/FE:BC:D2:06:69:1F
{
        retain: false
        version : 0.1.667
        address : FE:BC:D2:06:69:1F
        confidence : 100
        name : Undiscoverable Device Name
        timestamp : Wed Oct 24 2018 12:25:41 GMT+0000 (UTC)
        manufacturer : Unknown
        type : GENERIC_BEACON
        rssi : -62
        adv_data : 04 3E 28 02 01 00 01 1F 69 06 D2 BC FE 1C 04 09 6E 75 74 02 01 06 03 03 03 18 05 FF 59 00 00 18 09 16 0A 18 FE BC D2 06 69 1F C2

Edit: find out that departure is working OK (confidence form 100 to 0), but Arrival scan never finds NUT again. If I restart script it work. Tried with -g and -g -b switch.

1 Like

Thanks for the report. The known beacons file can be somewhat confusing, I’m working to fix that.

I have installed this one 1 RPi so far and all I can say is wow… this is exactly what I have been wanting, thank you! I’ve had problems since I started using HA 20 months ago and never found a reliable way of detecting when we arrive. I’ll be setting up 3, 1 down stairs, 1 up stairs and 1 in the garage to replace my iBeacons

utter genius !

2 Likes

@scr I tried to reproduce what you did, but don’t see any reportings made over mqtt when the mac address of the Nut isn’t present in either of the known_* files. Perhaps this is caused by other things, but for devices where mac address is present (such as iPhones) it is working.

Hello, so I have this up and running on 1 Pi zero W now and it has all the default settings and tracking 1 phone, my Huawei mate 10 pro with android 8 on. I turn off bluetooth to test leaving the house, 2 minutes later 0% perfect!

So I turn on bluetooth and it takes well over 5 minutes to detect the phone. I haven’t changed any of the preferences or added different switches.

Any idea what I am doing wrong please?

Cheers
Mark

1 Like

ok played with the setting and works a treat. I know people say about wifi flooding but so far so good with these… I will add a depart thingy as we always leave via the front door, so the depart scan only runs when it opens. Do this look ok?

# ---------------------------
#								
# BEHAVIOR PREFERENCES
#								
# ---------------------------

#DELAY BETWEEN SCANS OF DEVICES
PREF_INTERSCAN_DELAY=3

#DETERMINE HOW OFTEN TO CHECK FOR A DEPARTED DEVICE OR AN ARRIVED DEVICE
PREF_CLOCK_INTERVAL=2

#DEPART SCAN INTERVAL
PREF_DEPART_SCAN_INTERVAL=90

#ARRIVE SCAN INTERVAL
PREF_ARRIVE_SCAN_INTERVAL=3

#MAX RETRY ATTEMPTS FOR ARRIVAL
PREF_ARRIVAL_SCAN_ATTEMPTS=10

#MAX RETRY ATTEMPTS FOR DEPART
PREF_DEPART_SCAN_ATTEMPTS=5

#DETERMINE NOW OFTEN TO REFRESH DATABASES TO REMOVE EXPIRED DEVICES
PREF_DATABASE_REFRESH_INTERVAL=35

#PERIOD AFTER WHICH A RANDOM BTLE ADVERTISEMENT IS CONSIDERED EXPIRED
PREF_RANDOM_DEVICE_EXPIRATION_INTERVAL=45

#AMOUNT AN RSSI MUST CHANGE (ABSOLUTE VALUE) TO REPORT BEACON AGAIN
PREF_RSSI_CHANGE_THRESHOLD=10

#BLUETOOTH ENVIRONMENTAL REPORT FREQUENCY
PREF_ENVIRONMENTAL_REPORT_INTERVAL=300

#SECONDS UNTIL A BEACON IS CONSIDERED EXPIRED
PREF_BEACON_EXPIRATION=145

#SECONDS AFTER WHICH A DEPARTURE SCAN IS TRIGGERED
PREF_PERIODIC_FORCED_DEPARTURE_SCAN_INTERVAL=240

#PREFERRED HCI DEVICE
PREF_HCI_DEVICE='hci0'

#COOPERATIVE DEPARTURE SCAN TRIGGER THRESHOLD
PREF_COOPERATIVE_SCAN_THRESHOLD=25

#MINIMUM TIME BEWTEEN THE SAME TYPE OF SCAN (ARRIVE SCAN, DEPART SCAN)
PREF_MINIMUM_TIME_BETWEEN_SCANS=5

#SHOULD REPORT START/END OF KNOWN DEVICE SCANS
PREF_MQTT_REPORT_SCAN_MESSAGES=false


1 Like

Thank you for this! Is there anyway to get mqtt to try and trigger a depart scan once an input boolean has been triggered?

Welllllllll I’ve come crawling back. I abandoned use of monitor due to the bluetooth interference continually knocking certain of my WiFi devices offline every other minute.
I’ve tried life360 and unifi tracking and whilst they’re good…and I was nearly successful in implementing them instead…one huge drawback…low power mode.
Seems to render them next to useless.
SO. RETHINK. Back to monitor…(which was FAAAR quicker anyway)

Any way to turn down the power on the bluetooth radio? That way I could have one in the shed at the bottom of the garden and it would not affect the house WiFi?

I’m just trying desperately to avoid spending £££ upgrading the Spark Cores in my house to Particle Photons…

1 Like

Try the beta that’s up now. You can set a flag to reject all BT advertisements below a certain RSSI threshold. Cuts down arrival scanning significantly when only some people are home.

when you reboot HA, it shows the status as Unknown and I have to force it to work. Is there anyway to force a restart of the Monitor Service when the HA instance is rebooted? I did try this but it works 50% of the time

- alias: 'Telegram bot to notify on boot'
  trigger:
  - event: start
    platform: homeassistant
  condition: []
  action:
  - service: notify.telegram
    data:
      message: Home Assistant restarted
  - service: mqtt.publish
    data_template:
      topic: "monitor/scan/arrive"
      payload: ''
  - service: mqtt.publish
    data_template:
      topic: "monitor/scan/depart"
      payload: ''      

Publishing “monitor/scan/restart” does the trick for me.

2 Likes

I had the same problem, so this is what I run now when HA boots. Seems to work perfectly now.

alias: Update MQTT sensors on startup
trigger:
  - platform: homeassistant
    event: start
action:
  - service: mqtt.publish
    data:
      topic: "location/scan/restart"
2 Likes

@gth758y @J_IO_B
thanks both… works perfectly.

I do only have 2 phones being tracked and when we both go out, the arrival scans, scans and works well, but if only I go out… the arrival scan 50% of the time doesn’t run… any ideas please?

running -r -td

I’m tracking 2 phones as well, I implemented @benjimatt script from above with his settings. It’s been working flawlessly triggered using my main door sensors.

FYI I dont think running -r -td can be used together. When doing periodic scans I dont think depart scans are considered. (i could be wrong though)

This is what I suggest. (just my opinion)

sudo bash monitor.sh -u -d -x -tdr

running the above will

  • -u : update the service file
  • -d : return to default settings
  • -x : Retain Mqtt messages to broker (this will help when hass restarts it will read the retained message that is on the server)
    -tdr : This will trigger depart ONLY on trigger (if you do not have a depart trigger do not use “d”), also sends depart/arrive triggers to other Pi’s.
3 Likes

I would use Monitor -x instead, this way you retain the last status message instead of restarting the nodes.

1 Like

ah interesting thanks, and this would still allow the arrive scans? I want mine running a lot when “someone” is away

No this would go by bluetooth advertisement. if you end up using -r you will continually do name scans even when all devices are home. but you wont be able to do Depart scans either.

so i suppose its up to you

1 Like

Is there anyway to speed this up please? I just tested by turning BT off, run the exit script wait 5 minutes and turn BT back on… 2 or 3 minutes later the arrive scan picked up the phone, not BT advertising.

I was hoping this would be the one way to solve all my entry issues :slight_smile:
I just need it to detect me when I am 10ft from the house
Thanks.