本帖最后由 likaci 于 2024-3-5 00:08 编辑
广播包里有单击双击长按的数据, 不过是加密的, 需要使用blekey解密. 解密后分别对应 4a0c 4a0d 4a0e, 我尝试在ha里直接支持 但是pr一直没有被合并.
github 上 dentra/esphome-components 也可以比较方便的用 text_sensor 实现
external_components:
- source: github://dentra/esphome-components
miot:
xiaomi_account:
username: [email protected]
password: xxx
servers: cn
update_interval: 4h
on_miot_advertise:
mac_address: "xx:C1:38:1A:xx:xx"
then:
lambda: |-
if (x.id == 0x4a0c) {
id(ptx).publish_state("single_click");
delay(1000);
id(ptx).publish_state("release");
} else if (x.id == 0x4a0d) {
id(ptx).publish_state("double_click");
delay(1000);
id(ptx).publish_state("release");
} else if (x.id == 0x4a0e) {
id(ptx).publish_state("long_press");
delay(1000);
id(ptx).publish_state("release");
} else {
ESP_LOGW("miot_event", "miid: 0x%04x, data: %s", x.id, format_hex_pretty(x.data.data(), x.data.size()).c_str());
}
text_sensor:
- platform: template
name: "PTX"
id: "ptx"
|