How do I use bluetooth to track presence

Hi,
So i thrown a tantrum and was told I should ask properly, so here I try again.

I am trying my best to set up presence detection without a need to be online. I don’t want to expose my HA to the internet and I can’t even get my ISP to give me a static IP to do it.
What I figured is, it should be possible by sensing my phone (I want to track my phone, my wifes phone and her smart watch).
If all three are gone from the apartment I want automations to happen.

I see only two option how to achieve it. Connection to wifi and bluetooth or combination of the two.
I didn’t find any easy way to use wifi to achieve this since my wifi router is not supported (thanks Deco) and HA can’t figure out if my phone is on the same network, at least i didn’t find easy solution.

I decided to go bluetooth way.

I use recent 2022.12 build of HA on my RB4
I also have number of Shelly devices that can be, as of 2022.12, used as bluetooth proxy. I have no idea what active or passive is as the describtion expects me to know what unsolicited data from devices are. I was trying both passive and active setting or both at the same time for relays close to each other, but I don’t see any difference.

shelly setting

I used device tracker to find devices.
I used both Bluetooth LE and normal Bluetooth, while trying to figure this out and noticing that our phones and watch all use BLE I dediced to simplify the device tracker and use BLE only:

bluetooth:

device_tracker:
  - platform: bluetooth_le_tracker
    new_device_defaults:
    track_new_devices: true #turned this to false when I found all my devices
    interval_seconds: 5 # I was playing with these but didn't help
    consider_home: 20

Originaly it found my phone twice, 1 with normal BT and the second one with BLE.
Then I restored my HA version to reinstalled 2022.12 because I ended up with thousands of BT entities and found out there is no easy way to delete them(!) from HA. Now it finds only my phone as BLE.

Known_devices.yaml now shows all the devices (including hundereds of other devices discovered as well)

wonphone:
  name: WonPhone
  mac: BLE_AC:XX:XX:XX:XX:XX  #MAC redacted for this post
  icon:
  picture:
  track: true

I was able to track the phone for a while, but then it stopped being tracked at all. Same for my wifes phone. It shows them only as away. Only device that is still tracked is her watch. That was marked as away as she puts in the charger for the night, that probably puts the watch in some form of sleep mode.

In the companion app I turned on BLE transmitter to be able to be tracked. I tried differend modes to be tracked even increased the strenght of the transmitter, but home assistant can’t see the phone still.

Sadly most of the topics on this I found are either years old or have no answer.

https://community.home-assistant.io/t/enable-bluetooth-on-hass-os-for-bluetooth-and-ble-device-tracking/156441/17
https://community.home-assistant.io/t/bluetooth-presence-tracker/247030
https://community.home-assistant.io/t/use-bluetooth-devices-with-the-bluetooth-device-tracker/200731/7

1 Like

There’s a long thread about monitor on this forum, and it works rather well for me (and many others).

2 Likes

The best one I have ever used

Bluetooth
As far as I know bluetooth_tracker doesn’t work anymore as of 2022.7 unless one runs Home Assistant Core (and has pybluez installed) due to compatibility issues with the underlying dependency that doesn’t run on Python 3.10 (see here: https://github.com/home-assistant/core/issues/75049#issuecomment-1181688762)

Frenck has indicated that it can be fixed (Update to say that this integration is broken as of 2022.7.x · Issue #24115 · home-assistant/home-assistant.io · GitHub) if someone re-writes the integration, but no one has as of yet (and I can’t code).

Bluetooth LE
For bluetooth_le_tracker I get very different results. Currently I have both this issue: BLE device only appears 'away' after reboot host · Issue #79539 · home-assistant/core · GitHub and a device that remains being seen despite the battery being physically removed. No matter how often I reboot my HA instance.

I think I might be just dumb, but I don’t see a way in the topic to run Monitor without having another device like RPW to run the script. So unless I am wrong, there is no way to run it just on my RP4 without other devices.

You can run it on that Pi4 - if you use HAOS there’s an add-on or you can install it manually if you installed HA using Container or Core.

Some time has passed, I am still clueless. I tried installinging the add-on.

Now I have the addon set up like this:

broker: 192.168.68.66
port: 1883
username: name
password: password
topic_root: presence
publisher: ""

and I added known devices as I found them in know_devices.yaml from bt tracker

beacons: []
static:
  - A8:9C:ED:XX:XX:XX mi_9 #redacted
  - AC:92:32:XX:XX:XX wonphone
  - FC:F2:01:XX:XX:XX

Now it did this, then it stopped updating.

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-banner.sh: executing... 
-----------------------------------------------------------
 Hass.io Add-on: Bluetooth Presence Monitor
 Passive Bluetooth presence detection of beacons, cell phones, and other Bluetooth devices.
-----------------------------------------------------------
 Add-on version: 1.0.0
 There is an update available for this add-on!
 Latest add-on version: null
 Please consider upgrading as soon as possible.
 System: Home Assistant OS 9.4  (aarch64 / raspberrypi4-64)
 Home Assistant version: 2022.12.6
 Supervisor version: 2022.11.2
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] monitor.sh: executing... 
[21:37:10] INFO: Updating running configuration...
[cont-init.d] monitor.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[21:37:10] INFO: Starting required services...
Starting system message bus: dbus.
Starting bluetooth: bluetoothd.
[21:37:10] INFO: Updating Bluetooth Presence Monitor to latest version...
From https://github.com/andrewjfreyer/monitor
 + 87d433b...10b6cb7 master     -> origin/master  (forced update)
Previous HEAD position was 87d433b Merge pull request #289 from hmmbob/patch-1
HEAD is now at 10b6cb7 update intallation instructions
Already up to date.
[21:37:12] INFO: Starting Bluetooth Presence Monitor...
> updated monitor (v. Unknown) -> (v. 0.2.200)...
> using custom config directory [/opt/monitor]
using /opt/monitor as config dir
> A8:9C:ED:C5:32:89 confidence topic: presence/homeassistant/mi_9 (has not previously connected to hci0)
> A8:9C:ED:C5:32:89 device_tracker topic: presence/homeassistant/mi_9/device_tracker [not_home or home]
> AC:92:32:E7:7A:41 confidence topic: presence/homeassistant/wonphone (has not previously connected to hci0)
> AC:92:32:E7:7A:41 device_tracker topic: presence/homeassistant/wonphone/device_tracker [not_home or home]
> FC:F2:01:07:15:AC confidence topic: presence/homeassistant/fc_f2_01_07_15_ac (has not previously connected to hci0)
> FC:F2:01:07:15:AC device_tracker topic: presence/homeassistant/fc_f2_01_07_15_ac/device_tracker [not_home or home]
/usr/local/bin/monitor: line 1987: [: : integer expression expected
[-] 0.2.200 14-12-2022 09:37:22 PM [CMD-MQTT]	presence/homeassistant/mi_9 { ... confidence : 0 ... } 
[-] 0.2.200 14-12-2022 09:37:30 PM [CMD-MQTT]	presence/homeassistant/wonphone { ... confidence : 100 ... } 
[-] 0.2.200 14-12-2022 09:37:40 PM [CMD-MQTT]	presence/homeassistant/fc_f2_01_07_15_ac { ... confidence : 0 ... } 
[-] 0.2.200 14-12-2022 09:38:29 PM [CMD-RSSI]	PUBL 1C:B3:C9:07:4B:37 RSSI: -80 dBm (initial reading | 120 dBm) 
[-] 0.2.200 14-12-2022 09:39:15 PM [CMD-MQTT]	presence/homeassistant/mi_9 { ... confidence : 0 ... } 
[-] 0.2.200 14-12-2022 09:39:16 PM [CMD-NAME]	A8:9C:ED:C5:32:89 mi_9  Xiaomi Communications Co Ltd
[-] 0.2.200 14-12-2022 09:39:21 PM [CMD-MQTT]	presence/homeassistant/wonphone { ... confidence : 100 ... } 
[-] 0.2.200 14-12-2022 09:39:28 PM [CMD-MQTT]	presence/homeassistant/fc_f2_01_07_15_ac { ... confidence : 0 ... } 
[-] 0.2.200 14-12-2022 09:39:28 PM [CMD-NAME]	FC:F2:01:07:15:AC FC:F2:01:07:15:AC  Unknown
[-] 0.2.200 14-12-2022 09:46:35 PM [DEL-RAND]	RAND 52:C5:EB:BC:E9:FC expired after 445 seconds 
[-] 0.2.200 14-12-2022 09:46:37 PM [CMD-MQTT]	presence/homeassistant/wonphone { ... confidence : 100 ... } 

I restarted the addon and it did this

[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-banner.sh: executing... 
-----------------------------------------------------------
 Hass.io Add-on: Bluetooth Presence Monitor
 Passive Bluetooth presence detection of beacons, cell phones, and other Bluetooth devices.
-----------------------------------------------------------
 Add-on version: 1.0.0
 There is an update available for this add-on!
 Latest add-on version: null
 Please consider upgrading as soon as possible.
 System: Home Assistant OS 9.4  (aarch64 / raspberrypi4-64)
 Home Assistant version: 2022.12.6
 Supervisor version: 2022.11.2
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] monitor.sh: executing... 
[11:46:19] INFO: Updating running configuration...
[cont-init.d] monitor.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[11:46:19] INFO: Starting required services...
Starting system message bus: dbus.
Starting bluetooth: bluetoothd.
[11:46:19] INFO: Updating Bluetooth Presence Monitor to latest version...
From https://github.com/andrewjfreyer/monitor
 + 87d433b...10b6cb7 master     -> origin/master  (forced update)
Previous HEAD position was 87d433b Merge pull request #289 from hmmbob/patch-1
HEAD is now at 10b6cb7 update intallation instructions
Already up to date.
[11:46:21] INFO: Starting Bluetooth Presence Monitor...
> updated monitor (v. Unknown) -> (v. 0.2.200)...
> using custom config directory [/opt/monitor]
using /opt/monitor as config dir
> A8:9C:ED:C5:32:89 confidence topic: presence/homeassistant/mi_9 (has not previously connected to hci0)
> A8:9C:ED:C5:32:89 device_tracker topic: presence/homeassistant/mi_9/device_tracker [not_home or home]
> AC:92:32:E7:7A:41 confidence topic: presence/homeassistant/wonphone (has not previously connected to hci0)
> AC:92:32:E7:7A:41 device_tracker topic: presence/homeassistant/wonphone/device_tracker [not_home or home]
> FC:F2:01:07:15:AC confidence topic: presence/homeassistant/fc_f2_01_07_15_ac (has not previously connected to hci0)
> FC:F2:01:07:15:AC device_tracker topic: presence/homeassistant/fc_f2_01_07_15_ac/device_tracker [not_home or home]
/usr/local/bin/monitor: line 1987: [: : integer expression expected
[-] 0.2.200 17-12-2022 11:46:30 AM [CMD-NAME]	A8:9C:ED:C5:32:89 MI 9  Xiaomi Communications Co Ltd
[-] 0.2.200 17-12-2022 11:46:30 AM [CMD-MQTT]	presence/homeassistant/mi_9 { ... confidence : 100 ... } 
[-] 0.2.200 17-12-2022 11:46:39 AM [CMD-MQTT]	presence/homeassistant/wonphone { ... confidence : 0 ... } 
[-] 0.2.200 17-12-2022 11:46:40 AM [CMD-NAME]	AC:92:32:E7:7A:41 wonphone  HUAWEI TECHNOLOGIES COLTD

I feel like I am missing big part of setup in config or something.
This is exactly why I was frustrated to begin with. :frowning:

Now you need to create some MQTT device trackers such as:

mqtt:
  device_tracker:
    - name: "person2 bt front mobile"
      state_topic: 'monitor/first floor front/person2_mobile/device_tracker'
      source_type: bluetooth
1 Like

I cant make this addon to work, can someone help me troubleshooting it?

mqtt:
  broker: 127.0.0.1
  port: 1883
  username: "!secret mqtt_username"
  password: "!secret mqtt_password"
  topic_root: presence
  publisher: ""
known:
  beacons: []
  static:
    - XX:XX:XX:XX:XX:XX 
blacklist: []
extra_arguments: "-E"
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] 00-banner.sh: executing... 
-----------------------------------------------------------
 Hass.io Add-on: Bluetooth Presence Monitor
 Passive Bluetooth presence detection of beacons, cell phones, and other Bluetooth devices.
-----------------------------------------------------------
 Add-on version: 1.0.0
 There is an update available for this add-on!
 Latest add-on version: null
 Please consider upgrading as soon as possible.
 System: Home Assistant OS 10.3  (amd64 / generic-x86-64)
 Home Assistant version: 2023.6.1
 Supervisor version: 2023.07.1
-----------------------------------------------------------
 Please, share the above information when looking for help
 or support in, e.g., GitHub, forums or the Discord chat.
-----------------------------------------------------------
[cont-init.d] 00-banner.sh: exited 0.
[cont-init.d] 01-log-level.sh: executing... 
[cont-init.d] 01-log-level.sh: exited 0.
[cont-init.d] monitor.sh: executing... 
[19:17:44] INFO: Updating running configuration...
[cont-init.d] monitor.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[services.d] done.
[19:17:44] INFO: Starting required services...
Starting system message bus: dbus.
Starting bluetooth: bluetoothd.
[19:17:44] INFO: Updating Bluetooth Presence Monitor to latest version...
From https://github.com/andrewjfreyer/monitor
 + 87d433b...10b6cb7 master     -> origin/master  (forced update)
Previous HEAD position was 87d433b Merge pull request #289 from hmmbob/patch-1
HEAD is now at 10b6cb7 update intallation instructions
Already up to date.
[19:17:49] INFO: Starting Bluetooth Presence Monitor...
> updated monitor (v. Unknown) -> (v. 0.2.200)...
> using custom config directory [/opt/monitor]
> publishing MQTT .../scan/[arrival|depart]/[start|end]
using /opt/monitor as config dir

Is it possible to see what is happening under the hood?

Any luck with this or is there an install guideline/readme anywhere? Been trying to find a good option for room presence. Seems room assistant isn’t being updated anymore. Was hoping to get BluetoothClassic, Bluetoothle working to detect my iPhone.

are you trying to track presence in the rooms or track individuals in specific rooms?

I’m biased (being the author), but Bermuda might be what you’re looking for - the prerequisite is that you have one or more bluetooth proxies (so esp32 devices running esphome, or some shelly’s).

It will give you device_tracker entities for tracking home/not_home status, as well as Area and Distance sensors for each device to tell you which BLE proxy it’s closest to.

You’ll still need a beacon app on your phone so it gives you a stable MAC address to track, at least until I integrate with the new private_ble integration in core (for iPhones) and natively support iBeacon UUIDs for android, but it works with normal static BLE devices reasonably well.

2 Likes

Hello - can Bermuda be used to automate things e.g. open the garage door when arriving home? Is BT range/update frequency enough?

Take a look at this trash can tracking example. Instead of attaching a beacon to a trash can, you could use the HA app to generate a virtual beacon on your phone.

You won’t be able to filter by MAC on the BLE gateway scanner since your phone’s MAC will frequently be changing but it should still work.