ESPHOME

BLE bluetooth tracker

text_sensor:
- platform: template
name: "BLE ibeacon"
id: template_text
esp32_ble_tracker:
on_ble_advertise:
- then:
- lambda: |-
for (auto data : x.get_manufacturer_datas()) {
auto message = hexencode(data.data);
ESP_LOGD("ble_adv", "manufacturer_data: %s [%d]", message.c_str(), message.size());
if (message.size() >= 73) {
/* ibeacon = e2c56db5-dffb-48d2-b060-d0f5a71096e0 */
auto ibeacon = message.substr(6, 2) + message.substr(9, 2) + message.substr(12, 2) + message.substr(15, 2) +
'-' + message.substr(18, 2) + message.substr(21, 2) +
'-' + message.substr(24, 2) + message.substr(27, 2) +
'-' + message.substr(30, 2) + message.substr(33, 2) +
'-' + message.substr(36, 2) + message.substr(39, 2) + message.substr(42, 2) + message.substr(45, 2) + message.substr(48, 1);
id(template_text).publish_state(ibeacon.c_str());
}
}

BLE bluetooth tracker (deprecated)

parameters to change:

uuid: “02.15.E2.C5.6D.B5.DF.FB.48.D2.B0.60.D0.F5.A7.10.96.E0.00.01.00.02.C8 (23)”

name: “scipio cell”

binary_sensor:
- platform: template
device_class: presence
name: "scipio cell"
id: beacon1
script:
- id: ble_off_script
mode: restart
then:
- binary_sensor.template.publish:
id: beacon1
state: true
- delay: 60s
- binary_sensor.template.publish:
id: beacon1
state: false
esp32_ble_tracker:
on_ble_advertise:
- then:
- lambda: |-
for (auto data : x.get_manufacturer_datas()) {
if (strcmp(hexencode(data.data).c_str(), "02.15.E2.C5.6D.B5.DF.FB.48.D2.B0.60.D0.F5.A7.10.96.E0.00.01.00.02.C8 (23)") == 0) {
ESP_LOGD("ble_adv", "beacon1 found");
id(ble_off_script).execute();
}
else
{
ESP_LOGD("ble_adv", " - %s", hexencode(data.data).c_str());
}
}