Reliable presence detection but not bluetooth

Thanks John.
I’m still confused with the mqtt_preferences and the entry in configuration.yaml for the device tracker. Could you take a look at the following and tell me if I am in the right direction?

In configuration.yaml

  - platform: mqtt
    devices:
        colleen_android: 'monitor/android/[C0:EE:FB:F6:1A:4A]/device_tracker'

The mqtt_preferences file

# MOSQUITTO PREFERENCES
#								
# ---------------------------

# IP ADDRESS OR HOSTNAME OF MQTT BROKER
mqtt_address=192.168.1.xx

# MQTT BROKER USERNAME
mqtt_user=mqtt

# MQTT BROKER PASSWORD
mqtt_password=xxxx

# MQTT PUBLISH TOPIC ROOT 
mqtt_topicpath=monitor

# PUBLISHER IDENTITY 
mqtt_publisher_identity='android'

# MQTT PORT 
mqtt_port='1883'

# MQTT CERTIFICATE FILE
mqtt_certificate_path=''

#MQTT VERSION (EXAMPLE: 'mqttv311')
mqtt_version=''

Any help welcome

OK, I still did not have any luck with Monitor but the good news is that I configured Ping and it has been working flawlessly for the last couple of days. I have no dropouts or problems with both our Android phones going to sleep. I will run with this for a week and see how it goes.

I am going to give up with Monitor and remove the Pi3 as it is not ideal to have an additional box anyway and if I ever figure out how to pass through the Bluetooth from the NUC running Proxmox then maybe I will move back to Bluetooth as well.

I would like to add an additional form of presence detection so it is reliable, so I may still look at adding other options. In the meantime, I will run with Ping.
I would be interested to see what the new Android app brings that is being developed which may solve some problems for many of us.

A little off-topic but moving to a NUC and Proxmox was a great move. Hassio runs great in its VM and I have another VM running Windows 10 which runs my Plex server and newsgroup programmes. Previously these ran on a Pi3 and an old Thinkpad T420 for Plex etc. Now both replaced with a small NUC running both. I also love the fact I can easily back these VMs up or even clone them so test new versions of Hassio without breaking the production one.

Thanks for all your input into this discussion. It’s such a great community and one I am happy to be part of.

I’ve always found that GPS based trackers are less than ideal for home/away detection. They can take some time to update, so you don’t get shown as home or away for 5, 10, 15 minutes (or more, depending on the configuration of your GPS tracker). With monitor it takes maybe 30 seconds to detect home/away.

:slight_smile: 5 minutes is a long time to stumble around in the dark or wait for the heating!

Yes, I am not keen on GPS as the apps suck the life out of the battery. I have enough apps running on my phone without another power hungry one.
Like you say, updating can take some time but I guess if you want to track where you phones are outside of home they can be useful. Combining with something quicker to update is also a good option.

When I was using Bluetooth I found it to be very reliable and the updating was very fast. I would pull up on the drive and I was updated as home in seconds. It is a shame I am unable to use it with my NUC and Proxmox setup now but you never know, I might still figure it out!

Sorry for the late reply, 2 things in your configuration.yaml that come to mind:

  • colleen_android should be indented only 2 spaces after “devices”, it should start under the letter “v”, whereas in your case it seems to start under the letter “c”

  • the MAC address there should not be between brackets, it should be ‘monitor/android/C0:EE:FB:F6:1A:4A/device_tracker’

Looks fine other than that…

Also, before I used to manually run it on the Pi after every restart (because I wanted it to run with flag -b), but the advice given here solved that issue, just do this: [monitor] Reliable, Multi-User, Distributed Bluetooth Occupancy/Presence Detection - replace “vi” with “nano”, though, for a smoother text editing experience :smiley:

Hi
Thanks for your reply.
I noticed the error in the spacing and now have the following.

  - platform: mqtt
    devices:
      colleen_android: 'monitor/android/colleen/device_tracker'
      martin_android: 'monitor/android/martin/device_tracker'

I also realised the error with the [ ] and removed these and used the alais instead.
I can see the entities for the phones in Hass but they remain at not_home even when Bluetooth is connected on our phones.

In the MQTT addon log I can see the following

1563738101: New connection from 192.168.1.xx on port 1883.
1563738101: New client connected from 192.168.1.xx as android14249 (p2, c1, k60, u'mqtt').

so I assume messages are getting through but the state is not changing from not_home to home.
I keep looking to see if I can find the issue but if you can think of anything else please let me know.
Thanks

When you run the script manually with -b, do you see your phones in the list of BLE items it is finding?

Yes it finds the phones which is why I could not work out the problem.
I’ll post so further details from the terminal tonight.
Thanks.

OK, I think I have done something wrong installing and configuring Monitor so I will start again and reinstall the OS from scratch and see if I can get this working. Won’t be able to do this until Friday as working away this week.

Hi,
OK, I have started from scratch and imaged the Pi again and followed through all the instructions but I have come to the same issue where the device trackers are not updating from not_home to home when both the phones are home and Bluetooth is turned on.
So if you nice helpful people could help I have included below everything I know.
I am using a Pi3 which Bluetooth is already configured.
Here is the outputs and configurations that I have. I just cannot get to the bottom of why this does not work.


Output from the terminal following running sudo bash monitor.sh -b

pi@raspberrypi:~/monitor $ sudo bash monitor.sh -b
> starting monitor.sh (v. 0.2.197)...
> removing web request caches
> C0:EE:FB:F5:D8:BC confidence topic: monitor/andriod/martin (has not previously connected to hci0)
> C0:EE:FB:F5:D8:BC device_tracker topic: monitor/andriod/martin/device_tracker [not_home or home]
> C0:EE:FB:F6:1A:4A confidence topic: monitor/andriod/colleen (has not previously connected to hci0)
> C0:EE:FB:F6:1A:4A device_tracker topic: monitor/andriod/colleen/device_tracker [not_home or home]
[+] 0.2.197 26-07-2019 11:30:56 am [CMD-MQTT]   monitor/andriod/martin { ... confidence : 0 ... }
[+] 0.2.197 26-07-2019 11:30:56 am [CMD-NAME]   C0:EE:FB:F5:D8:BC martin  OnePlus Tech Shenzhen Ltd
[+] 0.2.197 26-07-2019 11:31:05 am [CMD-MQTT]   monitor/andriod/colleen { ... confidence : 0 ... }
[+] 0.2.197 26-07-2019 11:31:05 am [CMD-NAME]   C0:EE:FB:F6:1A:4A colleen  OnePlus Tech Shenzhen Ltd
[+] 0.2.197 26-07-2019 11:32:11 am [CMD-NAME]   C0:EE:FB:F5:D8:BC martin  OnePlus Tech Shenzhen Ltd
[+] 0.2.197 26-07-2019 11:32:11 am [CMD-NAME]   C0:EE:FB:F6:1A:4A colleen  OnePlus Tech Shenzhen Ltd


# ---------------------------
#
# STATIC MAC ADDRESS LIST
#
C0:EE:FB:F5:D8:BC martin
C0:EE:FB:F6:1A:4A colleen
# 00:00:00:00:00:00 Alias #comment
# ---------------------------

#----------------------------
#
behavior_preferences
#
#------------------------------

#ARRIVE TRIGGER NEGATIVE FILTER(S)
PREF_FAIL_FILTER_ADV_FLAGS_ARRIVE="NONE"
PREF_FAIL_FILTER_MANUFACTURER_ARRIVE="NONE"
PREF_DEVICE_TRACKER_REPORT=true


# ---------------------------
#
# MOSQUITTO PREFERENCES
#
# ---------------------------

# IP ADDRESS OR HOSTNAME OF MQTT BROKER
mqtt_address=192.168.1.x

# MQTT BROKER USERNAME
mqtt_user=mqtt

# MQTT BROKER PASSWORD
mqtt_password=xxxxxxxx

# MQTT PUBLISH TOPIC ROOT
mqtt_topicpath=monitor

# PUBLISHER IDENTITY
mqtt_publisher_identity='andriod'

# MQTT PORT
mqtt_port='1883'

# MQTT CERTIFICATE FILE
mqtt_certificate_path=''

#MQTT VERSION (EXAMPLE: 'mqttv311')
mqtt_version=''

#---------------------------
Entry in HASS configuration.yaml for device_tracker:
#---------------------------
device_tracker:
  - platform: mqtt
    devices:
      colleen_android: 'monitor/android/colleen/device_tracker'
      martin_android: 'monitor/android/martin/device_tracker'


Log for MQTT Add-on in HASS

Log
[11:53:37] INFO: Setup mosquitto configuration
[11:53:37] INFO: Found local users inside config
[11:53:37] INFO: Initialize Hass.io Add-on services
[11:53:37] INFO: Initialize Home Assistant discovery
[11:53:37] INFO: Start Mosquitto daemon
1564138417: mosquitto version 1.6.3 starting
1564138417: Config loaded from /etc/mosquitto.conf.
1564138417: Loading plugin: /usr/share/mosquitto/auth-plug.so
1564138417:  ├── Username/password checking enabled.
1564138417:  ├── TLS-PSK checking enabled.
1564138417:  └── Extended authentication not enabled.
1564138417: |-- *** auth-plug: startup
1564138417: Opening ipv4 listen socket on port 1883.
1564138417: Opening ipv6 listen socket on port 1883.
1564138417: Opening websockets listen socket on port 1884.
1564138417: Opening ipv4 listen socket on port 8883.
1564138417: Opening ipv6 listen socket on port 8883.
1564138417: Opening websockets listen socket on port 8884.
1564138417: Warning: Mosquitto should not be run as root/administrator.
1564138419: New connection from 172.30.32.1 on port 1883.
1564138419: New connection from 192.168.1.38 on port 1883.
[INFO] found mqtt on local database
1564138420: New client connected from 192.168.1.38 as andriod27243 (p2, c1, k60, u'mqtt').
1564138420: New connection from 192.168.1.38 on port 1883.
1564138420: New client connected from 192.168.1.38 as andriod27246 (p2, c1, k60, u'mqtt').
1564138420: Client andriod27243 disconnected.
1564138420: New connection from 192.168.1.38 on port 1883.
1564138420: Socket error on client <unknown>, disconnecting.
1564138420: New connection from 172.30.32.1 on port 1883.
[INFO] found homeassistant on local database
1564138420: New client connected from 172.30.32.1 as auto-AF7F59C6-040C-53E5-D596-64F60264953C (p2, c1, k60, u'homeassistant').
1564138420: New client connected from 192.168.1.38 as andriod27248 (p2, c1, k60, u'mqtt').
1564138420: Client andriod27248 disconnected.
1564138420: New connection from 192.168.1.38 on port 1883.
1564138420: New client connected from 192.168.1.38 as andriod27251 (p2, c1, k60, u'mqtt').
1564138420: New connection from 192.168.1.38 on port 1883.
1564138420: New client connected from 192.168.1.38 as andriod19058 (p2, c1, k60, u'mqtt').
1564138420: Client andriod27251 disconnected.
1564138420: New connection from 192.168.1.38 on port 1883.
1564138420: New client connected from 192.168.1.38 as andriod27257 (p2, c1, k60, u'mqtt').
1564138420: Client andriod27257 disconnected.

Any help appreciated.

Thanks.

mqtt_publisher_identity=‘andriod’ is one thing I notice, you have the path as “android” in HA :slight_smile:

Do you mean the device_tracker path? Should I remove the andriod for the path so it reads:

device_tracker:
  - platform: mqtt
    devices:
      colleen: 'monitor/colleen/device_tracker'
      martin: 'monitor/martin/device_tracker

No, I mean you have a typo, it’s “andriod” vs. “android”, change one to the other

Are, well spotted. I’ll change this now and give it another go. Thanks.

No change on getting the device tracker entities to update from not_home to home after changing this.

Could this line in the terminal be the problem about not previously connecting the hci0? do you get this?

C0:EE:FB:F5:D8:BC confidence topic: monitor/android/martin (has not previously connected to hci0)

Also, does this line need to have quotes around true?

PREF_DEVICE_TRACKER_REPORT=true

Here are the differences vs. my config:

  • I have no MACs set in the static mac address list

  • my behavior preferences looks like this:

#MAX RETRY ATTEMPTS FOR ARRIVAL
PREF_ARRIVAL_SCAN_ATTEMPTS=1

#MAX RETRY ATTEMPTS FOR DEPART
PREF_DEPART_SCAN_ATTEMPTS=2

#SECONDS UNTIL A BEACON IS CONSIDERED EXPIRED
PREF_BEACON_EXPIRATION=240

#MINIMUM TIME BEWTEEN THE SAME TYPE OF SCAN (ARRIVE SCAN, DEPART SCAN)
PREF_MINIMUM_TIME_BETWEEN_SCANS=15

#ARRIVE TRIGGER FILTER(S)
PREF_PASS_FILTER_ADV_FLAGS_ARRIVE="."
PREF_PASS_FILTER_MANUFACTURER_ARRIVE=".
"

#ARRIVE TRIGGER NEGATIVE FILTER(S)
PREF_FAIL_FILTER_ADV_FLAGS_ARRIVE=“NONE”
PREF_FAIL_FILTER_MANUFACTURER_ARRIVE=“NONE”

PREF_DEVICE_TRACKER_REPORT=true

  • in HA I have the device’s MAC instead of “martin” in monitor/android/martin/device_tracker

I have taken out the static mac address list entries and checked the behavior preferences against yours.

PREF_PASS_FILTER_ADV_FLAGS_ARRIVE="."
PREF_PASS_FILTER_MANUFACTURER_ARRIVE="."

was different as mine was

PREF_PASS_FILTER_ADV_FLAGS_ARRIVE=".*"
PREF_PASS_FILTER_MANUFACTURER_ARRIVE=".*"

not sure if that makes a difference?

I updated my HA file to include the MAC address in lower case.
This may be a silly question but I have been using the MAC address that I got from my router. Do I need the Bluetooth MAC address as they are slightly different. If I look up the Bluetooth MAC on my phone the last number/letter of the MAC address is different to the one I get from my router?

You definitely need the Bluetooth MAC from your phone, because on your router what you actually see is the WiFi MAC, which is a completely different MAC (each network interface on a device has its own MAC). Also, it seems that it makes a difference to use upper-case, so write the MAC like that.

Thanks, I’ll give you suggestions a try and see how I get on.