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

Gotcha. Looks like a delay calculation issue then. I’ll investigate and hopefully be able to isolate the guest device issue later tonight.

I’ve had no problems with false positives since updating to 0.4.13

Both my wife and I (the 2 phones I monitor) have left and returned with Presence correctly seeing both actions.

I’m not using PiHole. I was noticing issues with my Harmony Hub on Saturday. But I haven’t been seeing the slowdown issues since updating to 0.4.13

I managed to get it installed (at least I think I did) by skipping the command sudo rpi-update. It was odd. If I executed that command, the RPi Zero W would never reboot. I skipped it and proceeded without apparent incident. Just checked the service, and it is active.

Now I am not getting anything on the HA side but hopefully that will change after I post some more “dumb” questions.

1 Like

Good to hear it’s up and running! Odd that rpi-update command failed. Perhaps your board doesn’t like firmware updates.

Anyhow, does the quoted statement mean that you are not seeing any updates on your MQTT broker?

So I went ahead and ordered some PIR sensors, found a script that works pretty well (through limited initial testing) here and I think I am pretty happy with this two-for-one setup. The mqtt pir sensor is quite quick to respond (I have some battery powered Zwave PIR sensors and they have a 3-5 second lag, whereas this is within 1 second) The only thing I need to figure out now is how to get this python script to always run. I am sure it is a stupid question and I don’t mean to hijack the thread, just thought someone in this thread might know the most efficient way. Could it be added to the ‘presence.service’ file? Still new to all this.

Yeah, no problem adding it to the same service. There’s probably value in being able to separately start and stop.

Please pardon if these questions are simple or dumb but I will ask anyway.

In the write up it says to post the following in the mqtt_preferences file:
mqtt_address=“ip.address.of.broker”
mqtt_user=“your broker username”
mqtt_password=“your broker password”
mqtt_topicpath="location"
mqtt_room=“your pi’s location”

The first three lines are no problem. Is the fourth line entered verbatim or should location be something like garage, kitchen, etc.? Because that is what I thought would go between the quotes on the fifth line.

My other question at the moment concerns the following lines:
- platform: mqtt
state_topic: ‘location/owner/garage/00:00:00:00:00:00’

In the state_topic line, what MAC address is used in place of 00:00:00:00:00:00?

Thanks for any and all help.

leave it as “location” unless you are changing the mqtt sensor from

state_topic: ‘location/owner/garage/00:00:00:00:00:00’

to something else.

00:00:00:00:00:00 needs to be replaced with the bluetooth MAC of your phone (you can find it in settings). and also needs to be in the ‘owner_devices’ file

1 Like

Thank you for the information. I made the necessary modifications. Restarted everything but still see nothing.

Would the following request work to see the updates on the broker?

mosquitto_sub -d -u user -P password -t location/owner/garage/xx:xx:xx:xx:xx:xx with xx.xx etc being the bluetooth MAC address?

All I see is sending PINGREQ and received PINGRESP.

Thanks.

Andrew, where did you get the server, api-call-service, and api-current-state nodes? I don’t see them at flows.nodered.org.

thanks for the info.

created a separate service and it is working!
thanks again for creating this

1 Like

is everything configured correctly? i would start there and make sure it is finding the bluetooth MAC address you put in

run
sudo systemctl status presence.service

the output should give you the name of your phone like so:
Apr 24 03:39:09 raspberrypi bash[245]: location/owner/bedroom/xx:xx:xx:xx:xx:xx { confidence : 100, name : Jake’s iPhone, scan_durat......

if not you have a bluetooth problem not an mqtt problem

after that you can ensure the mqtt info is set up properly

One thing to watch out for is the version of mosquitto_pub that ships with Raspbian is old and uses a slash as part of the MQTT client ID. Newer versions of the broker will reject that client ID and mosquitto_pub won’t complain.

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=870165

These are part of the node-red-contrib-home-assistant node.

Looks like I broiught it to life in HA as well. Now will experiment a little to see how many Zeros I might need.

Also planning to implement it on my NUC on which HA is running.

Regarding lagging network I made the following observation: network is not constantly slow, but typing away in ssh hangs every few seconds or so for a short moment, a little less than a second maybe.

Have others experienced the same?

Lars

P.S. Really smart idea and great contribution. Thanks !

1 Like

Fantastic solution @andrewjfreyer. You have the same scenario as I do.
As a matter a fact, I started a script (python) a few weeks ago to do pretty much what you do, but it is in its early stages.
One big problem that I have is that every time that the Bluetooth scans (even with your code), it interferes with my wifi. It gets even worse when the target is not home, causing a lot of packages drops and increase the ping time.
Have anyone else had a problem with this? Its just impossible to play online games. I have tried to change wifi channels, moving things around… nothing helped.

On my script, the workaround was to increase the time to 10m when there is someone home and 1m when there is nobody home. But I naturally loose precision.
Another thing I do to save Bluetooth scans is to try a simple ping to the phone ip first. If the phone is not in the “resting” state, it works fine.
Another thing I do is right after one raspberry scan and find someone, it publishes on a topic and notifies every other raspberry, so they skip the current scan.

1 Like

I have been seeing similar symptoms. How did you determine it was WiFi interference?

1 Like

From my laptop I started to ping another computer on the network. I then started to trigger bluetooth scans manually. Ping times skyrocket and/or a few packages drop.
The original symptom was an online game, that became unplayable on the same weekend I started to poll for bt devices.

2 Likes

I cannot replicate that result.

I have a Pi B and a Pi Zero with Andrew’s script on, with default settings. From a third (wired) Pi I ping a wireless 2.4GHz printer across the house. I see no obvious change in ping times/reliability when I start or stop the service on both machines.

Odd.