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

how fast does this pick someone up?

“Fast, usually”

If you read the docs you’ll see that it scans when:

  • Some Bluetooth device (which may include your phone) to announce themselves, which starts a scan
  • You send a scan request

So, depending on your setup (do you have some way, like the door sensor mentioned way up in the thread, of triggering a scan; where is your monitor node physically located; what else is going on in the Bluetooth world around your node) it may pick you up as you approach, right about when you enter the house, of a few moments later.

For me it’s typically within plus or minus 10 seconds of somebody physically entering the house. Adjusting the position of that node would probably reduce the top end slightly, since currently signals from the area immediately around the front door are blocked by the walls.

Can you explain which service file you mean and where to find it? im sure ive done this before as i already have one monitor node running but im about to add a second one and cant remember how i did it last time! Thanks in advance!

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

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

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

Replace /local/bin/monitor with the folder you installed it in, and use the arguments you want.

Sorry im still a bit of a noob with all this. Is this a file i have to create or one that i can cd to and then edit via nano? Im running on a pi zero w using the instructions from the github. Thanks

Create it in /etc/systemd/system:

sudo nano /etc/systemd/system/monitor.service
sudo systemctl daemon-reload
sudo systemctl enable monitor
sudo systemctl start monitor
1 Like

Hi, I am struggling with this since the weekend… Using a pi zero W for my monitor. And a virtual machine for my home automation.
My home automation is able to discover a few tasmotas I have. Also seems my PI is sending the correct info, but I guess there is something very basic I am missing on my home automation as I get my iphone connected and same time disconnects. This is my log on mqtt:
1604054713: New connection from 192.168.0.35 on port 1883.
1604054713: New client connected from 192.168.0.35 as pi16603 (p2, c1, k60, u’mqttuser’).
1604054713: Client pi16603 disconnected.
1604054713: New connection from 192.168.0.35 on port 1883.
1604054713: New client connected from 192.168.0.35 as pi16606 (p2, c1, k60, u’mqttuser’).
1604054713: Client pi16606 disconnected.

I saw some other people posting the same, but did not find the answer yet. Any thoughts?

Hi, did you find a solution for this? I also have the same issue

I had a lot of problems running this on a Pi Zero W, it seems like it was underpowered for the task. Switching to a Pi 3 model A+ greatly improved the reliability.

Tks for the note @sota. This PI is 100% dedicated to monitor. I am new with home automation. Have been using domoticz (in another PI) for years without issues. But I really want to use a bluetooth monitor to trigger actions when I am around during specific times. Before I move to HA, I want to test it for some time. Did you have the same mqtt issue when you were with the pi zero w?

It was more to do with stability in general. Either the Bluetooth would stop scanning or else the Pi would fall off the network entirely.
I now have two Pi 3 A+ models on my ground and first floor and it works well using the monitor app. The scans are triggered by front and rear door sensors along with a motion sensor on the first-floor landing. It’s not 100% perfect, but it works well enough for me.

You have to check step-by-step. :wink:

  1. Setup your PiZero with monitor
  2. Edit the config file(s) on your PiZero
  3. Run monitor.sh in your SSH window, you will get some output. This will show you, how your devices are connecting and what they are telling your monitor instance
  4. If everything looks good, move to your HA instance. Everything good means, you see your devices connecting to monitor.sh without errors
  5. Check the credentials you have setup in your HA instance. Are these the credentials you are using in your monitor.sh config files?
  6. Is “discovery” in your MQTT instance enabled?
  7. Get MQTT explorer from the internet. Just search for it on google. There are other programs out there as well, what you want is something to track your MQTT traffic in your network.
  8. Check exactly what messages are going to be sent, which topic is used, and do the messages look ok
  9. If you get here and there is still nothing that points to errors, then do a short write up with your config settings in monitor.sh, the output that comes when running monitor.sh from the CLI and what MQTT explorer tells you.

:slight_smile:

1 Like

Hello,

I have a marginal problem. (Hassio 0.117.1)
The created mqtt sensor showing Unknown state.
My mqtt topic is this : monitor/Pi0/peterphone, it receives the message correctly within the mqtt integration.

Received message inside mqtt integration:

{"id":"00:EC:0A:7D:C5:E3","confidence":"100","name":"
Peterphone ","manufacturer":"Xiaomi Communications Co Ltd","type":"KNOWN_MAC","retained":"false","timestamp":"Sat Oct 31 2020 08:51:11 GMT+0000 (GMT)","version":"0.2.200"}

My sensor config:

sensor:
  - platform: mqtt
    state_topic: 'monitor/Pi0/peterphone'
    value_template: '{{ value_json.confidence }}'
    unit_of_measurement: '%'
    name: 'Pi0'

And by the way my Pi zero stops measuring (or I’m noob) after a while. I’m using monitor.sh -tadr, I would like to track my phone and tell wich room is in it, but it is not reporting after a few minutes even if I turn off my bluetooth it does not show confidence drop.

Tks @paddy0174. Probably I am doing something very stupid… When I run monitor.sh I get: -bash: monitor.sh: command not fuound.
Am I missing something?
Capture

If you are running it from ~/monitor then use bash ./monitor.sh

Tks @paddy0174 and @sota! Seems I my PI/mqtt are working well. I am almost sure it is something on HA. here you have the logs:




Any clue what can be the issue?

If you are inside the monitordirectory, you do bash monitor.sh. That should at least printout something like starting monitor.sh or something like that.

If that doesn’t work, what does ls -la inside the monitor directory print out? You should get a list with all files inside that directory, it is important, that the file monitor.sh does have the correct owner and permissions.

In my case it is owned by the user pi.

EDIT: That overlapped with your post, scratch that. :slight_smile: I’ll answer your next post.

This is how I have my config.yaml
yaml

it does. when I bash monitor.sh:
bash

and here is how the folder/files look: