ESPHome component for ESPresense-like room tracking

A very basic way to configure would be to compare all nodes values and the one that has the lowest distance would be considered the room you are in.

You create a template sensor called phone location and something lik;

{% if distance node 1 is lowest %}
Room1
{% elseif distance node 2 is lowest %}
Room2

And so on.
1 Like

I’m trying to use this with an iPhone running Room Assistant to provide a beacon, but I’m always getting ‘nan’ as a distance. I’m using an m5stamp, which has a risc-v processor if it makes any difference, and have tried both the arduino and esp-idf frameworks. I’m not seeing any “iBeacon data” messages from esp32_ble_tracker when I have very-verbose logging as I’ve seen others have had.

Can anybody offer advice?

Either your phone isn’t advertising or you’re using the wrong UUID. Use a BLE scanner app on another phone and see if it comes up.

I assumed the UUID I need is the Device ID in the room-assistant app on the phone. Clearly I don’t know what I’m doing, and at least one other person is having difficulty too, so at least I’m not alone. I think the problem is more with the use of room-assistant. Regardless, here’s what I’ve tried so far.

I modified ‘ble_dist.h’ to log when it finds a beacon. It’s very regularly reporting just one - it has what I understand to be an Apple manufacturer id (0x004c). If I turn off bluetooth on my phone and iPad (which both have room-assistant running) and Apple watch, and take the batteries out of my two Air Tags, it continues finding that same device, but no other (could it be an Apple TV or one of the laptops?).

If I install nRF Connect on the iPhone and iPad, they can both see each other (when bluetooth is on obv). Sometimes the name shows up as ‘room-assistant-companion’, but other times it’s the device name (eg. iPad mini). However, the app doesn’t appear to show the UUID. Even if it did, the code is not finding any other beacons. I installed Locate Beacon on both the iPad and iPhone, but if I enter the relevant Device ID, they don’t show up.

UPDATE: I decided to go back to basics and try room-assistant running on a server. It successfully sees both the iPhone and iPad companion apps. So therefore I assume the ESPHome code does not work with the beacon provided by the room-assistant companion app. It would be nice to know how nRF Connect (and hcitool etc) can get the iPhone’s name when esp32_ble_tracker cannot. If I knew how to get the device name, I could just use that for tracking.

Ok, so the room-assistant companion app works by using a particular characteristic (defined here), where it stores the Device Id. It is not the UUID of the beacon. Therefore, this code will not work with the room-assistant companion app.

The Locate Beacon app sends an iBeacon that this code can pick up, but it does not run in the background on the iPhone.

ESPHome should be able to handle non iBeacon BLE devices, but this distance tracking code won’t. It should be pretty easy to adapt, from what I remember. These pages should get you started, if you want to try:

2 Likes

Also, the home assistant app can do background iBeacons, at least on Android. probably iPhones too. Nevermind, it seems Apple has some limitations that prevent that, which is why room assistant is doing it that way.

Do you possibly have an example yaml of adding a 2nd device? I did another addtracker line but it doesn’t seem to be working. So far it works great with just the one device! Thanks!!!

was a typo in ibeacon uuid. Working great now! Thanks again!!!

1 Like

Hi,

I created a feature request outlining a way to solve this problem, if you’re like to look at Apple Devices Presence using ESPHome BLE Proxy (ESPresense alternative)

Thanks

Dan

2 Likes

Thanks for this project! I managed to successfully flash it on an olimex board and had it debug all BLE UUIDs as a test.

There are however a lot of them :slight_smile: Do you know an easy way to find the UUD for an iOS device (iPhone)?

unfortunately this little bit of code doesn’t support iOS. iOS has some security limitations that prevents identifying iBeacons by UUID. ESPresense has a workaround, but I didn’t port them because I don’t have any apple devices to test with. I’m open to a PR if you can hack it in though.

For MAC tracking and HA companion app tracking I made integration + ESPHome component. It does use MQTT, but not with discovery - for convenience, all beacons are created in integration, and have device_tracker, as well as current room sensor with raw data for all RSSI in arguments, and some settings for calibration.

GitHub - formatBCE/ESP32_BLE_presense: ESP32 firmware for Home Assistant Format BLE Tracker integration https://github.com/formatBCE/Format-BLE-Tracker. - ESPHome part
GitHub - formatBCE/Format-BLE-Tracker: BLE tracker integration, which works with ESP32 firmware https://github.com/formatBCE/ESP32_BLE_presense - HA integration

P.S.

  1. It doesn’t use ESPHome BLE stack, since that’s too laggy.
  2. Kalman filtering is used in integration to reduce RSSI noise.
  3. Usually changing room takes around 10-15 seconds. There’s room for improvement still.
1 Like

I notice this hasn’t been updated since last year. IN the example ESPhome YAML ‘add this section 2’ I take it we DONT add the custom_component section at the bottom given what is stated in the readme?

Looks good, but does it work in conjunction with the bt_proxy in active mode?
Thanks.

I doubt it’ll work with BT proxy. Scanning takes whole available radio time - it’s it’s main purpose.
All non-bluetooth tasks are working fine though (like GPIO sensors, UART etc.)

You want to add custom_component - it’s main config section.
Did readme confuse you?

P.S. it wasn’t updated because it works flawlessly for me.
However, I made some changes locally recently to HA integration, and testing them now. If it works better, will publish shortly.

Yes a little bit simply because of “Custom firmware (deprecated, use ESPHome instead)” sounds like we should not include that last section of ESPhome YAML:

custom_component:
- lambda: |-
    auto my_node = new BleNodeComponent("room_name"); # TODO replace rooom_name with your room name
    return {my_node};

…but I guess it’s that I was confusing “custom firmware” with “custom component”.

1 Like

Very nice project, added this to a few esp32 running esphome used as rgb fairy lights i have in a few rooms. I added my Android phone and my galaxy watch 4 and both were picked up just fine.

But my wife is using apple devices, do you plan to add apple presense detection? As i understand, this is quite tricky because of the way apple handles the uuid/MAC.

Thanks, I’m glad it works for you!

Regarding Apple - it’s harder to do because I don’t have any :slight_smile:

If you’re ready to test, I’d try to add support. :wink: