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

@sota the answer depends on whether you running beta or not - the beta has aliases enabled by default. The master branch uses the old method of creating a separate file. Please refer to each respective documentation set.

I’d recommend going with beta - it is more feature advanced and I’m going to merge into master here in the coming days anyway.

IF ON MASTER BRANCH:

known_static_addresses:

00:11:22:33:44:55 Example1

With this setup in this file, monitor will use Example1 as a fallback for the name of the 00:11:22:33:44:55 when sending MQTT messages. This prevents JSON sent via MQTT from having a blank or unknown “name” field.

mqtt_aliases:
00:11:22:33:44:55 Example2

With this setup in this file, monitor will use Example2 as the last path component when posting MQTT messages: `monitor/[NAME OF MONITOR NODE]/example2


IF ON BETA BRANCH:

known_static_addresses:

00:11:22:33:44:55 Example1

With this setup in this file, monitor will use Example1 as a fallback for the name of the 00:11:22:33:44:55 when sending MQTT messages and as the last path component when posting MQTT messages: `monitor/[NAME OF MONITOR NODE]/example1.

If you want to disable this behavior, set PREF_ALIAS_MODE=false in behavior_preferences.

OK, great. Also, I’ve just discovered that you support the MQTT Device Tracker Platform so progress is finally being made.

Thanks!

1 Like

I’m not seeing my tracked devices appearing. The is what I’m getting on MQTT:

home
**qos**  : 0,  **retain**  : false,  **cmd**  : publish,  **dup**  : false,  **topic**  : monitor/ground_floor/pat_s_iphone_7/device_tracker,  **messageId**  : ,  **length**  : 56

My device tracker entry is:

- platform: mqtt
  devices:
    pats_iphone7: 'monitor/ground_floor/pat_s_iphone_7/device_tracker'

But my device_tracker doesn’t appear.

1 Like

Run monitor from the command line with the -V flag for verbose logging. That’ll help us diagnose.

OK, I finally got back to this again. One error I noticed was that I had single quotes around the MQTT username and password, which the HASSIO broker didn’t seem to like. However, I’m still not seeing tracker devices being created. Here’s the log from my MQTT broker:

1555768066: |-- data=username=xxxx&password=yyyy&topic=&acc=-1&clientid=
[INFO] found mqtt on local database
1555768066: |-- getuser(mqtt) AUTHENTICATED=1 by http
1555768066: New client connected from 192.168.16.91 as ground_floor31286 (c1, k60, u'mqtt').
1555768067: |-- mosquitto_auth_acl_check(..., client id not available, mqtt, monitor/ground_floor/pat_s_iphone_7, MOSQ_ACL_WRITE)
1555768067: |-- url=http://127.0.0.1:8080/superuser
1555768067: |-- data=username=mqtt&password=&topic=&acc=-1&clientid=
1555768067: |-- aclcheck(mqtt, monitor/ground_floor/pat_s_iphone_7, 2) SUPERUSER=Y by http
1555768067: |--  Cached  [52199086E1E8F745A616308A7A88C09E2572EBA9] for (client id not available,mqtt,2)
1555768067: |-- mosquitto_auth_acl_check(..., client id not available, mqtt, monitor/ground_floor/pat_s_iphone_7, MOSQ_ACL_READ)
1555768067: |-- aclcheck(mqtt, monitor/ground_floor/pat_s_iphone_7, 1) CACHEDAUTH: 0
1555768067: |-- mosquitto_auth_acl_check(..., client id not available, mqtt, monitor/ground_floor/pat_s_iphone_7, MOSQ_ACL_READ)
1555768067: |-- aclcheck(mqtt, monitor/ground_floor/pat_s_iphone_7, 1) CACHEDAUTH: 0
1555768067: |-- mosquitto_auth_acl_check(..., client id not available, mqtt, monitor/ground_floor/pat_s_iphone_7, MOSQ_ACL_READ)
1555768067: |-- aclcheck(mqtt, monitor/ground_floor/pat_s_iphone_7, 1) CACHEDAUTH: 0
1555768067: Client ground_floor31286 disconnected.

Output from monitor with -V:

> btle text pid = 30881
> btle listener pid = 30883
> mqtt listener pid = 30886
> packet listener pid = 30890
> beacon database time trigger pid = 30893
[-] 0.2.184 20-04-2019 02:47:35 pm [CMD-RAND]   [passed filter] data: 38:F2:C8:84:17:18 pdu: ADV_NONCONN_IND rssi: -73 dBm flags: none man: Microsoft delay: 0
[-] 0.2.184 20-04-2019 02:47:36 pm [CMD-INFO]   **** started arrival scan [x1 max rep] ****
[-] 0.2.184 20-04-2019 02:47:36 pm [CMD-RAND]   [passed filter] data: 4E:6B:A4:4C:7B:FB pdu: ADV_IND rssi: -68 dBm flags: 0x1a man: Apple, Inc. delay: 1
[-] 0.2.184 20-04-2019 02:47:43 pm [CMD-SCAN]   (No. 1) 88:6B:6E:3E:59:79 arrival?
[-] 0.2.184 20-04-2019 02:47:44 pm [CMD-NAME]   88:6B:6E:3E:59:79 Pat’s iPhone 7 Plus  Apple Inc
monitor/ground_floor/pat_s_iphone_7/device_tracker home
[-] 0.2.184 20-04-2019 02:47:45 pm [CMD-POST]   monitor/ground_floor/pat_s_iphone_7/device_tracker
[-] 0.2.184 20-04-2019 02:47:46 pm [CMD-POST]   monitor/ground_floor/pat_s_iphone_7
 {
    "id":"88:6B:6E:3E:59:79",
    "confidence":"100",
    "name":"Pat's iPhone 7",
    "manufacturer":"Apple Inc",
    "type":"KNOWN_MAC",
    "retained":"false",
    "timestamp":"Sat Apr 20 2019 14:47:43 GMT+0100 (IST)",
    "version":"0.2.184"
 }
1 Like

you still have to add an mqtt device tracker, or a sensor, in HA.

Yes, I’ve done that in my device_trackers.yaml:

- platform: mqtt
  devices:
    pats_iphone7: 'monitor/ground_floor/pat_s_iphone_7/device_tracker'

I think the problem is with this though. If I use the mqtt.publish service to push “home” to the topic, it’s still not creating the device. Also, I notice that MQTT retain is false - should it be true?

Success! There were a lot of duplicated entries in my known_devices.yaml from previous attempts to get this to work. I cleared them out and restarted Home Assistant. The devices are now reporting presence correctly. One oddity is that the source type is GPS, is this correct?

|[device_tracker.pats_iphone7](https://hass.io:8123/dev-state#)|home|source_type: gps friendly_name: pats iphone7|

1 Like

do you not retain the messages on the mqtt server? I added the -x to my monitor instances and even on a restart my values seem to stay.

@andrewjfreyer these aliases look interesting, im going to have to look into these next time I update (currently still on 0.2.148). I am having major life changes which will allow me to use your monitor script much more. I purchased a house that is right around 1900 SQ feet which will give me much different idea of bluetooth presence than what I currently use.

Because of the Radio RA2 dimmers/occupancy sensors that I want to use I will most likely be straying away from HASS. Luckily your script send messages to an MQTT server so it will still be utilized. More to come soon, you are making strides by the way. keep it up!!!

1 Like

you can set the source type in your config to bluetooth if you like.

@benjimatt I had spotted the -x switch in the monitor docs, but it didn’t work for me because of the old entries I had in known_devices.yams. I’ve now set it permanently in the systemctl file.

@andrewjfreyer Sorry, I’ve tried putting source_type in the sensor definition but it doesn’t seem to work. I can change the attribute on the states page, but it doesn’t survive a restart.

Sorry if this was previously discussed - I did try to skim through the 1200 posts :slight_smile:

Is there a list/guide of what flags are available and what they do? Today I am getting a second pi delivered to me, and I am confused which flags I need to use to configure it properly (although I believe it is -tad from the readme). Do I need to change the config for the original one (i think the readme says -tr but I don’t know if those are set by default)?

@coolguymatt I think if you use -help you will get the list of flags. On the Pi closest to the entrance I used -x -tr (and also -u to update the service file); on the 1st floor Pi I used -x -tad and it seems to work as intended. Hovever, I still have a bit of reading to do before I’m happy with the overall setup of the sensors.

1 Like

did you see the readme/faq on github? have you looked through the helpfile -h?

-h was what I needed, thanks @andrewjfreyer and @sota

1 Like

Hi Andrew,

I tried the latest beta 0.2.185 still crashing and getting the error.

monitor.sh: line 1589: 00cfa7d4451573ae313a992f137d: value too great for base (error token is “00cfa7d4451573ae313a992f137d”)

1 Like

Can you run with verbose logging and flag debugging? Your system is, for some reason, not parsing strings properly.

monitor.sh -b -V -F

Thanks Andrew, will run and post output if it happens again.

This is the second time one of my devices is marked off when my door hasn’t been opened at all. (Using -tad) how can I investigate what happened?

Also. now that -r is back does it look for departs even when -tr is set?