BTHome BLE for your MicroPython projects

If you like to geek out with microcontrollers, Bluetooth Low Energy, and MicroPython, this may be of interest to you.

BTHome-MicroPython

I was looking for a way to build some DIY sensors with microcontrollers running MicroPython and communicate readings to Home Assistant via Bluetooth. The BTHome integration is perfect for this, but the only examples I could find were written in C++. So I wrote my own MicroPython module that creates the BLE advertisement in BTHome format. This advertising payload can then be used with MicroPython’s aioble (async Bluetooth Low Energy) library to create a BTHome compliant sensor beacon.

The project’s main.py shows how to communicate the mocked-up values used in the BTHome format example. Home Assistant will then show a BTHome sensor named DIY-sensor with a temperature of 25C (77F) and humidity of 50.55%, the same as the example payload used by the BTHome.io format example. The microcontroller then goes to sleep for a little while and wakes up to do it all again.

The example only shows temperature and humidity, but nearly all of the BTHome object IDs are implemented, so you should be able to communicate just about anything you want.

2 Likes

Great project! Maybe a silly question from my side: any idea on battery duration between wifi-based sensors (I’ve heard that typically wifi sensors on batteries don’t last too long) and your approach?

I haven’t tried much with battery power. Though putting the microcontroller in deep sleep should help with that.