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

Type exactly that. You will then be in the nano editor. edit as described. ctrl-x to exit.

1 Like

Thank you for some reason I kept getting it wrong. That’s why I removed the post.

This is a great tool you have created and thank you again for continuing to be active.

I’m also very curious how you get Monitor to start more or less as a service, I currently SSH into the Pi every time and run it manually, can someone share a command that would help? Would crontab do the job? And if so, what would the command be?

When you first run this: sudo bash monitor.sh - it’ll prompt if you want to install it as a service.

Aha, but will saying yes to that (which I’m pretty sure I did) allow me to then tell it to run with -b? It’s the only mode that works (impeccably, though!) for me.

here’s what you need to run to modify the startup flags:

first, modify the service with the flags you want

sudo vi /etc/systemd/system/monitor.service

then reload the daemon (to pickup the changes you just made) and restart the service

sudo systemctl daemon-reload
sudo service monitor restart
1 Like

Outstanding, thanks!

Though what @jon102034050 said will work, but an easier way will be to stop the service and run the script manually in cli with all the flags you want alongside the -u flag.

This will update the service file, and start the system.

1 Like

I have tried this on a few rasperry pies (v3, zero), and all jam the Wi-Fi (Unifi AP LR). I notice this by sluggish connection, and see that the connection quality displayed in Unifi’s web GUI is drastically reduced. Any ideas on why this happens?

Clogging of the 2.4GHz space because BT is also 2.4? Try being exclusively on 5GHz on your WiFi in the house…

Cool, did not know that…I already did the other method and it works as desired now :slight_smile:

5 GHz exclusively is unfortunately not an option. By reading previous posts, I understand that active scanning with name requests can be the problem source. Would it be possible to use only passive BLE scanning for paired devices?

Hi,
I’ve set up monitor with flag -r which picks me up the second I pull on my drive, yet it also keeps dropping to zero randomly.

What’s the best setting for it to pick me up as soon as I pull on the drive, yet only scan to see if I’ve left when i unlock my door?

sudo bash monitor.sh -tdr

Which basically means depart scan only on trigger and continuously scan for arrival.

Regards

1 Like

Super thank you.

I’m trying to get this running on a NUC running Ubuntu 18.04, but the most recent version of mosquitto I am able to install is 1.4.15 and thus is not satisfying the greater than version 1.5 check. Any thoughts?

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