Bluetooth Low Energy Novice

Have begun my journey on BLE, but not sure I am doing it correctly. Have read heaps of posts on here and the esphome docs, but not sure what I am seeing is correct.

I purchased an iBeacon, and obtained the MAC address from the software that is supplied with the iBeacon.

Here’s the BLE code I have in my ESP32 unit…

# Bluetooth Tracker          
esp32_ble_tracker:

binary_sensor:
  - platform: ble_presence
# iBeacon
    mac_address: EF:51:6F:21:75:74
    name: "BLE Presence Test"

When the ESP32 starts, here’s what I see in the logs…

[15:47:59][C][ble_presence:011]: BLE Presence 'Presence Test'
[15:47:59][C][esp32_ble_tracker:793]: BLE Tracker:
[15:47:59][C][esp32_ble_tracker:794]:   Scan Duration: 300 s
[15:47:59][C][esp32_ble_tracker:795]:   Scan Interval: 320.0 ms
[15:47:59][C][esp32_ble_tracker:796]:   Scan Window: 30.0 ms
[15:47:59][C][esp32_ble_tracker:797]:   Scan Type: ACTIVE
[15:47:59][C][esp32_ble_tracker:798]:   Continuous Scanning: True

I see this in the logs… but no idea what it means?

[15:42:58][D][esp32_ble_tracker:809]: Found device F0:B3:EC:22:4E:69 RSSI=-92
[15:42:58][D][esp32_ble_tracker:830]:   Address Type: PUBLIC
[15:42:58][D][esp32_ble_tracker:834]:   TX Power: 2

I never see any reference to the iBeacon MAC address: EF:51:6F:21:75:74 so not sure what I’ve done wrong?

So what am I trying to achieve… put simply, I want to know when the iBeacon presence is detected, and then HA runs an automation. For example, the iBeacon could be placed inside a car, so when car is home and detected HA performs an automation.

Apology if these are random questions… appreciate any guidance.

Are you sure the MAC address is correct?
Did you follow this guide?

Yes, I followed the guide. Interestingly I beleive I have made some progress… of sorts. Here’s what is happening… which is strange.

You can see the presence flip flops, between away and detected. Yet the iBeacon hasn’t moved?

No idea why that would be happening, unless there is something wrong with the iBeacon?

My BLE Presence journey continues. Purchased another iBeacon, but not having much more luck unfortuinately.

Here’s the code from my ESP32 device:-

# Presence based on MAC address and UUID
binary_sensor:
  - platform: ble_presence
    service_uuid: 'd546df97-4757-47ef-be09-3e2dcbdd0c77'
    name: "BLE Test 1"
    id: ble_presence_test1

And here’s the data from the iBeacon app…

And here’s what the entity looks like in HA:-
BLE_Entity_Test

So not sure what I am doing wrong? Seems no matter what I try I just cannot get Home Assistant to recognise the iBeacon device?

Yes, I have read all the documentation… many times :slight_smile:

Taking a few steps back to your older posts:

Did you solve the flip flop (in range, out of range) problem in the ESP yet?

Where did you get the numbers you entered for scan interval and window? Or were those automatically supplied by the ESP?

I think you could try adjusting the scan interval to 500ms and the window to 400ms. That will give the ESP a better chance to see the beacon. If that causes some issues, drop the window down to 300ms.

You can also change the ACTIVE scan to whatever the opposite value is…maybe passive? You don’t need active scanning for this type of usage case. Active scanning is for when you want to send scan requests to the beacon, which you would only do in very special usage cases.

There are also some other settings in the ESP that you can adjust, but I’m not at my computer now, so I will try to look them up later.

Moving on to the Feasy app screen, the first beacon looks fine, although the -75 calibrated RSSI seems low to me. But it depends on the beacon antenna, so if Feasy says it should be -75, then ok. But the second beacon’s calibrated RSSI of -3 is definitely wrong. I have no idea what type of beacon that is, but you might try adjusting it to something like -60 just to at least give it a chance to work properly with the ESPresence. (ESPresence uses this number in a math formula to estimate the distance from the beacon, so if this number is wacko, the distance calculation will also be wacko.)

Sorry for not addressing the HA part of the equation, but I’m still a noob at HA. I’m a beacon genius but HA fool! :laughing:

One other thing I just noticed:

I see one MAC …EE:7E, but two iBeacon UUIDs and one Eddystone URL broadcast on the same screen of the Feasy app. Have you activated multiple broadcast slots on the beacon?

If so, you should only activate one slot. For example, just use the first iBeacon slot only, then be sure you enter that UUID in the ESPresence. Also be sure the ESP scan screen can see that beacon (you can check the ESP logs) and its correct MAC.

OK, so here is the ESPresence config screen that someone else sent to me one time.

The “Factor used to account for…” thing is where you can make some adjustment to the distance calculation. You can look up in the ESPresence instructions how to adjust this number.

Basically, this is a constant that plugs into the formula used to calculate the distance from the beacon. The other main inputs into the formula are the actual live RSSI of the beacon and the measured (fixed) RSSI of the beacon.

The page also has an input for “RSSI expected from a 0dBm transmitter…” but as it also shows, you don’t need to enter anything here since you are using an iBeacon. iBeacons broadcast their fixed/calibrated RSSI as part of their regular broadcast, so you don’t need to specify this. Probably anything you enter here will be ignored if you are using an iBeacon.

Hey there…

Did you solve the flip flop (in range, out of range) problem in the ESP yet?

The iBeacon that was flip flopping appeared to have an issue, with the battery going flat really quickly. Either that or I hadn’t programmed it correctly. So I ended up purchasing the Feasy unit.

Where did you get the numbers you entered for scan interval and window? Or were those automatically supplied by the ESP?

Yes, they were the default numbers.

I think you could try adjusting the scan interval to 500ms and the window to 400ms. That will give the ESP a better chance to see the beacon. If that causes some issues, drop the window down to 300ms.

Thanks, will give that a go.

You can also change the ACTIVE scan to whatever the opposite value is…maybe passive? You don’t need active scanning for this type of usage case. Active scanning is for when you want to send scan requests to the beacon, which you would only do in very special usage cases.

So I assume when you say active scan, you mean that is configured in the ESPHome setup?

There are also some other settings in the ESP that you can adjust, but I’m not at my computer now, so I will try to look them up later.

Thanks, much appreciated.

Moving on to the Feasy app screen, the first beacon looks fine, although the -75 calibrated RSSI seems low to me. But it depends on the beacon antenna, so if Feasy says it should be -75, then ok. But the second beacon’s calibrated RSSI of -3 is definitely wrong. I have no idea what type of beacon that is, but you might try adjusting it to something like -60 just to at least give it a chance to work properly with the ESPresence. (ESPresence uses this number in a math formula to estimate the distance from the beacon, so if this number is wacko, the distance calculation will also be wacko.)

No problem, I will look at the Feasy app and see what can be adjusted and try a few combinations.

Sorry for not addressing the HA part of the equation, but I’m still a noob at HA. I’m a beacon genius but HA fool! :laughing:

Really appreciate the feedback, and you taking time out of your day.

One other thing I just noticed:

I see one MAC …EE:7E, but two iBeacon UUIDs and one Eddystone URL broadcast on the same screen of the Feasy app. Have you activated multiple broadcast slots on the beacon?

In the Feasy app there is an option to turn off the various beacons… see the screen below, I have disabled all but the top beacon.

If so, you should only activate one slot. For example, just use the first iBeacon slot only, then be sure you enter that UUID in the ESPresence. Also be sure the ESP scan screen can see that beacon (you can check the ESP logs) and its correct MAC.

I have used the UUID from the first beacon in the ESPPresence config.

I have never seen this screen previously? Where is this found? Is this in HA or ESPHome?

Re my config screenshot: Oops, my bad. I thought you were using ESPresence since I kept seeing the word “presence” on your screens. Now I realized you are using ESPHome instead. So please ignore that config screen shot above. (FYI, this is what I was referring to: ESPresense | ESP32 based indoor positioning system)

Re ACTIVE scan type: I was referring to the screenshot you posted earlier showing your ESP log or maybe settings. One of them was “Scan Type: ACTIVE”. My suggestion was to turn this off, but I’m not sure of the terminology that ESP Home uses. It’s not super important. It will save a bit of resources and the beacon battery maybe. But you can just leave it as is for now. It’s not causing your issue.

Re the Feasy app screen:
-You can turn off TLM. You don’t need it for your usage case, and it just uses extra battery power. (Feasy might be using the TLM to broadcast the beacon’s battery %. If so, you might want to leave it on for that purpose.)
-Your single iBeacon broadcast looks perfect except you left the calibrated rssi at -3. That won’t work at all. Change it to -60; that might not be exactly right for your specific Feasy beacon, but it’s definitely more usable/accurate than -3. If for some strange reason Feasy won’t let can’t change it, then disable that iBeacon broadcast and use the other one (the one with -75 calibrated rssi) instead. Notice though that the uuid is different for this other iBeacon broadcast. Be sure to change that in ESP Home settings.
-Be sure to copy the uuid into ESP Home instead of trying to type it. Don’t confuse a zero with the letter O. There are no letter O’s in uuids. Anything that looks like an O is a zero.
-I wonder what “key” means? It shows “key(ms)” then 100 and 35000. I have no idea what that could be.
-Your interval is set to 260ms. This should work great for your usage case, but it will wear out the battery really fast. 500ms should work fine. Even 1000ms should be ok unless you want super fast reaction times for your automation.

A different approach: Coincidentally, I received an email from an HA user yesterday telling me how happy she is with her beacon automation. She tried and failed to setup ESPresence, so switched to a different sketch for the ESP. Here’s a snippet of her email: “ A wonderful person named Andrii created a custom integration called Format BLE Tracker and put it on Github (GitHub - formatBCE/Format-BLE-Tracker: BLE tracker integration, which works with ESP32 firmware https://github.com/formatBCE/ESP32_BLE_presense). I don’t know why more people don’t use it; it works perfectly, and it was so easy to set up.” Now I’m trying to convince her to put a beacon on her cat’s collar like I have on all four of my cats!

UPDATE: Some progress… so I thought I’d share.

The code I found has worked is…

# Bluetooth Tracker        
esp32_ble_tracker:
  scan_parameters:
    interval: 1100ms
    window: 1100ms
    active: true

# Bluetooth Proxy
bluetooth_proxy:
  active: true

With the code above… this auto-magically popped up in my HA instance.
iBeaconTracker

Only thing is… there are no other parameters associated with this integration/device?
iBeaconTrackerOptions

I also obtained a XIAOMI Mijia Bluetooth Thermometer 2 and added the integration… HA found the device via my BLE proxy but there’s not much data showing?

So my journey continues… Biggest learning so far… I’ve made much more progress running the ESP32 as a Bluetooth proxy than all the other configs I’ve tried i.e. trying to have the ESP32 tracking BLE locally didn’t get the outcomes I wanted.