forked from dgrnbrg/appdaemon-configs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
irk_locator.yaml
81 lines (75 loc) · 2.38 KB
/
irk_locator.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
substitutions:
irk_prefilter_entity: sensor.irk_prefilter
irk_source: ${device_name}
esphome:
includes:
- irk_resolver.h
esp32:
framework:
sdkconfig_options:
CONFIG_MBEDTLS_HARDWARE_AES: y
bluetooth_proxy:
esp32_ble_tracker:
on_ble_advertise:
- then:
- if:
condition:
or:
- switch.is_on: skip_irk_prefilter
- lambda: |-
uint8_t addr[6];
for (int i = 0; i < irk_prefilters.size(); i++) {
auto& irk_vec = irk_prefilters[i];
uint8_t* irk = irk_vec.data();
auto addr64 = x.address_uint64();
addr[5] = (addr64 >> 40) & 0xff;
addr[4] = (addr64 >> 32) & 0xff;
addr[3] = (addr64 >> 24) & 0xff;
addr[2] = (addr64 >> 16) & 0xff;
addr[1] = (addr64 >> 8) & 0xff;
addr[0] = (addr64) & 0xff;
if (ble_ll_resolv_rpa((const uint8_t *)addr, irk)) {
ESP_LOGD("local_irk", "Resolved idx %d from ${irk_source}", i);
return true;
}
}
return false;
then:
- homeassistant.event:
event: esphome.ble_tracking_beacon
data:
source: ${irk_source}
rssi: !lambda |-
return x.get_rssi();
addr: !lambda |-
return x.address_str();
switch:
- platform: template
name: Skip IRK prefiltering
id: skip_irk_prefilter
restore_state: true
optimistic: true
entity_category: config
text_sensor:
- platform: homeassistant
internal: true
entity_id: ${irk_prefilter_entity}
id: irk_prefilter
on_value:
then:
- lambda: |-
uint8_t output[16];
size_t outlen;
size_t pos = 0;
std::string token;
irk_prefilters.clear();
while ((pos = x.find(":")) != std::string::npos) {
token = x.substr(0, pos);
mbedtls_base64_decode(output, 16, &outlen, (const uint8_t *)token.c_str(), token.length());
std::vector<uint8_t> ov;
for (int i = 0; i < 16; i++) {
ov.push_back(output[i]);
}
irk_prefilters.push_back(ov);
x.erase(0, pos + 1);
}