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

Is this only to detect presence when arriving or leaving the house? And also it can tell where exactly a person is I.e. 1st or 2nd floor?

Your understanding is correct

As explained in the documentation, you can try to use RSSI values to triangulate devices in a home, but the measurement error is large. At best, you might be able to semi-reliably estimate the position of a device (within a few meters) that has been stationary for 5 to 10 minutes.

RSSI values are not reliable enough to trigger any time-sensitive automation.

Thanks. Working nicely with the nut, a bit unreliable with just one pi and a Fitbit due to range.

Adding the beacons to the known beacons file prevents MQTT messages firing off for every new Bluetooth device?

No, but you can add devices you donā€™t want to see to the blacklist.

@andrewjfreyer
Hi, wondering if you can point me in the right direction?
I have 2 Raspberry Piā€™s (RPi_1 and RPi_2). RPi_1 has HA, monitor and mosquitto broker installed, which has a username/password defined. And Iā€™ve set /etc/mosquitto/conf.d/default.conf to be:

allow_anonymous false
password_file /etc/mosquitto/passwd

I can successfully ā€˜hello worldā€™ message via mosquitto_sub and mosquitto_pub on RPi_1 with the username/password defined. With monitor mqtt preferences set to that broker, it also successfully authenticates and sends messages.

RPi_2 is not playing ball. It also has HA, monitor and mosquitto installed. I defined the same username/password and conf file for it too but Iā€™m not using it as a brokerā€¦I configured monitor mqtt preferences to point to mosquitto on RPi_1 (same network) with corresponding username and password. It starts up with these errors:

Unable to connect (Lookup error.).
mqtt broker went offline, or a password/username combination was rejected.

I canā€™t seem to figure out why RPi_1 monitor works but not RPi_2.
If I remove the username/password conf and have everything as anonymous, it all works.

Thx,
A
(PS. Iā€™m basically trying to set up monitor on another RPi to send presence state to the other one)

So I have this working very reliably with a Nut mini BLE device - tracks very accurately and has suprisingly good range throughout my house.

A random question - when I restart my home assistant server, the devices all default to unknown until the status changes on the Monitor PI Zero and a new MQTT message is sent. Is there any way to request a current status from Monitor via MQTT for known devicesm so that I can get an update on restart via an automation?

1 Like

@ planetawylie

I have this issueā€¦

Try putting a simple username and password. Iā€™m not sure if there is a bug in mqtt.

1 Like

Usually this behavior happens when you have a special character in your password. Particularly bad characters are: @ : /

Do you have any of these characters in your MQTT password?

I would describe mosquittoā€™s password handling as buggy, yes. My workaround to support the most users ended up forbidding a small, limited set of special characters.

Working on one, yes. For the time being, most users (including myself) send a restart message to each monitor node.

1 Like

Sighā€¦I need to RTFM. Yes I have a ā€˜@ā€™ in the pwd.

Thank you
:bowing_man:

EDIT: Confirmed, fixed the password and everything working now :grinning:

1 Like

is it normal to see multiple process running?

pi@raspberrypi:~ $ ps -guax | grep monitor
root 448 0.9 0.3 5680 3776 ? Ss 17:43 0:06 /bin/bash /home/pi/monitor/monitor.sh -b -tadr -x &
root 656 0.0 0.2 5396 2512 ? S 17:43 0:00 /bin/bash /home/pi/monitor/monitor.sh -b -tadr -x &
root 657 0.0 0.2 5408 2524 ? S 17:43 0:00 /bin/bash /home/pi/monitor/monitor.sh -b -tadr -x &
root 658 0.5 0.3 5672 3360 ? S 17:43 0:03 /bin/bash /home/pi/monitor/monitor.sh -b -tadr -x &
root 659 0.1 0.3 5680 2988 ? S 17:43 0:01 /bin/bash /home/pi/monitor/monitor.sh -b -tadr -x &
root 663 0.0 0.3 5660 3156 ? S 17:43 0:00 /bin/bash /home/pi/monitor/monitor.sh -b -tadr -x &
root 665 0.8 0.3 5568 3448 ? S 17:43 0:05 /bin/bash /home/pi/monitor/monitor.sh -b -tadr -x &
root 667 0.0 0.2 5396 2836 ? S 17:43 0:00 /bin/bash /home/pi/monitor/monitor.sh -b -tadr -x &

Yes, this is normal.

@andrewjfreyer

Thanks

After a few min HA stops receiving MQTT data.

I run debug /verbose and got.

monitor.sh: line 943: 031c8c8d94: value too great for base (error token is ā€œ031c8c8d94ā€)

monitor.sh: line 943: 1000520041a003b10RANDC2: value too great for base (error token is ā€œ1000520041a003b10RANDC2ā€)

I did a scan and on the thread and looks like different line from what [benjimatt] got.

1 Like

What version are you running?

version 0.2.151

updated to 0.2.163 let see what happensā€¦ :slight_smile:

UPDATE: It was the same. I reverted to the master 0.2.150 been stable,

I have been reading down through this very long thread, and getting more confused as I go! I have monitor running on a RPi Zero W and itā€™s generating MQTT traffic. What I wanted was something that would provide Occupancy detection - ā€œIs anyone home?ā€ as well as Presence detection - "Who is home?
However the examples seem to focus on Occupancy or am I wrong?

Thanks!

I group the sensors or device trackers in home assistant. That answers ā€œis anyone homeā€.

The value(s) of the individual sensors/trackers answer the more specific second question.

EDIT - for more context:

If these are my sensors from monitor

sensor.andrew_first_floor
sensor.andrew_second_floor
sensor.wife_first_floor
sensor.wife_second_floor

ā€¦ and these are the respective input booleans turned on and off via automation:

input_boolean.andrew
input_boolean.wife

We can group the booleans like this:

group: 
  name: owner occupancy
  entities: 
  - input_boolean.andrew
  - input_boolean.wife

So, now we have three ā€œinterestingā€ entities in HA:

group.owner_occupancy
input_boolean.andrew
input_boolean.wife

If group.owner_occupancy is ON, at least one person home.

If group.owner_occupancy is OFF, the home is vacant.

If input_boolean.andrew is ON, andrew is home.

If input_boolean.andrew is OFF, andrew is away.

If input_boolean.wife is ON, wife is home.

If input_boolean.wife is OFF, wife is away.

Ah, OK I think I see a little light at the end of the tunnel. One other question regarding sensors, the examples use the MAC address of the device. But our phones are listed in known_static_address, so should I be using the nicknames in the sensor defininition like this:

# Pat's iPhone 7
- platform: mqtt
  state_topic: 'monitor/ground_floor/pat_s_iphone_7'
  value_template: '{{ value_json.confidence }}'
  unit_of_measurement: '%'
  name: "Ground Floor"