Announcing: Library to parse Xiaomi Mijia LYWSDCGQ Temperature/Humidity sensor BLE broadcasts

Discuss development of drivers for external hardware and components, such as LCD screens, sensors, motor drivers, etc.
Target audience: Users and developers of drivers.
Post Reply
User avatar
scy
Posts: 7
Joined: Sat Sep 05, 2020 12:50 am
Contact:

Announcing: Library to parse Xiaomi Mijia LYWSDCGQ Temperature/Humidity sensor BLE broadcasts

Post by scy » Mon Jan 03, 2022 12:34 pm

Hi everyone!

I own some Xiaomi Mijia BLE temperature/humidity sensors and recently noticed in the ESPHome docs that you don’t have to connect to them in order to retrieve the current readings, they’re being broadcast in the advertisement packets.

Since I’d like to access these sensors from a board running MicroPython (and not ESPHome), I’ve written a really small library (just one function, actually) to parse the data they broadcast. Just wanted to leave this here in case anyone else might need to do the same thing.

Find the library at https://codeberg.org/scy/micropython-xi ... -adv-parse. There’s also example MicroPython code demonstrating how to use it.

If you’re using other Xiaomi BLE sensors (temp/hum or e.g. their plant humidity ones), chances are they support something similar. Some of them might either require you to decrypt that data (which is non-trivial, as far as I can see, because you need AES-CCM, which seems to be unavailable in MicroPython right now) or flash an alternative firmware. See the ESPHome docs for a good overview. Those sensors are not supported by my library though, and I don’t think I want to maintain code for sensors I don’t use. See the “status & contributing” section of the readme if you’d like to extend my code or create a fork or something.

Post Reply