Home Asssistant Xiaomi Mijia LYWSD03MMC Temperature and Humidity Sensor Tutorial September 2022

This guide describes how I got the Xiaomi Mijia LYWSD03MMC Temperature and Humidity sensors working in September 2022. This is likely to change soon as Bluetooth functionality is being built into Home Assistant Core, but for now it’s probably fairly accurate. Note that I am not an expert in this area, I read a lot and spent a lot of time on this.

I’m using the XDO BT-802 Bluetooth receiver. There’s an XDO BT-802 Bluetooth Linux tutorial on its use that I wrote here. It took quite a bit of time to get going in Linux, but once I did it’s been good with great range - though I’ve only been using it for a few days.

The PVVX Custom Firmware documentation is where I got a lot of this information. My aim is to make it easier to understand for beginners like myself.

Chrome Configuration
This comes directly from the PVVX page.

If using Android, Windows, Linux: Ensure you enabled “experimental web platform features”. Therefore copy the according link (i.e. chrome://flags/#enable-experimental-web-platform-features for Chrome), open a new browser tab, paste the copied URL. Now set the Experimental Web Platform features flag to Enabled. Then restart the browser.

Flash With PVVX Firmware
The Xiaomi sensors use encryption. The custom firmware removes the encryption and makes things a bit more configurable. This step can be worked around, but for that find another guide.

Open the TelinkMiFlasher website on a computer or phone that has Bluetooth available. I found my Android Pixel phone worked well, though my desktop computer also worked well once I attached the WiFi / Bluetooth combined antenna. If you have problems try turning off all other Bluetooth devices such as phones and mice, and move to an area that doesn’t have active Bluetooth transmitters.

  1. Tick the “Get Advertising MAC” box. Hit the Connect button. A dialog will pop up, wait until your Bluetooth device appears, choose it and hit Pair. This can take quite a while, be patient. You may have to move the Bluetooth devices around, reconnect a bunch of times, etc.

Bluetooth Pairing

  1. Hit “Do Activation” and wait until the three fields below are filled out. If they don’t fill out you may need to disconnect / reconnect / connect again.

  2. Hit “Custom Firmware ver xxx” button. You don’t need to select or upload a custom firmware, that’s done for you.

  3. Hit the “Start Flashing” button - it’s easy to miss. Wait - be patient. Don’t move devices around.

The flashing log should look something like this.

5:15:16 PM: Searching for devices

5:15:39 PM: Connecting to: LYWSD03MMC
5:15:42 PM: Hardware Revision String: B1.7
5:15:42 PM: Detected Mi device
5:15:42 PM: Get Advertising MAC (Web Experimental Features!)
5:15:42 PM: Connected
5:15:47 PM: MAC: A4C138XXXXXX
5:15:48 PM: Activating now, please wait...
5:15:52 PM: Registration successfull
5:15:52 PM: Send Login, please wait...
5:15:53 PM: Received device infos are correct
5:15:53 PM: Login successfull
5:15:56 PM: Load firmware file 'ATC_v38.bin'...
5:15:56 PM: File: ATC_v38.bin
5:15:56 PM: File size: 67252 bytes
5:15:56 PM: Count: 4204
5:16:37 PM: Start DFU
5:17:47 PM: Update done after 68.811 seconds
5:17:53 PM: Disconnected.

Make a note of the MAC address such as A4C138XXXXXX so you can copy and paste this later if required. It’s more commonly written A4:C1:38:XX:XX:XX

Disconnect, Reconnect, Configure
Once your custom firmware has confirmed it’s written disconnect and reconnect. From here you can configure any settings you like. I’m not an expert on what all these settings do, but I attempted to reduce the reporting frequency because for my application reporting every 5 - 10 minutes would be fine. To achieve that I made the following changes:

  • Advertising interval: 7500ms (7.5s). My understanding is this is how often the Bluetooth device sends out “I’m here” pings so a phone / computer can connect to it to alter the configuration. I read it’s meant to be 10 seconds or less.
  • Measure interval multiple. I set this to the max, 25, to reduce how often measurements are done. 7.5 * 25 = 187.5s = 3.125 minutes. That’s about how often I would expect to get temperature information. If I could make it less often, I would.
  • RF TX Power: turn this down as much as possible while still reliably getting readings. Most of mine I’ve left near zero, but the sensor in the fridge is about +3. If you’re having connection problems you can turn it up, if it’s connecting fine you can turn it down to reduce battery use.
  • Smiley: you can change how the face looks, or leave it to “comfort”. The additional settings below lets you configure the temperature thresholds.
  • Advertising type: I use “BTHome”.
  • Do NOT tick the “LE Long Range Only” box that is available in newer versions of the firmware. If you do this (as of 2023) Home Assistant can’t receive the messages, and you can’t connect to the temperature sensor with any computer, phone, or operating system I’ve tried (multiple Linux computers, multiple Bluetooth adapters, multiple phones that support BT5+). If you tick the box and untick the other box it’s probably unticked. More details here - NB very complicated.

You MUST hit “send config” once you’ve made these changes. The link above to the PVVX Github site has quite a bit more information.

Firmware v4.4

Firmware v3.8

Additional Configuration
There are additional things you can configure. I change the device name to something unique and easy to identify for Home Assistant - e.g. “Fridge” or “Office”. You can tweak the comfort parameters which control how the little face looks.

I also put a label on the back of the sensors so when I have them together I know which is which.

Sensors Configured
At this point your Bluetooth sensors are configured! Go use them!

I’ve found that with a good Bluetooth receiver the range is quite impressive when you use them with a good Bluetooth adapter with an external antenna:

  • 10m through three walls seems to work fine
  • 6m from inside a fridge and through three walls works fine
  • 10m through a house wall and a concrete block wall to my greenhouse gives low strength but works

Integrating the Sensors with Home Assistant
Around Aug / Sept / Oct 2022 Home Assistant is starting to build Bluetooth features into the HA core, under the name BTHome - not to be confused with British Telecom. At the time of writing (HA 2022.09.05 release I think) it works but not as well as Passive BLE Monitor. If your BLE signal strength is low you get gaps in your data, rather than using the previous temperature the sensors show “unavailable” or similar. I have both running, but I only use the data from Passive BLE Monitor, which also provide signal strength.

For now, you can install the Passive BLE monitor integration. Follow its instructions.

As of HA 2022.09 and later, just wait for BTHome to discover the sensors, give you a notification, at which point you can add them to HA.

If there’s anything that needs more explanation post below and I’ll do my best. I can’t always reply quickly, but I will usually reply eventually.

If you would like help
I’m not an expert, but I’ll help if I can. Please read this tutorial I wrote on the Bluetooth XDO BT802 adapter I wrote. Run all the commands from the “Ensure Bluetooth is Enabled” section down, put the output below. I would also need to know the hardware you have HA running on and the Bluetooth adapter in use.

20 Likes

I am just her to say thanks!

1 Like

HA does not find this device. When I attempt to add a Xiaomi BLE integration Ha says “no devices found on network.” Passive BLE will not install. Says “Only a single configuration of BLE monitor is allowed”. I assume that’s because the HA Bluetooth integration is installed.
I’m up to date on everything HA, ATC flash, Bluetooth.

I have the Bluetooth and Passive BLE Monitor integrations both installed.

I’m happy to help @uSlackr , though I’m not an expert - I only started using Bluetooth about a week ago. To provide help I would need to know:

Thanks.
I’m running on HA Blue
I’m using the ZEXMTE BT-DG54 [RTL8761BU] that I picked off of the HA BT integration page.

> dmesg|egrep -i "blu|hci|bt"
[    1.206252] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    1.211589] ehci-pci: EHCI PCI platform driver
[    1.215996] ehci-platform: EHCI generic platform driver
[    1.221259] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[    1.227274] ohci-pci: OHCI PCI platform driver
[    1.231692] ohci-platform: OHCI generic platform driver
[    1.312948] sdhci: Secure Digital Host Controller Interface driver
[    1.318093] sdhci: Copyright(c) Pierre Ossman
[    1.328614] sdhci-pltfm: SDHCI platform and OF driver helper
[    1.502659] xhci-hcd xhci-hcd.1.auto: xHCI Host Controller
[    1.507791] xhci-hcd xhci-hcd.1.auto: new USB bus registered, assigned bus number 1
[    1.515441] xhci-hcd xhci-hcd.1.auto: hcc params 0x0228fe6c hci version 0x110 quirks 0x0000000000010010
[    1.524696] xhci-hcd xhci-hcd.1.auto: irq 41, io mem 0xff500000
[    1.530550] xhci-hcd xhci-hcd.1.auto: xHCI Host Controller
[    1.535983] xhci-hcd xhci-hcd.1.auto: new USB bus registered, assigned bus number 2
[    1.543575] xhci-hcd xhci-hcd.1.auto: Host supports USB 3.0 SuperSpeed
[    1.810660] usb 1-1: new high-speed USB device number 2 using xhci-hcd
[    2.102787] usb 2-1: new SuperSpeed USB device number 2 using xhci-hcd
[    2.406689] usb 1-1.1: new full-speed USB device number 3 using xhci-hcd
[    2.642672] usb 1-1.2: new full-speed USB device number 4 using xhci-hcd
[    3.642146] Bluetooth: Core ver 2.22
[    3.642374] NET: Registered PF_BLUETOOTH protocol family
[    3.646036] Bluetooth: HCI device and connection manager initialized
[    3.651866] Bluetooth: HCI socket layer initialized
[    3.656609] Bluetooth: L2CAP socket layer initialized
[    3.661546] Bluetooth: SCO socket layer initialized
[    3.673256] usbcore: registered new interface driver btusb
[    3.675365] Bluetooth: hci0: RTL: examining hci_ver=0a hci_rev=000b lmp_ver=0a lmp_subver=8761
[    3.682382] Bluetooth: hci0: RTL: rom_version status=0 version=1
[    3.687690] Bluetooth: hci0: RTL: loading rtl_bt/rtl8761bu_fw.bin
[    3.697180] Bluetooth: hci0: RTL: loading rtl_bt/rtl8761bu_config.bin
[    3.700203] Bluetooth: hci0: RTL: cfg_sz 6, total sz 27814
[    3.846319] Bluetooth: hci0: RTL: fw version 0x09a98a6b
[    7.966444] Bluetooth: BNEP (Ethernet Emulation) ver 1.3
[    7.966458] Bluetooth: BNEP filters: protocol multicast
[    7.966467] Bluetooth: BNEP socket layer initialized
[    7.967854] random: bluetoothd: uninitialized urandom read (4 bytes read)
[   77.554024] Bluetooth: RFCOMM TTY layer initialized
[   77.554046] Bluetooth: RFCOMM socket layer initialized
[   77.554048] Bluetooth: RFCOMM ver 1.11
> lsusb
Bus 002 Device 002: ID 05e3:0620
Bus 001 Device 001: ID 1d6b:0002
Bus 001 Device 003: ID 10c4:8a2a
Bus 001 Device 002: ID 05e3:0610
Bus 002 Device 001: ID 1d6b:0003
Bus 001 Device 004: ID 0bda:8771

@uSlackr can you please edit your post to provide the output of the other commands in that other tutorial.

Sorry - meant to add the hcitool and hciconfig are not installed. Looks like they are part of bluez. Is it ok to install that without affecting the OS or HA? Well, apt-get doesn’t work either

Not sure about that. I can’t really help without the output of those commands. Take a backup / image before you mess about with things. I use this tool to create SD card backups, which I write to my PC using a mapped drive.

I figured it out. It wasn’t bluetooth related.
Using the Telink Flasher, I loaded the 3.8 firmware. I then set the Advertising Type to BTHome. I was then able to add them via the BTHome integration.
Thanks for the help and thanks to @the_Tinker_Dad on twitter

1 Like

Interesting, I’ve never used that integration. I just did a bit of reading about advertising types (link). It looks to be about the data format of the packets sent by the BLE devices.

  • BTHome is an open standard. This seemed to work without the BTHome plugin, but it took 20 - 30 minutes after I changed the setting to start working.
  • ATC441 didn’t work either
  • PVVX (custom) as I have in the diagrams seems to work fine.

@uSlackr Could you please link to the BTHome integration? I couldn’t find it in the “add integration” dialog or with Google. Google is confused with British Telecom / BT.

BTHome project
HA BTHome Integration
You have to have the BTHome integration to work with the bthome advert

Thanks :slight_smile: BTHome format seems to work fine without that plugin, I just had to wait 30 minutes after I changed the setting for the temperatures to start showing up.

Hi,

I managed to connect the Mijia using the BTHome integration, but I only have on sensor value:
sensor.atc_4851_signal_strength

I flashed ATC_v38.bin and then used Telink Flasher to set the advertising type to custom, 10sec and saved the settings to flash:


16:44:46: Detected custom Firmware
16:47:22: Settings AE was send successful
16:47:24: Settings FE01 was send successful
16:47:25: Settings DF was send successful

Does anybody know how to debug this?

…using the correct flasher did the trick

https://pvvx.github.io/ATC_MiThermometer/TelinkMiFlasher.html

now 4 values are shown

nevermind
cheers

2 Likes

What config did you send via https://pvvx.github.io/ATC_MiThermometer/TelinkMiFlasher.html ?

I used this link to flash the ATC_v38.bin file provided by the site and changed the advert type to BThome but I still only see the signal_strength sensor :frowning:

I largely used all the defaults, including the default firmware / binary file it wanted to use. Screenshots above show what I did fairly well. I din’t use the BTHome advert type, I used the default which my rusty memory thinks might be PVVX.

Once you’ve reflashed with the default type of advert see how it goes. I didn’t use the Home Assistant bluetooth features, I used and still use Passive BLE Monitor as I find it more reliable.

I had some struggle with this as well, but selecting BTHome did it! Now all my 6 devices show all sensors! This is on a fresh RPi3B+

1 Like

Same here. I followed the tutorial (thanks @tomwaldnz) without issues yet ‘Passive BLE monitor’ and ‘Xiaomi BLE’ integrations failed to read humidity and temperature (only signal strength and battery readings worked). Once I changed the advertising method to BTHome, then the BTHome integration was able to pick up humidity and temperature readings

I’ve edited the tutorial to add the BTHome information. I wonder why PVVX works for me but not others. I’ll get some more temperature sensors some time, when I do I’ll try both options out.

I also have a few problems: I have had a bunch of sensors on the custom ATC format with the BLE integration. I decided to switch them all over to BThome. Now only 4 of 7 sensors show values. Time has box fixed this for me so far.

I personally prefer gaps in the data rather than extrapolated data to show missing signals.