Home Assistant Community

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

Tags: #<Tag:0x00007fcf53cbf398> #<Tag:0x00007fcf53cbedf8>

On the device you are running monitor on, try running mosquitto_sub or mosquitto_pub and see if it will connect to your broker.


Ok, but is where monitor is running

 New connection from on port 1883

How you do that?

please note that is where monitor is running

 New connection from on port 1883 #mosquitto log (host

Google will help with mosquitto_sub or _pub.


When running the script I do not get the error of ACL denying, but a more simple

1549872148: New connection from on port 1883. 1549872148: Socket error on client &lt;unknown&gt;, disconnecting.

I have seen this client id problem a few times on the forums lately. Try setting


to something (anything). In the motion setup I mean.


Its already there. Pluis in my HASSIO mosquitto configuration there is no configuration directory, no ACL


Also this is my mosquitto configuration (active is false)

  "logins": [
      "username": "",
      "password": ""
  "anonymous": true,
  "customize": {
    "active": false,
    "folder": "mosquitto"
  "certfile": "fullchain.pem",
  "keyfile": "privkey.pem"

Ok I changed to port 1884 (from 1883) and its working … but I have both port in the mosquitto hassio ocnfiguration, and other devices all connect to 1883 … strange

p.s. do you also receive the message “Error: success” in monitor log? Means no error, correct?

EDIT, EDIT, the script crashes my HASS instance, could not find anything in the log … have to investigate further (when stopping the script no more crashes)


SO i dont use node red…But this IDEA could help you. (Curious to know how your automations are setup)

This is how my current scripts are running

I only trigger departs when my door closes. WHen my door opens it triggers a cancel of the depart script just incase I have multiple door openings in a small amount of time.

the depart goes

  • send depart scan
  • wait 20 seconds
  • send depart scan
  • wait 40 seconds
  • send depart scan
  • wait 60 seconds
  • Check status of both sensors in my house
  • if mismatched send a restart command and wait 30 seconds
  • If not mismatched check if sensor is 100 or 0 and turn off / on certain automations based on these numbers

The only downside would be if I wanted an arrival automation to happen quickly after depart. In this setup it would take about 2-3 minutes for my arrival automations to turn back on. Let me know if something is unclear


Thank you…
So for my setup its like this

  • When i open the door = nothing
  • When i close the door, it checks our singal and if 100 for both of us = it will run a depart scan
  • If the scan was already running, it will cancel that, wait 15 sec and run again
  • Issue i have is if lets say someone is at 100 inside and i go outside, it will rrun both scripts - arrive and depart and will depart me because i am outside. Now lets say i go into the garage and since the arrival is running because the 2nd person was 100 - it will get me again and bring me home.

I want a check in place where if it departs me; dont bring me back home for lets say 3 mins as i dont want it to bonce around.



The code snippets I sent before were from running via command line as I was tinkering a lot on the weekend getting the setup just correct.

None the less, ive just stopped it and run via command line, and im not getting the messages anymore. Very strange…

Thank you for investigating anyway and thank you for a great script.

1 Like

my theory was that you had a latent older version running in the background - glad to hear that things are working well now!


I would create your automations per person and just set a timer after the door closes for 3 min (cancel timer when door opens). After 3 min if user A is 100 turn on depart automations (not running them just making sure they are on)

if user A is 0 after 3 min turn on the Arrival automations (no executiion , just making sure the automation is on)

I would send you a node red config but I dont use nodeRed and have very little desire to learn it at this time. you could check my scripts in my github. (most that I speak of here are toward the bottom)



I have attached a picture of my node red. I have a timer in place in case I am waiting in the car on the driveway already departed at 0 and person B who is at 100 opens the front front door and come out. Now since person B was 100 and I was at 0. Both depart and arrive will run. And there is a chance it may bring me back in if I am withing range slightly. Not sure about the logic but I want it so if my status just changed from home to away, don’t look at me for 3 mins.


OHHHHH I completely missed the part where you are using -TAD
I personally use -TRD

do you have a Camera or Motion sensor that you could use for a arrival trigger instead of the doors? Possibly a fence ? do both users enter/exit from either door?


Yes I am using tad so both are on triggers only. We use the same door in and out. And if one of us are outside departed at 0 and one is inside. As soon as that door opens it will run both scans as it thinks I am coming in from 0 and person B is leaving. Running both are fine it’s just that if I am already departed and waiting outside perhaps within range of pi then I might get arrived again even though I’m out and staying out. It’s a tough one…


Thanks again for your work on this.
I just wondered if you could suggest any troubleshooting I can do to see why I can’t see any of my iBeacons in monitor.sh? I can see them all from my iPhone and from a Win10 PC running Bluetooth Beacon Interactor. I can’t see them either by MAC address or by UUID. I am running with the -b flag and with default settings.
Any advice much appreciated.
Thanks very much


It would be helpful to see what btmon sees from monitor's perspective. To do this, it’s most convenient to have two separate ssh sessions:


sudo btmon


#stop monitor
sudo systemctl stop monitor

#run an le scan
sudo hcitool lescan

Now, we can see what btmon sees. When you first run the hcitool lescan you’ll see a number of devices show up, but it’ll “settle down” in about 15 - 20 seconds. Then we can go back to btmon to see whether or not an iBeacon was seen. Note that btmon reports ibeacon UUIDs with hex bytes ordered with incorrect endian-ness (i.e., backwards) so if your iBeacon begins with 1A2B3C, you’ll see btmon show it as 3C2B1A.

The problem may be that your beacon sends an iBeacon package less frequently than other beacons. I’m working on a solution, so make sure to stay on the beta branch.


Many thanks!
When I run the second set of commands, I get an error on the second command

[email protected]:~ $ sudo hcitool lescan
Set scan parameters failed: Input/output error

So it looks like it doesn’t want to run an LE scan for some reason? It’s a new Pi Zero W and I have followed the setup steps as per your guide. ISTR I needed to install a couple of libraries to get monitor to run without errors, but I didn’t note down which ones I’m afraid.

What do you advise?
Thanks very much again for your help.