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

Does your sensor really work with the rssi values? Normally it would be confidence. Like so:

value_template: '{{ value_json.confidence }}'

That could be the reason… :wink:

Tks so much @paddy0174! Now seems I do not get disconnected from the broker anymore…
1604155625: New connection from 192.168.0.35 on port 1883.
1604155625: New client connected from 192.168.0.35 as pi685 (p2, c1, k60).
But my sensor (Iphone) icon still does not show anything… :o
icon
Is it probably related to my MQTT or yaml?

So how does your config look now?

Post the (corrected) configuration for your sensor. I’m not sure, if HA is case sensitive so use all lower case if possible. Like so:

sensor:
  - platform: mqtt
    state_topic: 'listen/pi/C0:9A:D0:28:EE:8D'
    value_template: '{{ value_json.confidence }}'
    unit_of_measurement: '%'
    name: 'iphone'

Afterwards you could check with the developer tools how your sensor is named and if it is working correctly.

I have the same problem.

@peterson1190 and @henrybcn
What do your developer tools show about that sensor? Does it show at all?

Yes, I can see it as sensor.pi0 and the value is Unknown.

@peterson1190 @paddy0174 , nothing changed with the new config. And yes, I can see the sensor, but is unknown


back to square one… :grimacing:

I have installed monitor.sh and things seems to be working without any errors. When I run sudo bash monitor.sh, I can see my known devices reporting. I can also see the topics in MQTT explorer. The confidence level of either device never goes above 0 though. I tried adding:

PREF_DEVICE_TRACKER_REPORT=true
PREF_DEVICE_TRACKER_HOME_STRING=home
PREF_DEVICE_TRACKER_AWAY_STRING=not_home
PREF_DEVICE_TRACKER_TOPIC_BRANCH=device_tracker

and can see the device tracker topic but both report as not_home.

Also, when I start monitor.sh, I get
confidence topic: monitor1/RaspberryPi2Monitor1/my_device (has not previously connected to hci0)

and when I try sudo bash monitor.sh -c my_bluetooth_mac, I get error: connection to my_bluetooth_mac failed.

hciconfig shows hci0 UP RUNNING

Edit: So tonight, I ended up adding a couple devices that were not Apple iPhones and was able to get at least one of the devices (out of 2) to show with a confidence of 100 so I know everything is working correctly. I have seen people in the forums be able to scan Apple iPhones. Is there something specific I need to do for Apple devices?

Hi HA Community!

I’m an openHAB user and registered here after finding the Monitor tool. It looks like a great project. Thanks to @andrewjfreyer for publishing this. Greetings from the dark side!

I’m trying to build an automatic door unlock trigger and wanted to know if monitor would work for our scenario. So far I’ve only got monitor up and running, integrated with openHAB, and arrival/departure scans are working with physical triggers (motion detected, door closed, etc).

However, for the purpose of unlocking a door, a high degree of precision is required, so now I’m in the tweaking phase. My challenge is reliably distinguishing the difference between being inside vs outside in the yard. We’re often in the yard, detached garage, or in the street in front of the house, so we’re not exactly away, but far enough where I’d like to trigger an automatic unlock when we walk up to the entryways.

  • Is there a way to adjust the confidence levels based on different RSSI values to help monitor tell the difference? As it stands right now, monitor doesn’t flag us as away if we’re in the back or front yard because we’re still too close.
  • Alternatively, is there another method in monitor that everyone is using? Is what I’m asking even possible?

Thanks in advance!

EDIT: Forgot to mention. We don’t need an occupancy monitor since there’s already one in place which works reliably. The intention would be to use Monitor in tandem with the existing setup.

I’m running Monitor quite passively now, I think, and I’m also NOT trying to query iPhones. I think that’s helping a lot. Just BT beacons.

Hi, I installed monitor.sh and was working fine last night. But I noticed this morning that it stopped after 2 hours or so. The last scan was at 9:43pm but was running perfectly fine around 7pm. My flags were -r -a.
Any idea why it stopped??

If you want a reliable system, I’d go for something that triggers your monitor scan. Like a motion detector or a infrared light barrier or something like that. With that trigger you start the scan.

The problem with this use case is, you can’t run enough scans, that determine how far away from the door you are. And these scans would depend on whatever is sending out the signals often enough.

If you want to go into this direction, I’d rather go with something like room-assistant. It is better suited for that kind of use case.

Hi, i run monitor on a fresh new pi-zero W, powered from a wall psu. Works fine for two days and after it crash in some way, i need to unplug/replug the power. How can i debug the problem? Maybe monitor fill the whole ram or cpu? I monit just 3 BLE beacons.

Just a quick question, I have monitor setup and running.

My question is do I have to create a seperate mqtt senor is HA for each phone I’m tracking? I found the example a little confusing as it refers to ‘first floor’ and ‘second floor’

Yes, One mqtt sensor for every device

1 Like

Is there a way to see what flags are currently active on monitor.sh?

And is it possible to go from dev/beta branch back to stable?

Quick question, I have a single monitor node setup with default settings. two phones setup but I’m finding my Pixel phone appears to drop off for periods of around 10 mins then reappear. I can clearly see this in device tracker I have setup going from home to not home for 10 or so minutes. based on this behaviour it doesn’t seen very reliable for presence detection :frowning:

Any suggestions to improve things much appreciated

Quick question, total noob here. I’ve had my Pi with Home Assistant since yesterday and absolutely zero prior coding experience but so far have managed to integrate everything I wanted except for BLE based presence detection. I’ve read through your project and it looks exactly like what I need for my usecase, however mine is a bit different since I only have 1 Pi and one room with smart devices (live in a shared apartment). Is it possible to install this on my main Pi and have it work based only on that? How would I go about detecting my bluetooth device (iPhone) and setting this up so that it triggers my (adaptive) lighting?

Probably a very noob question to ask, but I’m sort of stuck even after reading through the instructions several times.

Noticed the same on mine. It runs fine for weeks of monitor is not running.

Sure, it doesn’t have to be remote from your main HA install, it just can be.

For simplicity, enable PREF_DEVICE_TRACKER_REPORT (see here then scroll down), and configure an MQTT Device Tracker. Then you’ll have a device_tracker.pi_man_sam (or similar) entry that reports if your phone has been seen, or not. You can use that entity in your automations.

For example, you’ll have an entry like this in your configuration.yaml:

device_tracker:
  - platform: mqtt
    source_type: 'bluetooth'
    devices:
      pi_man_sam: 'monitor/identity/pi_man_sam_mobile/device_tracker'
  • identity is the value of mqtt_publisher_identity from mqtt_preferences
  • pi_man_sam_mobile is the alias you gave your device in known_static_addresses
1 Like