afarago / esphome_component_bthome

This package implements ESPHome components to low-code support Bluetooth Low Eneregy BTHome device standalone reception, and a leverage this protocol over ad-hoc routerless WiFi transmission over ESP-NOW channel.
MIT License
55 stars 11 forks source link

Encrypted BtHome? #10

Open nagyrobi opened 1 year ago

nagyrobi commented 1 year ago

I'd like to passively catch encrypted BtHome advertisments sent by Xiaomi sensors running pvvx firmware. I have the bindkey extracted for each.

Currently they are passed to HA via proxy, and HA decrypts them, but I'd like to use the measurements locally on ESPHome node, rather than import them back from HA through the API.

Additionally, averaging filters on ESPHome are much better than HA's filters, that's another reason to do all the maths in the node firmware. Not mentioning HA as a central single point of failure...

afarago commented 1 year ago

Hi, that is a great idea - do you feel like creating an initial PR for the parser? https://github.com/afarago/esphome_component_bthome/blob/master/components/bthome_base/bthome_parser.cpp As of today I have bthome_ble_receiver component that works with unencrypted bthome messages.

I have very little knowledge on the AES-CCM yet. Once we have a working solution I am happy to add the necessary augmentation to the esphome component.

nagyrobi commented 1 year ago

I lack the C++ knowledge unfortunately, but I assume some inspiration on the logic behind decryption could be taken from how HA BtHome component does it.

nagyrobi commented 1 year ago

Also see https://github.com/esphome/esphome/blob/41f29c46d024138ae8b3a1dd19d94f1c4ed96816/esphome/components/xiaomi_ble/xiaomi_ble.cpp#L234C19-L321C19

Maybe this would work almost out of the box, as BtHome in pvvx is using the same bindkey as the original firmware.