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

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 192.168.1.238 is where monitor is running

 New connection from 192.168.1.238 on port 1883

How you do that?

p.s.
please note that 192.168.1.238 is where monitor is running

 New connection from 192.168.1.238 on port 1883 #mosquitto log (host 192.168.1.16

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 192.168.1.238 on port 1883. 1549872148: Socket error on client <unknown>, disconnecting.

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

mqtt_publisher_identity=''

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

# PUBLISHER IDENTITY
mqtt_publisher_identity='office_pi3'

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"
}

EDIT
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.

@andrewjfreyer

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ā€¦

@andrewjfreyer
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:

First:

sudo btmon

Second:

#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.

1 Like

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

pi@raspberrypi:~ $ 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.