Tuesday, 15 April 2025

Zigbeeifying Xiaomi LYWSD03MMC temperature sensors

I asked for recommendations for good Zigbee temperature sensors, and lots of people recommended the Xiaomi LYWSD03MMC (which is Bluetooth rather than Zigbee, but can be flashed with custom Zigbee firmware).  I ordered a couple from AliExpress (https://www.aliexpress.com/item/4001209595851.html), which appear to have been dispatched from a UK warehouse and arrived very quickly.

I had some problems installing the new firmware, so this post is documenting the process.

These sensors came with a fairly new firmware, which unfortunately complicates the over-the-air firmware update process.  They must first be associated with the Xiaomi app and then the keys extracted.

  1. Install the Xiaomi Android app, create an account and pair the sensors over Bluetooth.
  2. Download the Xiaomi token extractor Python script (https://github.com/PiotrMachowski/Xiaomi-cloud-tokens-extractor) and execute it.  This will output some info for each device.  I had a lot of trouble with this because it kept telling me I needed to do 2-factor authentication, but that never worked.  Eventually after a lot of Googling, I tried setting a name for my home and a nickname for my user, and the 2-factor auth problems went away.  I'm not sure specifically what fixed the problem.  Beware: I came across a blog post suggesting that you can extract the "ssecurity" and "serviceToken" values from your HTTPS traffic and bodge them into the Python script - doing this appeared to make the login succeed, but the app would always tell me "No homes found for server" for each of the servers that it tried.  In the end I didn't need to bodge those values into the Python script.
  3. Go to https://pvvx.github.io/ATC_MiThermometer/TelinkMiFlasher.html - I did this in Chrome from my phone because my workstation has a very old Bluetooth adaptor which didn't want to talk to the temperature sensors.
  4. Click "Connect".
  5. Wait while it finds devices to pair with, select the appropriate temperature sensor and click "Pair".
  6. Once connected, copy and paste some of the values from the token extractor:
    ID -> Device known id
    TOKEN -> Mi Token
    BLE KEY -> Mi Bind Key
    (I found running KDE Connect very useful since it allowed me to copy into the clipboard on my workstation and then paste them on my phone).
  7. Click "Login" and the status bar on the page should show "Login successful".
  8. Press the "Original_OTA_Xiaomi...." button.  Flashing the original firmware is apparently the recommended thing to do before any custom firmwares, to make sure you're starting from a known firmware version.
  9. Press "Start flashing" and wait.  The status bar will show the status of the update - it will take a couple of minutes.
  10. Once flashing is complete, press "Reconnect" and wait until it has reconnected.
  11. Copy and paste the same values from the token extractor again.
  12. Click "Login" again.
  13. This time, select "Custom Firmware: ATC_...".
  14. Press "Start flashing" and wait again.
  15. Once flashing is complete, press "Reconnect" and wait until it has reconnected.
  16. This time, we don't need the info from the token extractor.  Select the Zigbee firmware and click "Start flashing".  The device will show dashed lines on the screen while you wait for the update to complete.
  17. When complete, the device will briefly display "oo o" and then go back to showing temperature and humidity as normal.
  18. Put the Zigbee bridge (in my case, Zigbee2MQTT) into pairing mode and wait for it to pair.  I needed to bring the temperature sensor close to the coordinator - it wouldn't pair to the nearest smart plug for whatever reason.
I'm now going to spend a few days evaluating these sensors, and if they work well I'll get a bunch of them.

No comments:

Post a Comment