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

Have you tried adding the mosquitto-dev PPA to your repositories list?

See the very bottom of this page: https://mosquitto.org/download/

1 Like

FYI iā€™m currently on 0.2.194 and this script has been very consistent.

Ive probably posted this already but this is the section I use for departing which I do on a Door trigger.

sudo bash monitor.sh -u -tdr -x

do_nothing:
  sequence:
  - delay: 00:00:01
mqtt_depart:
  sequence:
  - data_template:
      topic: location/scan/arrive
    service: mqtt.publish
  - delay: 00:00:10
  - data_template:
      topic: location/scan/depart
    service: mqtt.publish
  - delay: 00:00:20
  - data_template:
      topic: location/scan/depart
    service: mqtt.publish
  - delay: 00:00:30
  - data_template:
      topic: location/scan/depart
    service: mqtt.publish
  - delay: 00:00:40
  - data_template:
      topic: location/scan/depart
    service: mqtt.publish
  - delay: 00:00:50
  - service_template: "{% if states.sensor.benji_bedroom.state | float != states.sensor.benji_living_room.state | float %} script.mqtt_restart {% elif states.sensor.bridget_bedroom.state | float != states.sensor.bridget_living_room.state | float %} script.mqtt_restart {% else %} script.home_status {% endif %}"
mqtt_restart:
  sequence:
  - data_template:
      topic: location/scan/restart
    service: mqtt.publish
  - delay: 00:00:40
  - service_template: "{% if states.sensor.benji_bedroom.state | float != states.sensor.benji_living_room.state | float %} script.mqtt_notify_fail {% elif states.sensor.bridget_bedroom.state | float != states.sensor.bridget_living_room.state | float %} script.mqtt_notify_fail {% else %} script.home_status {% endif %}"
home_status:
  sequence:
  - delay: 00:00:01
  - service_template: "{% if states.sensor.home_occupancy_benji.state | float == 100 %} script.benji_home_state {% elif states.sensor.home_occupancy_benji.state | float == 0 %} script.benji_not_home_state {% else %} script.do_nothing {% endif %}"
  - service_template: "{% if states.sensor.home_occupancy_bridget.state | float == 100 %} script.bridget_home_state {% elif states.sensor.home_occupancy_bridget.state | float == 0 %} script.bridget_not_home_state {% else %} script.do_nothing {% endif %}"
  alias: Home_Status
mqtt_notify_fail:
  sequence:
  - service: script.home_status
  - service: notify.benji
    data:
      title: Sensor Mismatch
      message: Your sensors are missmatched after a restart
2 Likes

I just thought Iā€™d add my thanks to the Andrew and the others who have developed this great solution. Iā€™ve had it installed for about a week, and itā€™s working fabulously. Iā€™ll add a couple of notes in case others encounter anything similar:

  1. I have 3 Rpiā€™s running Monitor nodes. 2 are Pi 3 B+'s connected via Ethernet and one is a Pi-sero W connected via Wifi. It seems like there is a huge difference in detection range between these. The Pi-W is good for about one room whereas the Pi 3ā€™s are good even across two floors of the house. I know many are running Pi 0 Wā€™s without difficultly, so it may be the difference between WiFi connection versus wired connection. Iā€™ve ordered an Ethernet adaptor for the zero-W just to see if going wired increases the range.

  2. I use motion detection on my Hikvision cameras triggered by a webhook from my Synology Sureveillance Station software to trigger the departure scan. So far, this is working flawlessly. For information on the Surveillance Station implementation, see here: https://community.home-assistant.io/t/surveillance-station-camera-motion-detection-in-hass/70680/33. There is some controversy on the thread about whether this works, but itā€™s flawless for me.

1 Like

I have been struggling with configuring Monitor but I seem to be getting closer. One question I have which may be a very obvious one but does your phone need to ā€˜connectā€™ to the Pi (ie be paired and then connect)?
I know in the standard Bluetooth integration it did not need to pair or connect to the Pi.
The reason I ask is that I can pair my phone but cannot connect. I get the message Failed to connect - no usable services on this device. Using a Pi3.

Thanks

No, Iā€™ve not paired, and thereā€™s no need to connect.

Pairing is only needed if you want the RSSI figures as far as I know.

Thanks for confirming that. Looks like I need to do some more investigation.
I have Monitor setup with ā€œPREF_DEVICE_TRACKER_REPORT=trueā€ as I only have one Pi3 and I want to use it for presence detection. I have the two entities for both our phones in HASS but they are not changing from home to not_home.
Iā€™ll keep looking at it and post if I get really stuck :slight_smile:

Hi

Anybody know how to debug bluetooth if it doesnt work.
Right now im getting confidence 0 on all my added devices.
When i try to run sudo hcitool lescan i dont get any devices either. Im setup is a pi 3b with ethernet connection and adguard home.

@andrewjfreyer I have added a Chipolo: https://chipolo.net/en/, must be unpaired with phone and found mac with command sudo bash monitor.sh -b, but it is found only few moments, then is confidence 0. If i run sudo bash monitor.sh -b it get back for moment, but iphones and watches works fine. Chipolo found few times: https://imgur.com/a/gU8oJyF. I think it only turn on bluetooth when I press the button on Chipolo!? Because the monitor find it/update then fro 5 minutes. Is this fixable?

I paired my Chipolo with my phone, which improved the visibility later. It still regularly drops off visibility, even if itā€™s not moving - watching the logs shows that it doesnā€™t beacon that regularly, and sometimes goes quiet.

I now treat them the same as any other BT device - if a door didnā€™t open, it canā€™t have left.

When its paired with phone, and added to known_static_addresses in monitor I get always confidence 0 or wont find Chipolo, how have you workaround this?

Maybe it needs unpaired on the phone end?

Have again unpaired. If i delete mac address from known_static_addresses or/and known_beacon_addresses it change mqtt mac address from _ to : . Phones have _. So I have now 2 sensors for testing. But still I must click on Chipolo to get detected and it drops connection after 5min and never come back again. Or when I unpair it from phone, it get instant visible for 5min.

Interesting that the Chipolo does thatā€¦have you tried deleting its app as well? The Tiles I have do not work well at all if I have the app on the phone, but once itā€™s removed theyā€™re rock-solid, never had a dropout from them in nearly 5 months.

This is extremely promising. Two questions I have after tinkering around. I have a NUC as my main device and a pi3 as the second with default settings on both.

  1. Will a departure scan on one device automatically trigger an arrival scan on the other?
  2. When triggering scans based on entrances to my house, what is the best practice on triggering either an arrival or departure scan?

Yes, deleted too. If paired wont work, only unpaired and only when I press button, works for 5min. Without button pressed, no detection at all! I think iphone wont advertise beacons!?

But I donā€™t see what this has to do with the iPhoneā€¦I found out the Tileā€™s MAC, put it in configuration.yaml and the only connection that goes on is between the Pi and the Tile - Monitor is constantly scanning and whenever it detects the Tileā€™s MAC within its range, it sets me to Home, no phone involved at all.

Few reported that they had working with phones. Have it done exactly as you, but with button press. monitor also found the old Mi band 2, an alternative for car, can also charge it there, battery life was then about 35days.

Update: Have installed monitor on Kodi OSMC on rPI 3B+. same procedure. Happy to use Kodi with monitor!

NUT and iTAG-ebay working great!

Its possible to implement on my pi3b+ where my hassio homeassitant setup Is

Is that a question? If so the answer is yes.

hi i woke up this morning and to find monitor sees me as away. when i logged in i see this message

Canā€™t init device hci0: Connection timed out (110)

could some one please help