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

Hi guys,

Monitor is working great, the onlything is when I reboot HA all monitor sensors have the stats on unknown. They don’t update until I leave the house because the arrive/depart scan made it 0.

Is there anyway to restart Monitor trough a mqtt message or is there a other solution for this problem?
Found it:

monitor/scan/restart

That’s a known error that lots of users are experiencing, but I’m having difficulty duplicating. Working on it!

Let me know if there is anything I can do to help you debug. Thanks for the great software.

Chris.

Sorry for the noob question but ive set up monitor on a spare rpi3b and have Hassio running in docker on another machine. I’ve ran the script and monitor finds my iPhone with w confidence level of 100 but when I was the below in home assistant I can’t view the sensor? Any help appreciated.
‘’‘platform: mqtt
state_topic: ‘livingroom/monitor/matt_iphone’
value_template: ‘{{ value_json.confidence }}’
unit_of_measurement: ‘%’
name: ‘Living Room’
‘’’

Hi,

Tyring this script. It correctly detects when i turn on my bluetooth and go out of range. However, when coming back in range, it is not detected untill I restart the script.

I’ve run monitor without any arguments, and with -b.

What should I do to have it also detect the phone when it comes back ?
hcitool name returns the name.

Did you ever figure out what the issue is? I’m seeing this on my LG G7 as well. Confidence is always reported as 0 and RSSI reports back at 99.

Edit: Okay so I didn’t pair with Monitor so that explains the RSSI value of 99
Edit2: Followed the “pairing” guide and even got "connection created to XX:XX:XX:XX:XX:XX, but RSSI still reports 99 and confidence level 0 when I restarted the monitor service
Edit3: I’m fairly convinced at this point it has something to do with my USB Bluetooth dongle. I have an original Raspberry pi B (the one with just two USB ports). I can’t get HCIUART to start. HCITools isn’t able to find a device. Everything I’ve tried hasn’t fixed the problem. Bluetoothctl states no default device has been set. Yet Bluetooth the service is running and lsusb shows my Bluetooth device

Message 3 received on monitor/main/XXXXXX at 8:23 AM:
{
“id”: “##:##:##:##:##:##”,
“confidence”: “0”,
“name”: “XXXXXXXX”,
“manufacturer”: “LG Electronics Mobile Communications”,
“type”: “KNOWN_MAC”,
“retained”: “false”,
“timestamp”: “Sun Mar 29 2020 08:23:15 GMT-0500 (CDT)”,
“version”: “0.2.200”
}

Ah yes. I posted it on the github issue tracker but forgot it here. I was using the WiFi MAC address by mistake I should have used the Bluetooth MAC address. Hope this helps.

Glad you figured out your issue. Unfortunately that isn’t mine. I’ll keep playing. I think it’s an issue with the Cambridge “drivers” in Raspbian.

No idea who’s actually paying attention to my saga, but I figured it out. I was using cheap USB Bluetooth “Cambridge” Dongles (both the “CSR 4.0” and “CSR 5.0”). While they work great for WIndows, apparently they don’t work so well in Linux (maybe if in xwindows instead of just commandline?). Anyway, I happen to have a much more expensive TPLink Bluetooth USB Dongle in my gaming PC that I pulled just in case and sure enough upon reboot it was working as expected. Apparently this is a “real” Cambridge Bluetooth USB dongle.

So now I’m rocking an ORIGINAL Raspberry Pi with an Edimax 150N Wireless USB and a TPLink USB Bluetooth adapter (I did overclock it to 900mhz just in case).

1 Like

Are you sure the state_topic is “livingroom/monitor/matt_iphone” and not "monitor/livingroom/matt_iphone "?

Can someone check this init script for me please?

Unit]
Description=Monitor Service
After=network.target

[Service]
User=root
ExecStart=/bin/bash /home/pi/monitor/monitor.sh -x -b -tdr &
WorkingDirectory=/home/pi/monitor
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target network.target

My state_topic is livingroom/monitor/matt_iphone. If i wanted to trigger a depart scan would it be livingroom/monitor/depart? I’m sure I’ve tried this in developer tools > mqtt and when I turn off my bluetooth then run this, it still shows me at home?

Normally the topic would be monitor/livingroom/ not the other way around. Are you sure that’s right?

Sorry I didn’t see this. Yes I had that the wrong way around. I’ve got it sorted now in that it’s detecting my iPhone but the service doesn’t seem to be working and the only way I can get my presence detected is by running the script manually.

Sounds like a problem with your service script. Is it enabled? What errors do you get from the service?

All running fine using these commands…no errors come up after I run them.

sudo systemctl daemon-reload
sudo systemctl enable monitor
sudo systemctl start monitor

Is there a command I can use to check whether the script service itself is running? If I look at mqtt in home assistant the messages are only from when I run the script manually. Also running on a rpi3b with deconz running. Wondering if it’s worth just running on my pi zero instead…

The useful commands for checking the status are:

sudo systemctl status monitor

And for watching behaviour (press <CTRL><C> to cancel):

sudo journalctl -f -u monitor

The first command says that the service is active and running. The second outputs broken pipe errors. I’ve googled but not sure if this is an issue or not?

- Logs begin at Thu 2019-02-14 10:12:00 GMT. --
Apr 05 03:51:02 phosconpi bash[27618]: ./support/btle: line 399: printf: write error: Broken pipe
Apr 05 04:04:50 phosconpi bash[27618]: ./support/btle: line 352: printf: write error: Broken pipe
Apr 05 04:06:21 phosconpi bash[27618]: ./support/btle: line 352: printf: write error: Broken pipe
Apr 05 04:24:24 phosconpi bash[27618]: ./support/btle: line 352: printf: write error: Broken pipe
Apr 05 04:28:30 phosconpi bash[27618]: ./support/btle: line 352: printf: write error: Broken pipe
Apr 05 05:05:02 phosconpi bash[27618]: ./support/btle: line 352: printf: write error: Broken pipe
Apr 05 06:08:15 phosconpi bash[27618]: ./support/btle: line 352: printf: write error: Broken pipe
Apr 05 06:15:32 phosconpi bash[27618]: ./support/btle: line 352: printf: write error: Broken pipe
Apr 05 06:23:58 phosconpi bash[27618]: ./support/btle: line 352: printf: write error: Broken pipe
Apr 05 06:39:22 phosconpi bash[27618]: ./support/btle: line 352: printf: write error: Broken pipe

I’d expect a lot more information in the log than just those errors, I’d guess it’s not running as a user that can access the Bluetooth device. Can you share the whole of your systemd script please.

Sure it’s here, based on what you’ve just said I think I need to change the user below to pi? Given that manually running the script as pi seems to work?

[Unit]
Description=Monitor Service
After=network.target

[Service]
User=root
ExecStart=/bin/bash /home/pi/monitor/monitor.sh -x -b -tdr &
WorkingDirectory=/home/pi/monitor
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target network.target

If you run it sometimes as root and sometimes as pi, that’ll likely cause you issues, but running it as root should mean it just works :man_shrugging:

I’m surprised as the lack of logging though. Maybe somebody else will have suggestions.