There are 2 ways - at least that I know about - how you can communicate:
- Advertisements - connection-less, max 31 bytes of payload
- Client-server - requires connection, up to 512 bytes.
I tried both of them and working on a blog post with more details, but in I’ll try to cover them here briefly.
One thing I’d note - I’d agree with the above comment is that communicating data directly to HA is somewhat cumbersome. It’s much more convenient to use another ESP32 that will bridge BLE to HA.
In my case, I have 2 nodes: a transmitter, and receiver.
Transmitter is on wired power supply, connected to Wi-Fi, pulls data from HA, and exposes them over BLE.
The receiver powered by a battery, wakes up every interval, receives data to show on eInk display, and goes back to deep sleep.
I recently contributed a small change to ESPHome that allows you to embed payload into BLE advertisements. It’s available in the latest release so you can start using it right away. Since ti requires a bit of coding, maintainers didn’t want to include the guide into the docs, but the guide itself is still on GIthub esphome-docs/esp32_ble.rst at 42fe5663127f9233d157eb300d9d30af030e71e8 · ashald/esphome-docs · GitHub - it’s a full example of transmitting data over BLE advertisements, and consuming them. In theory, you should be able to receive the advertisements with HA, but IDK what it’d take to make existing BLE integrations to process custom data [so I’d suggest just using 2x EP32].
If you want to use the client-server mode that can handle more data, there is an excellent ESP32 custom component wifwucite/esphome-ble-controller which can expose any sensor value as a BLE characteristic. To consume them via ESP32, you can use the built-in ble_client sensor, or text_sensor that O contributed as well (I think it’s already available in the latest release, but docs haven’t been updated yet so you can see them here esphome-docs/ble_client.rst at efbd53774d5a64f114cbd1a5989e6b8453ed2bfa · ashald/esphome-docs · GitHub). Alternatively, you can use myhomeiot/esphome-components which provides a slightly more convenient client in my opinion, which I used in my prototype.
Again, there should be an integration for HA that could connect to a BLE server, but I’m not aware of any, and IDK what it’d take to make it work with custom services and characteristics.
Hope this helps, and let me know if you’d have any questions.