Xiaomi Mijia thermometer & hygrometer in Home Assistant (LYWSD03MMC) on Hass.io

Connecting a thermometer & hygrometer (humiditymeter?) to Home Assistant can be a bit of a hassle. Who doesn’t want one in every room? There are lots of ways to get them set up, but it’s easy to make things nicely-complicated & expensive. Who doesn’t love spending more money than you need? 

I picked up a pack of Xiaomi Mijia sensors (or LYWSD03MMC, when you get to know them), they run on a coin-cell battery for about a year, have BTLE / Bluetooth Low Energy transmission of their status, and are pretty cheap. I got mine on Aliexpress, they’re probably everywhere. 

Getting them to work on Home Assistant is painful, thanks to its (Home Asssistant’s) terrible logging and buggy features. Here’s how I got mine working, to save you some time.

A. Remove bind key and install custom firmware

The “bind key” is a form of security, I guess, to prevent people from using other apps to access the data. It seems like a stupid thing to add to a device like this, but whatever. There are a few ways to work around the bind key, to extract it, or to get rid of it. 

The ESPHome site has some tips; the easiest way seems to be to just install a custom firmware and be done with it. You can do this on a phone, it’s pretty easy. Steps:

  1. Download the firmware from here. Click download, save to your device.

  2. Open the “Telink Flasher” webpage. It’s just a web page. Works fine in Chrome. Looks technical, but don’t let it bother you.

  3. Make sure your sensor is turned on (battery plastic is removed). Easy.

  4. Click “Connect” (top left) on the web page. It’ll show a list of bluetooth devices nearby. Find the Mijia thermometer. It’s called “LYWS… (jumble of characters)”. Connect with it.

  5. Scroll to the bottom of the web page, to see a confirmation that it was able to connect.

  6. Scroll back to the top of the web page (easy, huh). Click “Do Activation”. This will read out the bind key and display it on the page. If you just want the bind key, then that’s all you need! Let’s get rid of it so that we don’t need it anymore though. 

  7. Click “Select Firmware / choose file” and select the downloaded firmware “.bin” file from step 1. 

  8. Click “Start flashing” to save it on the thermometer. It’ll take a bit less than a minute or so. You should see progress messages on the page. If you don’t see anything there, maybe the connection got dropped, and go back to step 4 (connect / do activation) and try again. Be patient first though.

  9. Done! Well, almost. You flashed it! It’ll restart briefly.

  10. Click “Connect” again on top of the web page, and write down the name shown there (“ATC_[numbers/letters]") – this is the name of your device now. If you have multiple of these, that’s how you’ll recognize which one is which. I taped the name to the device on the back (don’t cover the little hole on the back though).

  11. Adjust the settings of the custom firmware. I selected “Advertising type: Mi like” (to make it easier to find for other apps), and “Show battery in LCD: disabled” (to reduce confusion & keep a simple UI). 

  12. Done with flashing. Time to connect.

B. Connect to Home Assistant with HACS

Yeah, there’s theoretically an existing integration that would work for this, but for whatever reason it doesn’t. The logs are useless:

*WARNING (MainThread) [homeassistant.components.sensor] Updating
mitemp_bt sensor took longer than the scheduled update interval
0:00:30 *

*WARNING (SyncWorker_x) [homeassistant.components.sensor.mitemp_bt]
Polling error*

*WARNING (MainThread) [homeassistant.helpers.entity] Update of
sensor.x_temperature is taking over 10 seconds*

No, rebooting won’t help. No, moving the devices closer isn’t necessary. No, bluetooth doesn’t need extra drivers on the Raspberry Pi 3/4 with Hass.io. Maybe this will work at some point, but it doesn’t as of 2020-12-30. Some suggest setting up a MQTT gateway with another Raspberry Pi running custom Python scripts (sure! complexity!), some suggest using ESPHome as a gateway (yay, more devices). You can also jut make it work with HACS and the BLE_monitor integration.

  1. Install HACS if you don’t have it already. It seems kinda-shady, but it works. HACS is useful for various custom integrations that aren’t included in the general configuration. Installing it is a bit of a hack (HAC? sorry). 

    a. Enable the Terminal integration

    b. Go to the Terminal page in Home Assistant

    c. Copy & paste the command line from here

    curl -sfSL https://hacs.xyz/install | bash -

    d. Restart everything

C. Set up the BLE_Monitor integration

The BLE_Monitor integration monitors the Bluetooth LE connections that are sent out by devices. There’s no need to poll them. It’ll detect the devices automatically and then you’re done (apart from changing names, etc). Easy peasy (there’s also a FAQ with information). 

Go to the HAC-S tab in your Home Assistant, click on Integrations, click on the “+ Explore & add” button bottom/right, search for “BLE” and install “Passive BLE monitor integration (Xiaomi Mijia BLE MiBeacon monitor)”. Restart Home Assistant.

Now, go to “Configuration” & “Integrations” in the Home Assistant, and add the “Passive BLE Monitor” integration there. In the options, you don’t need to select anything. Easy, right.

Click on “devices” or “entities” in the “Passive BLE Monitor” card, and wait until your devices from “Step A” show up. You’re essentially done at this stage, no need to do anything more. 

The devices will show up with the full “MAC” address, which is a jumble of hex characters (0-9, A-F), where the last 6 will be the ID that you wrote down on the devices in “Step A” above. This is how you can differentiate the devices, rename them in Home Assistant if you want, or assign them to various locations. 

Want to add more devices? Just flash the firmware (Step A, write down their IDs), and assign them in Home Assistant when they automatically show up. It’s super-easy. Buy more here - or wherever you get these things. 

Comments / questions

There's currently no commenting functionality here. If you'd like to comment, please use Twitter and @me there. Thanks!

Tweet about this - and/or - search for latest comments / top comments

Related pages