Understanding BLE trackers

I have just started my journey into learning ESPHOME. My first project has been to create a BLE tracker as the native one in HA suddenly stopped working and I cannot find a solution.
Initially, I needed to track one specific BLE tag and this seems to be working fine, based upon its MAC. I now have a binary sensor which shows its presence - although I can’t seem to create it as a device_tracker entity? It can seemingly only be a binary_sensor, which is unhelpful, but not insurmountable.

Anyway, one other thing I’d like to implement is to track the BLE beacon on my watch as I move around the house. I’m aware that the MAC is randomised so I can’t track that. If I examine the logs,. though, I can see that the watch very clearly sends text with its name in every broadcast.

I cannot for the life of me see how I tell the tracker to look for that broadcast text, rather than a MAC or other data. I’m sure it must be possible, but I cannot find anything which explains how.

TIA

(edited for clarity)

I’m using manufacturer_id

on_ble_manufacturer_data_advertise:
    - manufacturer_id: '0969'
      then:

You could also look at something like the Bermuda integration in HACS which will create the tracker and assign an attribute telling you the area and estimated distance of the closest BLE proxy and it supports the private MAC integration for randomized MACs… (I deployed three myself yesterday and three more today and I’m finding things all over the house)

1 Like

Is that a custom repo or is it included in default HACS integrations?

I can’t seem to find it by searching “bermuda”.

Here you go

1 Like

What I see in the logs, though, is below and is nothing so succinct

[09:35:06][VV][esp32_ble_tracker:431]: Parse Result:
[09:35:06][VV][esp32_ble_tracker:448]:   Address: 6E:84:89:61:EE:8B (RANDOM)
[09:35:06][VV][esp32_ble_tracker:450]:   RSSI: -99
[09:35:06][VV][esp32_ble_tracker:451]:   Name: 'Galaxy Watch4 Classic (7QCT)'
[09:35:06][VV][esp32_ble_tracker:456]:   Appearance: 192
[09:35:06][VV][esp32_ble_tracker:459]:   Ad Flag: 2
[09:35:06][VV][esp32_ble_tracker:465]:   Manufacturer data: 01.00.02.00.01.03.FF.00.00.43.00 (11)
[09:35:06][VV][esp32_ble_tracker:481]: Adv data: 02.01.02.0E.FF.75.00.01.00.02.00.01.03.FF.00.00.43.00.03.19.C0.00.1D.09.47.61.6C.61.78.79.20.57.61.74.63.68.34.20.43.6C.61.73.73.69.63.20.28.37.51.43.54.29 (52)

I can see the data there, of course, but I don’t understand how to extract it.

What you see? What you expect to receive?

All data is in HEX, it can be converted to dec or ascii.
for example: 47.61.6C.61.78.79.20.57.61.74.63.68 in the middle of your Adv data is “Galaxy Watch” in ascii.

Have a look how BLE packets are formed:

I’ll have a read, thanks. This is my first foray into ESPHOME and I’m very green. I just need to learn how to look for a certain string within that Adv data, I imagine.

Thank you,

What you expect to have in that string?

Sorry, what I mean is that I don’t fully understand what the name of the string is that I’m looking for and how I can search for a sub-string within it.
I realise that this probably sounds dense, but this is my first attempt at anything like this.

Don’t worry. I just don’t understand what you are looking for. An example?

Yes, that’s it. I need to understand what code I enter to search the relevant data stream and then how I tell that code what to actually search for (as in: I assume that I don’t need to include the wrong string in the search, but a unique part of it).

You need to know where that relevant data is. And what form of data.
Bytes can represent one ascii letter, or dec number or 8 individual bits. Sometimes those bytes are separated to represent two individual numbers.
There’s no generic way of reading whatever message.

Have a look how I extract temp and humidity data from specific known bytes.
Humidity is extracted from eleventh byte, temp integral from tenth byte and decimals from ninth byte. There’s some bitmasking also.
No way you can find those data if you don’t know what/where to look for.

on_ble_manufacturer_data_advertise:
    - manufacturer_id: '0969'
      then:
        - lambda: |-
            float humidity = x[10] & 0x7F;
            float temp = (x[8] & 0x0F) * 0.1 + (x[9] & 0x7F);
            if ((x[9] & 0x80) == 0){
              temp = -temp;
              }

I gotta give you props for your level of understanding this. Everytime I try to learn this, I quickly realize that smashing my fingernails with a hammer is more preferable… I do appreciate all of you folks that do understand it and can help out thogh.

I’m not a bit manipulator either. Having hard time when I need to break and join bytes!
To dig that temp sign +/- from single bit in tenth byte made me loose my hair.

I like learning a lot of stuff but not that and I cant even force myself, its unbearable lol.

I didnt catch the reason why OP doesnt just use something like Bermuda or Espresence? Pulling in BT beacon temp data cant be that big of a deal.

1 Like

Two reasons, really:

  1. This was partly a learning exercise for ESPHOME
  2. I didn’t know about Bermuda until this thread - and have now installed it.

Annoyingly, I’ve had BLE tracking working absolutely fine natively in HA for months and then it suddenly stopped working completely. I think it was a HAOS update which broke things. So, I thought that this would be a good way to jump into ESPHOME.

Ok, that mostly makes sense, I think.

Except… where did you get the manufacturer_id from? What would be the equivalent in my case?

Right but, only tracking in HA is really no different than using presence based on devices connecting to wifi and showing Home/Away or from gps data showing the dame thing. At least for me, presence detection is more than home/away. Its home, which room everyone and their devices are in, their location in that room if something is lost and needs found and its pet tracking to notify me if my dog gets out of the fence. Im not sure if thats your end goal but, to man6 people presence is simply home/away and IMO that isnt extremely useful information.

It’s part of the broadcast, 2 bytes but in reverse order. Yours is 0075, if I remember correctly location.

[09:35:06][VV][esp32_ble_tracker:481]: Adv data:02.01.02.0E.FF.75.00.01.00.02.00.01.03.`

Anyway, try Nordic nRF Connect app. It’s helping to understand packets and devices you have nearby.