Implement ESPresense fuctionality in Home Assistant taking advantage of ble_proxy of ESPHome

Hi,

With the recent expansion of Bluetooth capabilities in Home Assistant, including the BLE Proxy functionality of ESPHome, as well as code available from other open-source projects, I think the pieces exist to have an Apple device presence sensor, which would also probably work for none-Apple devices.

Currently, I am using ESPresense to track Apple devices after finding out their IRK (Identity Resolving Key) - this is detailed at Apple | ESPresense.
This works well, however, the drawback is that I already use ESPHome BLE Proxies for a bunch of Xiaomi and other Temp and Plant sensors, so adding ESPresense essentially doubles the number of ESP32 devices I need to deploy.

When I look at the verbose logging from ESPHome, I can see that it is already forwarding all the relevant packets to Home Assistantā€¦

[10:06:55][V][bluetooth_proxy:033]: Proxying packet from  - AA:AA:AA:AA:AA:AA (Apple iPhone). RSSI: -69 dB
[10:06:56][V][bluetooth_proxy:033]: Proxying packet from  - AA:AA:AA:AA:AA:AA (Apple iPhone). RSSI: -69 dB
[10:06:57][V][bluetooth_proxy:033]: Proxying packet from  - AA:AA:AA:AA:AA:AA (Apple iPhone). RSSI: -70 dB
[10:06:57][V][bluetooth_proxy:033]: Proxying packet from  - BB:BB:BB:BB:BB:BB (Apple iPad). RSSI: -85 dB
[10:06:57][V][bluetooth_proxy:033]: Proxying packet from  - CC:CC:CC:CC:CC:CC (Apple Watch). RSSI: -75 dB
[10:06:57][V][bluetooth_proxy:033]: Proxying packet from  - AA:AA:AA:AA:AA:AA (Apple iPhone). RSSI: -69 dB
[10:06:58][V][bluetooth_proxy:033]: Proxying packet from  - AA:AA:AA:AA:AA:AA (Apple iPhone). RSSI: -69 dB
[10:06:59][V][bluetooth_proxy:033]: Proxying packet from  - CC:CC:CC:CC:CC:CC (Apple Watch). RSSI: -77 dB
[10:06:59][V][bluetooth_proxy:033]: Proxying packet from  - AA:AA:AA:AA:AA:AA (Apple iPhone). RSSI: -70 dB
[10:06:59][V][bluetooth_proxy:033]: Proxying packet from  - BB:BB:BB:BB:BB:BB (Apple iPad). RSSI: -86 dB
[10:07:00][V][bluetooth_proxy:033]: Proxying packet from  - CC:CC:CC:CC:CC:CC (Apple Watch). RSSI: -75 dB
[10:07:00][V][bluetooth_proxy:033]: Proxying packet from  - AA:AA:AA:AA:AA:AA (Apple iPhone). RSSI: -71 dB
[10:07:00][V][bluetooth_proxy:033]: Proxying packet from  - BB:BB:BB:BB:BB:BB (Apple iPad). RSSI: -84 dB
[10:07:01][V][bluetooth_proxy:033]: Proxying packet from  - BB:BB:BB:BB:BB:BB (Apple iPad). RSSI: -87 dB
[10:07:03][V][bluetooth_proxy:033]: Proxying packet from  - AA:AA:AA:AA:AA:AA (Apple iPhone). RSSI: -71 dB
[10:07:03][V][bluetooth_proxy:033]: Proxying packet from  - BB:BB:BB:BB:BB:BB (Apple iPad). RSSI: -81 dB
[10:07:03][V][bluetooth_proxy:033]: Proxying packet from  - CC:CC:CC:CC:CC:CC (Apple Watch). RSSI: -79 dB
[10:07:04][V][bluetooth_proxy:033]: Proxying packet from  - AA:AA:AA:AA:AA:AA (Apple iPhone). RSSI: -77 dB
[10:07:04][V][bluetooth_proxy:033]: Proxying packet from  - CC:CC:CC:CC:CC:CC (Apple Watch). RSSI: -78 dB

So the feature request is for a new HA component that would allow the adding of Apple devices after discovering the IRK, and then have their presence (and possibly even room / area location) tracked.

I think the reverse engineering work on the Apple protocols here GitHub - furiousMAC/continuity: Apple Continuity Protocol Reverse Engineering and Dissector may also be of relevance.

Thanks

Dan

I too have this challenge, using ESP32ā€™s in my smart home for both ESPresense AND other functions is a shame. It would be great to have this functionality included in ESPHome so that we can use the ESPā€™s we have to itā€™s fullest potential.
Please note that having the ā€œroomā€ function is very usefull in order to track devices to specific rooms. And when I say devices Iā€™m thinking of both Apple, Android or smart trackers (using bluetooth)ā€¦

2 Likes

I have cross-posted this feature request in ESPresense at Implement ESPresense fuctionality in Home Assistant taking advantage of ble_proxy of ESPHome Ā· Issue #795 Ā· ESPresense/ESPresense Ā· GitHub and changed the title as I think it has much broader applicability than just Apple devices

1 Like

I wonder if you could adapt this? GitHub - dalehumby/ESPHome-Apple-Watch-detection: ESPHome BLE Apple Watch presence detection

Any movement here?

This has been done in 2023.10:

Still need one ESPresence device to extract the IRK, but only once.

1 Like

Just learned about this from your post, and this seems to work very well with my iPhone + ESPHome on my ESP32s. Thank you for sharing!

Youā€˜re welcome.

One thing I noticed in my home though was that one has to be strategic about the placement of the ESP devices, when trying to do indoor tracking. Which BT-device is registered as the closest to my iPhone often changes in my home even when the device is not moved at all, and itā€˜s often not true.

I ended up with reporting the floor instead of the room (which is enough to find it ā€¦).

Would you guys mind sharing how you did this? I started with the Private BLE integration and have the IRKs from the iDevices I want to track- that integration works ok by itself but I need a proxy away from the server, so I got ESPHome running and an ESP32 board online, but I canā€™t figure out what to do now.

@fmon you can use the Bermuda custom integration which lets you track Private BLE (and other BLE devices) by Area, based on which esphome proxy is getting the strongest signal.

(disclaimer: Iā€™m the author, so somewhat biased).

2 Likes

Thanks, Iā€™ll check it out! Iā€™m currently using ESPresence but it requires flashing the boards after which theyā€™re useless for anything else.

1 Like

I really liked Bermuda, but had to switch to Espresence because of lack of ability to change the setting for the individual tracker (it is currently in Global options). Is that the limitation or just WIP?
Great work regardless. Cheers,

Per-scanner offsets are currently in v0.6.9rc2, which you can install if you enable ā€œshow beta versionsā€ in HACS.

The UI is a bit clumsy, but weā€™re pretty limited in what we can do in an options_flow.

In the configure menu, choose ā€œCalibration2: Scanner RSSI offsetsā€ and follow the instructions given in the dialog - let me know how you go!