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

I had five running: three Pi Zero W, one a Pi 3, another a Pi 3B+. The house is around 1600 sq ft, 1.5 stories. Yards are small.

I have three Unifi AP’s, two in the house and one in detached garage. Wifi covers entire property.

Just checked and there are 8 APs advertising that aren’t mine.

Only knew of a problem by looking at Unifi console which gives an overall ‘Wifi experience’ percent. Usually the console reports a 90%+ score but with all five Pi’s running it was 28. When I looked at the clients I would see all the 2.4 drop from Unifi and reconnect. Anyway, I i intend to continue working on this system because the Monitor system is accurate and detects changes minutes before the Unifi or NMAP platforms.

Just wanted to add my experience to the mix: after messing around with a BT adapter on my HASS.IO VM and having constant stability issues with the BLE Tracker Addon + a couple of Tiles, I gave up and bought an RPi 3B+ just for this software. It has worked impeccably, kudos on a job well done!

I use the -b flag and a couple of filters and don’t keep the Tile MACs in the known devices list, as for some reason when I do that they are seen both as known MACs (and always “not_home”) and separately when scanning (which sees them correctly)…after removing them from the list, they are now just seen as part of the regular scan, so all is well.

I guess it would also be nice to have it start automatically, but I have no clue how to mess around with system.d and am not sure how it could be monitored that way…

To detect presence of the car, not of a person.

The BT and WIFI radios interfere with one another and other 2.4GHz radios nearby. If you’re using just one of the wireless technologies only, the interference problems seem to go away for a lot of people.

well how do you connect the pi zero to HASS if you disable WiFI, this I don’t understand

I got long ago a NUT beacon, will try to see if that works for the car. The beacon has
Under Service data:
UUID
DATA (its like a mac address)

Under Service UUID
UUID (different from service uuid above)

which one shall go to mqtt_aliases and known_mac _addresses or known_beacon_addresses??

I put the mac address under known_beacon_addresses, and in log I only see this (notice how the mac is slightly different from the mac that I read with a beacon tracker which is C3:3B:12:A4:96:8E)

0.2.016 07:14:32 pm [CMD-RAND]  [passed filter] data: C3:3B:12:A4:9:8 SAI) DT EGH pdu: SCAN_RSP rssi: UKN dBm flags: none man: unknown delay: 1

If in known_beacon_addresses I put this modified mac address C3:3B:12:A4:9:8 is not recognized by monitor (I guess because is a wrong format?)

The purpose is what he said:

I can use that information in other automations. Car at home and I’m not, use the public transport travel times for my “returning home” ETA. Car leaves home and I don’t, turn on all the lights and sound the sirens :stuck_out_tongue:

Anyone got any pointers?
Twice now I’ve tried to update (git pull) on two zeros from an old version to the latest (tarring the folder first) & from what I can see they seem to work from the pi’s perspective. My issue on both instances is that my HA does not get the updates as it did before.

Pi 1 is the master & Pi 2 points to it as does the HA

I use the built in mqtt in the HA & don’t have mosquito_sub or pub to do a test & am at a loss on how to trouble shoot.

For now I’ve put back the backups on both Pis & all is working again (though the older version isn’t as stable)

you can install mosquitto_pub/sub on any of your machines, including the pi zeroes.

@andrewjfreyer Hi, just upgraded to 0.2.053 but having big issue, not connecting to mqtt broker. I have no user and no password in my mqtt

================== BEGIN LOGGING ==================
Connection Refused: not authorised.
Error: The connection was refused.
0.2.053 14-03-2019 12:58:05 pm [CMD-ERRO]       mqtt broker went offline, or a p                                 assword/username combination was rejected. attempting subscribe in 10 seconds...

this the log in HASSIO mosquitto

1552568448: New connection from 192.168.1.237 on port 1883. 1552568448: Socket error on client <unknown>, disconnecting.

this my mqtt_preferences, which were working in previous version (I did not update since long)

# IP ADDRESS OR HOSTNAME OF MQTT BROKER
mqtt_address=192.168.1.11

# MQTT BROKER USERNAME (OR BLANK FOR NONE)
mqtt_user=""

# MQTT BROKER PASSWORD (OR BLANK FOR NONE)
mqtt_password=""

tried also as below but same error

mqtt_user=
mqtt_password=

I patched my copy of the MQTT file, to remove the username/password lines from mosquitto_pub, to get it to work with a broker that doesn’t require authentication.

It’s ugly, but it works…

mmhh with a scale from 1 to 10 how difficult is that? I may just wait a fix or reverse ot a previous version of monitor.

May we use in HASSIO addon multiple logins? Like below?

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

I tried but when doing this from inside monitor host

sudo mosquitto_sub -h "192.168.1.11" -u "test" -P "test" -t "#"

I receive this log in HASSIO mosquitto addon

1552591309: New connection from 192.168.1.238 on port 1883. 1552591309: |-- mosquitto_auth_unpwd_check(test) 1552591309: |-- ** checking backend http 1552591309: |-- url=http://127.0.0.1:8080/login 1552591309: |-- data=username=test&password=test&topic=&acc=-1&clientid= /bin/auth_srv.sh: line 37: LOCAL_DB["${username}"]: bad array subscript 2019/03/14 20:21:49 socat[36] E waitpid(): child 37 exited with status 1 1552591309: |-- http req fail url=http://127.0.0.1:8080/login re=Server returned nothing (no headers, no data) 1552591309: |-- url=http://127.0.0.1:8080/login 1552591309: |-- data=username=test&password=test&topic=&acc=-1&clientid= /bin/auth_srv.sh: line 37: LOCAL_DB["${username}"]: bad array subscript 2019/03/14 20:21:49 socat[42] E waitpid(): child 43 exited with status 1 1552591309: |-- http req fail url=http://127.0.0.1:8080/login re=Server returned nothing (no headers, no data) 1552591309: |-- url=http://127.0.0.1:8080/login 1552591309: |-- data=username=test&password=test&topic=&acc=-1&clientid=

If you can use a text editor, it’s trivial. Edit support/mqtt and delete the references to -P "$mqtt_password" and -u "$mqtt_user".

2 Likes

I can confirm that this is is a temporary solution that won’t effect other operations of monitor. However, it’ll be a bit more involved than a standard git pull to update to future versions.

1 Like

The expression you’re looking for is that it’s a horrible hack, and things will break when you upgrade :wink:

2 Likes

The expression I would use is “what the hell are you (@Klagio) doing running an MQTT broker with no authentication?”

everything is inside my LAN no external access. I started like this because of a couple of project for which only no username no password was working … I may start to fix it with ACL or so, but its getting a lot of time to understand all this.

If I put 2 logins (one no username no password, another with username password) in hassio addon configuration, then I use a device with the username password I recieve this error, I do not understand

1552599685: New connection from 192.168.1.176 on port 1883. 
1552599685: |-- mosquitto_auth_unpwd_check(test) 
1552599685: |-- ** checking backend http 
1552599685: |-- url=http://127.0.0.1:8080/login 
1552599685: |-- data=username=test&password=test&topic=&acc=-1&clientid= /bin/auth_srv.sh: line 37: LOCAL_DB["${username}"]: bad array subscript 
2019/03/14 22:41:25 socat[36] E waitpid(): child 37 exited with status 1 
1552599685: |-- http req fail url=http://127.0.0.1:8080/login re=Server returned nothing (no headers, no data) 
1552599685: |-- url=http://127.0.0.1:8080/login 
1552599685: |-- data=username=test&password=test&topic=&acc=-1&clientid= /bin/auth_srv.sh: line 37: LOCAL_DB["${username}"]: bad array subscript

thanks it works. That was easy, the difficult part will be remember what I did a month from now, lol

1 Like

Well, until this week, it was accessible only on 127.0.0.1 :wink: Only with the arrival of monitor have I needed to open it up any further.

I will fix that at some point, but not today :smiley:

The script exited last night with “monitor.sh: line 1519: -80-: syntax error: operand expected (error token is “-”)”, any idea what that is?

1 Like