Making gateway: BLE device <--> HA - Recommended approach?

I have a pool chlorinator/pump controller that is a BLE peripheral which I’d like to integrate with Home Assistant.

I have reverse engineered the connection protocol to the peripheral - it uses GATT with some proprietary handshake and packet encryption. I’ve built a simple proof of concept in Arduino on the doit esp32 devkit that connects, fetches a charateristic and decrypts it, so I’m happy that I can make the protocol work.

I’d like to use esphome since I’m hoping that almost all of the necessary bits are already handed in esphome (HA integration, wifi, ble, OTA…)

I’m a c/c++ programmer from way back, so I’m reasonably good with that. Not so good with python and yaml. I’m completely new to esphome.

Here’s the functional components (I think) I need:

  • BLE client to handle the GATT
  • Custom state machine to handle the authentication/connection
  • AES128 library to help with the crypto
  • Probably a helper class to manage all the parsing and state.
  • Sensor platform to handle feeding all the state back to HA
  • Something to handle controlling writable attributes back to the machine (eg pump on/off/auto).

How do I architect my esphome component? What’s the right way of doing this?
After a little bit of experimentation, here are some of the questions I’ve got:

  • Do I use a custom sensor component, or even a generic custom component?
  • Do I multiple inherit the bits I need?
  • Or, do I make my own ‘external component’? Is this more scalable? The python looks intimidating.

Any guidance is vastly appreciated!

Probably best to ask on discord. There is a homeassistant bluetooth developers channel. An ESPHome component is not recommended if starting from scratch. I think best to make a home assistant component which will handle all the processing. That way you can use a normal BT adapter or a ESPHome proxy. Best of both worlds.

I have written (actually adapted from someone else’s airthings) component for a BT radon monitor and it was a learning process. https://github.com/jdeath/rd200v2 But that is just a sensor, I think you need more capability than that. You write a python script in using the bleak BLE library, then adapt it for homeassistant. The bleak version of my radon component is in the repo, so you can see the basics. Look for a BLE component in homeassistant which is close, for a starting point. Perhaps on discord they can give you more pointers.

1 Like