This article is a kind of follow-up on the one I did originally in 2019. ESPhome has improved a lot over time and now there are these 4$ Xiaomi temperature and humidity sensors that can be hacked and then work in the same way. The absolute best way to get per room temperature sensing into Home Assistant in my opinion!
–update 2021-10
It seems a new hardware type of this sensor has surfaced with a different LCD driver in there. Currently the custom firmware out there don’t work perfectly on these versions (it’s being worked on). So right now I’d advise keeping the original firmware out there but the method to find the key can be still be used!
–update 2021-11
Firmware has been updated and now auto identifies old version and new version and works correctly!
Video Tutorial
The main part of this tutorial comes in the form of a video. In there I walk you through “hacking” the little 4$ modules, getting the right code into ESPhome and all surrounding subjects.
Product shopping links:
π New 4$ sensor (LYWSD03MMC): https://geni.us/A3KWeh
π “Old” Non-E-Ink Xiaomi Mijia Temp and Humi sensor (LYWSDCGQ): https://geni.us/Tr2RpJH
π E-ink Round (CGG1) model: https://geni.us/eJIB
π E-ink Bigger rectangular (LYWSD02) model: https://geni.us/JBWKR
ESP32 boards:
π MH-ET Live ESP32: http://geni.us/4OZdAj
π Wemos D32 Mini: https://geni.us/9aXV
USB power:
π High Quality Phone charger (very stable for ESP32, 5v 2A continuous): https://geni.us/TiSqB
USB Cable:
πGood Micro-USB cable: https://geni.us/4Yqui9t
Shoutout:
Again a big shoutout to Aaron Christophel for creating this amazing hack and putting it all together. Check out his video and Github!
Link to Hack Creator Video: https://youtu.be/NXKzFG61lNs
Link to Hack Creator Github: https://github.com/atc1441/ATC_MiThermometer
Text Bits:
To go with the video here are the text bits mentioned in there.
The below configuration sets some settings the way I like to use them, the most important line is the “esp32_ble_tracker” which enables bluetooth advertisement tracking. Please flash the binary with this enabled using USB the first time to make sure all internal partitioning is done correctly.
substitutions: esphome_name: minividtemp esphome: name: ${esphome_name} platform: ESP32 board: mhetesp32devkit wifi: ssid: !secret esphome_wifi_ssid password: !secret esphome_wifi_pass domain: .quindorian.iot logger: level: debug api: reboot_timeout: 60min password: !secret esphome_api_pass ota: password: !secret esphome_ota_pass time: - platform: homeassistant esp32_ble_tracker: switch: - platform: gpio name: "${esphome_name}-Onboard-LED" pin: 2 inverted: True - platform: restart name: ${esphome_name}-restart id: restart_switch sensor: - platform: uptime name: "${esphome_name}_Uptime Sensor" - platform: wifi_signal name: "${esphome_name} WiFi Signal" update_interval: 60s
The MAC address lines you are looking for looks something like this:
[16:33:56][D][esp32_ble_tracker:544]: Found device A4:C1:38:FA:4C:CB RSSI=-33 [16:33:59][D][esp32_ble_tracker:565]: Address Type: PUBLIC [16:33:59][D][esp32_ble_tracker:567]: Name: 'ATC_FA4CCB'
One you have found the MAC address (In this case the “A4:C1:38:FA:4C:CB” part), please add the following to the bottom of the config (in the sensor section):
- platform: xiaomi_lywsd03mmc mac_address: A4:C1:38:FA:4C:CB bindkey: "05e04076be48f427f3d90e166d0fbd5e" temperature: name: "MiniVideoTemp Temperature" humidity: name: "MiniVideoTemp Humidity" battery_level: name: "MiniVideoTemp Battery Level"
*If you are using the original firmware, please change bindkey value to what you saw on webpage, if using custom firmware, just leave bindkey line as it is and you only need to change the names.
The complete configuration then looks like this:
substitutions: esphome_name: minividtemp esphome: name: ${esphome_name} platform: ESP32 board: mhetesp32devkit wifi: ssid: !secret esphome_wifi_ssid password: !secret esphome_wifi_pass domain: .quindorian.iot logger: level: debug api: reboot_timeout: 60min password: !secret esphome_api_pass ota: password: !secret esphome_ota_pass time: - platform: homeassistant esp32_ble_tracker: switch: - platform: gpio name: "${esphome_name}-Onboard-LED" pin: 2 inverted: True - platform: restart name: ${esphome_name}-restart id: restart_switch sensor: - platform: uptime name: "${esphome_name}_Uptime Sensor" - platform: wifi_signal name: "${esphome_name} WiFi Signal" update_interval: 60s - platform: xiaomi_lywsd03mmc mac_address: A4:C1:38:FA:4C:CB bindkey: "05e04076be48f427f3d90e166d0fbd5e" temperature: name: "MiniVideoTemp Temperature" humidity: name: "MiniVideoTemp Humidity" battery_level: name: "MiniVideoTemp Battery Level"
Adding more then one Sensor
A single ESP32 can easily handle multiple sensors, to add multiple you just keep adding the last block of the config with the new MAC address and names such as:
- platform: xiaomi_lywsd03mmc mac_address: A4:C1:38:FA:4C:CB bindkey: "05e04076be48f427f3d90e166d0fbd5e" temperature: name: "MiniVideoTemp Temperature" humidity: name: "MiniVideoTemp Humidity" battery_level: name: "MiniVideoTemp Battery Level" - platform: xiaomi_lywsd03mmc mac_address: A4:C1:38:EF:8B:32 bindkey: "05e04076be48f427f3d90e166d0fbd5e" temperature: name: "OntopCloset Temperature" humidity: name: "OntopClosetHumidity" battery_level: name: "OntopClosetBattery Level" - platform: xiaomi_lywsd03mmc mac_address: A4:C1:38:AA:46:B2 bindkey: "05e04076be48f427f3d90e166d0fbd5e" temperature: name: "Cellar Temperature" humidity: name: "Cellar Humidity" battery_level: name: "Cellar Battery Level"
Ending remarks:
Battery life for the new sensors is currently still unknown, with the custom firmware it will be directly linked to the advertising interval, so be careful with setting it too low!
Also make sure to take a look at the old video and article, if you are unsure about the steps to take and process, there is other information in there!
Other then that, happy hacking and I believe this is a very easy way to add some cheap temperature and humidity sensors to Home Assistant which can then be deployed in various areas of your home!
Hi,
Can i ask you a question? I did everything above and flashed the ESP32 with success. I see in the logs the Uptime and wifi signal.
Only i’m not receiving any data from the sensors. The MAC address is correct. Do you have any idea why this is not working?
Thanks in advance!
Hey Eric, I just ran into this. Did you make sure when flashing the sensor to click the advertising like in the video. That made the difference for me.
Same here.
I’m using a Wemos D1 mini ESP32 and the device shows up in the list of devices,
Only two of the 4 (2/4) of the lywsd03mmc devices show up in the entities with each temeperature, humidity end battery .
But no values .
What goes wrong and where is more information to find ?
Thanks in Advance!
it looks like the settins are not persistent. so any time you take the battery out of the sensor, the adverstisement type goes back to “custom”.
I noticed that too… You just need to save the settings.
Once you have everything the way you want it you need to click the “Save current settings in flash” button. You’ll see the log state “Settings DF was send successful and the little device will show “Sto” on the screen. Hope that helps!
Hi this is awesome but I can’t figure out if I doing something wrong. When I try to put in
esp32_ble_tracker:
There is a red x in esphome’s
.yaml When I use your text bits.
If I change my board to the d1_mimi and the platform to ESP8266. You have ESP32 for the platform and mhetesp32devkit. I didn’t know if I can put that with a D1mini .
Thank you for this. I can’t wait until I get this working.
no, you cant. ESP8266 does not have BLE, only ESP32.
Thanks. Flashing was so easy. Can’t believe it’s done through a webpage on your mobile phone π
Very clear way of explaining things. Much appreciated.
One thing that I was wondering, you are listing 2 different ESP32 modules (and there are many other out there), how should I pick the right one for my application, or are they all more or less the same?
Thanks
Hi, thx for the tutorial, ive ordered 3 mini sensor via your ref. link π
my question is, how to make it possible with HA with ESP822 (nodeMCU) ?
is it possible, or i have to order that esp32 thing too?
(i already have nodeMCU)
Thanks
*ESP8266 (since you review the commentsd, pls corret to this, and then delete this one, thx)
Ah, silly me:) just did my research…
i need esp32, so ive ordered too, via your aff link.
you should delete all 3 of my comments:) thx
Fantastic Video! Many thanks for helping me set it all up. The way you do the videos is very informative and structured. Perfect to follow. Keep up the good work!
Regarding the ultra cheap sensors – please mention somewhere, (maybe in Ending Remarks above here) that after flashing with custom software, one need to also push the settings: Advertising Type: “Mi Like” as opposed to default “Custom” setting. I have spent a good few days wondering why everything went well but no values received from the sensor.
I don’t think Aaron mentions that.
Again, great videos and blogs, thank you very much for your hard work!
How do you do that?
You can do it in the TeLink flasher in chrome. There are a series of settings near the bottom of the page – see “Advertising Type”. Press the “Mi Like” button – it will immediately send this setting to the device, and add a line to the log at the bottom.
Hello,
I came across your video and followed the instructions for the Mi Square temp/humidity sensor. I am having trouble getting the temperature, battery, and humidity to show in home assistant. I am uncertain what I am doing wrong. Any assistance would be greatly appreciated.
Thanks,
Nathan
I have the same problem and I see in his video , he has a different platform name xiaomi_mija (which is shown working but not recognised by Esphome) as what he has in the program which is xiaomi_lywsd03mmc and appears as a standard sensor in Esphome but does not for me deliver the values in the log.The ble_tracker finds the MAC address and Name but no values – I am confused.
Ian
Hi Andries,
First of all thanks for the great YouTube channel and video’s, keep up the nice tutorials.
One question regarding this setup, yesterday with one ESP32 and one 4$ sensor it worked fine. Today I have setup two more ESP32’s and 7 extra 4$ sensors to cover our house but no information is shown in HA. The sensor that worked yesterday has now a solid line of death.
Any idea what I missed? Disabled BT of the staging mobile, restarted the 4$ sensors and ESP32’s as shown in the vid. And in the ESPhome logs of the ESP32’s I see the ATC_devices broadcasting for those that should be connected to that specific ESP32 but still no data in HA.
I really hope you can push me in the right direction.
Thanks and best regards,
Melvin
I have the same, any solution? do I need an API key and where do I find it?
Hello,
any ideas why my BT device does not report values.
I tried it with original FW and custom.
This is my first try with esphome and I like your tutorial lot.
Thanks Peter
12:48][D][esp32_ble_tracker:565]: Address Type: RANDOM
[12:12:48][C][logger:185]: Logger:
[12:12:48][C][logger:186]: Level: DEBUG
[12:12:48][C][logger:187]: Log Baud Rate: 115200
[12:12:48][C][logger:188]: Hardware UART: UART0
[12:12:48][C][esp32_ble_tracker:530]: BLE Tracker:
[12:12:48][C][esp32_ble_tracker:531]: Scan Duration: 300 s
[12:12:48][C][esp32_ble_tracker:532]: Scan Interval: 320.0 ms
[12:12:48][C][esp32_ble_tracker:533]: Scan Window: 30.0 ms
[12:12:48][C][esp32_ble_tracker:534]: Scan Type: ACTIVE
[12:12:48][C][restart:021]: Restart Switch ‘minividtemp-restart’
[12:12:48][C][restart:021]: Icon: ‘mdi:restart’
[12:12:48][C][xiaomi_lywsd03mmc:012]: Xiaomi LYWSD03MMC
[12:12:48][C][xiaomi_lywsd03mmc:013]: Bindkey: 05.E0.40.76.BE.48.F4.27.F3.D9.0E.16.6D.0F.BD.5E (16)
[12:12:48][C][xiaomi_lywsd03mmc:014]: Temperature ‘MiniVideoTemp Temperature’
[12:12:48][C][xiaomi_lywsd03mmc:014]: Unit of Measurement: ‘Β°C’
[12:12:48][C][xiaomi_lywsd03mmc:014]: Accuracy Decimals: 1
[12:12:48][C][xiaomi_lywsd03mmc:014]: Icon: ‘mdi:thermometer’
[12:12:48][C][xiaomi_lywsd03mmc:015]: Humidity ‘MiniVideoTemp Humidity’
[12:12:48][C][xiaomi_lywsd03mmc:015]: Unit of Measurement: ‘%’
[12:12:48][C][xiaomi_lywsd03mmc:015]: Accuracy Decimals: 0
[12:12:48][C][xiaomi_lywsd03mmc:015]: Icon: ‘mdi:water-percent’
[12:12:48][C][xiaomi_lywsd03mmc:016]: Battery Level ‘MiniVideoTemp Battery Level’
[12:12:48][C][xiaomi_lywsd03mmc:016]: Unit of Measurement: ‘%’
[12:12:48][C][xiaomi_lywsd03mmc:016]: Accuracy Decimals: 0
[12:12:48][C][xiaomi_lywsd03mmc:016]: Icon: ‘mdi:battery’
[12:12:48][C][web_server:131]: Web Server:
[12:12:48][C][web_server:132]: Address: minividtemp.fritz.box:80
[12:12:48][C][wifi_signal.sensor:009]: WiFi Signal ‘minividtemp WiFi Signal’
[12:12:48][C][wifi_signal.sensor:009]: Unit of Measurement: ‘dB’
[12:12:48][C][wifi_signal.sensor:009]: Accuracy Decimals: 0
[12:12:48][C][wifi_signal.sensor:009]: Icon: ‘mdi:wifi’
…
[12:13:05][D][esp32_ble_tracker:544]: Found device A4:C1:38:64:B8:57 RSSI=-77
[12:13:05][D][esp32_ble_tracker:565]: Address Type: PUBLIC
[12:13:05][D][esp32_ble_tracker:567]: Name: ‘ATC_64B857’
[12:13:21][D][sensor:092]: ‘minividtemp_Uptime Sensor’: Sending state 37.00500 s with 0 decimals of accuracy
yaml:
– platform: xiaomi_lywsd03mmc
mac_address: A4:C1:38:64:B8:57
bindkey: “05e04076be48f427f3d90e166d0fbd5e”
temperature:
name: “MiniVideoTemp Temperature”
humidity:
name: “MiniVideoTemp Humidity”
battery_level:
name: “MiniVideoTemp Battery Level”
The sensor log is showing data but I’m getting nothing in home assistant – any ideas?
hey Quindon, thanks for the 2 videos, after watching your $4 LYWSD03MMC video I ordered the sensors and the ESP32s, I used your referral links so I hope that you get something back in return.
After waiting what felt like a lifetime my sensors and ESP32s arrived and I watched and followed both your videos then got to work and after some initial panic thinking HA was not getting any data from the LYWSD03MMC I continued to wait and very slowly HA started to get data first only the Temp. then minutes later Battery and finally the Humidity (I am using the stock firmware for now) so it is very slow at updating but this would be optimized for a button cell battery – in any case I will also setup another unit with the hacked firmware just for comparison because like you I want to manage the bathroom vent fan.
Thanks again for the time and effort you put in and sharing the knowledge it greatly appreciated !
I have issue with one sensor. It doesnt advertise any parameters.
I did exact same procedure on every sensor (8 pcs) and only one is no advertising temp, bat, and hum. ESP is able to find it, I can pair with it. I tried refreshing and putting battery out but it did not helped. Any ideas ?
Try spamming Mi Home and 5min again, that should fix it
Excellent tutorial. Thank you Andries for your time dedicated on these. They work like magic and the custom firmware really makes it even more efficient.
For the people that have issues:
– Remember to ‘reconnect’ after flashing, wait for the ‘custom firmware detected message’
– And disconnect your phone (refreshing the page does that for you) before you check the ESPHome logs
Awesome man! Thx for the guide, I have it all up and running and love the stuff. Thank you so much. Looking forward to more content from you.
Greetz, Arjo
All is working, thanks to your video. Now what i want to do is to use the Xiaomi Temp Sensor as an external sensor for my Tado Thermostat Value in my Office. I have HA set up and all is working but im still missing how i can configure HA to take the Temp value of the Xiaomi and decide the heat my office or not (regulating the value and thermostat).
do you have any idea how to set this up (step by step)?
Thanks in advance and great content π
Cheers,
Bart
I wondered what I had done wrong, so I came back to this page to see if anyone else had the same issue I was experiencing. It doesn’t work too well without the “Mi Like” advertising. Thank you for filling in the missing piece Paul.
Can you explain how to use one ESP32 with multiple sensors? Adding another ‘-platform’ section results in an failure to validate.
I added it on to the article on the bottom π
How do I get one esp32 to be the hub for more than one LYWSD03MMC ? I tried just adding a second platform: xiaomi_lywsd03mmc with all the info with different sensor names, it looks like in the the log its receiving info from both sensors but HA isn’t seeing the first sensor data. Its only showing and updating the temp, humidity, and battery level of the second sensor and not the first even though both are shown in the esphome logs.
I just added a little piece to the article showing you how to do this! π
Is there an outdoor Xiaomi temperature sensor or a device that will work almost in the same way that is outdoor rated?
Thanks for the video and Post
Great video and tutorial for a (old) newbie like me.
Bought the MH-ET Live ESP32 board and 2 Mi temp sensors and got it to work, at least it shows me the temp/hum and battery information (flashed it with the custom fw)
It gave some frustration I was not able to use my iPhone for the flashing part, but using Chrome on my W10 notebook, I managed it to work.
My plan was to put one of the sensor in our bathroom and replace the zigbee Aqara sensor (without display) which I use for controlling my ventilation system.
Unfortunately this seems not to be working as the MultiRoom sensor is only updating once per 5 min (although I hit multiple times the 10 sec advertising interval button).
Is my assumption correct, or should it be possible to report once per 10sec back to HA?
And again, thanks for your video and post.
For me “Mi Like” doesn’t work. I switched Advertising Type back to “Custom” with Telink Flasher and use the platform: atc_mithermometer without a bindkey parameter. Thats the way all sensors works for me right now.
Hi,
Thanks for all your help. This works great with the little square units. How do you go about getting the LYWSD02 working? Unless I missed it you don’t address this in your video. The web app doesn’t work for flashing them.
Thanks!
Problem with Entity showing up as unavailable in home assistant. When I first did this a month ago It worked fine and I could see the data from the sensor. But know it just say’s unavailable but when looking at the log in Esphome the data is coming through. Don’t know what has changed in Esphome or Home Assistant. Please help if you see anything wrong with my code but like I said it use to work.
substitutions:
esphome_name: liverrmheater
esphome:
name: ${esphome_name}
platform: ESP32
board: esp-wrover-kit
wifi:
ssid: “****”
password: “****”
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: “****”
password: “****”
logger:
level: debug
api:
reboot_timeout: 60min
password: “esphome_api_****”
ota:
password: “****”
time:
– platform: homeassistant
esp32_ble_tracker:
switch:
– platform: gpio
name: “${esphome_name}-Onboard-LED”
pin: 2
inverted: True
– platform: restart
name: ${esphome_name}-restart
id: restart_switch
sensor:
– platform: uptime
name: “${esphome_name}_Uptime Sensor”
– platform: wifi_signal
name: “${esphome_name} WiFi Signal”
update_interval: 60s
– platform: xiaomi_lywsd03mmc
mac_address: A4:C1:38:7D:75:2D
bindkey: “05e04076be48f427f3d90e166d0fbd5e”
temperature:
name: “MiniVideoTemp Temperature”
humidity:
name: “MiniVideoTemp Humidity”
battery_level:
name: “MiniVideoTemp Battery Level”
Maybe a stupid question. But do I need only an ESP32 and the Thermometers? Or do I need also a RaspberryPI that runs HomeAssistant?
This is really meant for when you run Home Assistant (on whatever hardware)
Hi,
it was not possible for me to add the Sensor directly into HomeAssistant that is running on my Raspberry Pi. Have you any tips or tricks for that?
I tried the flashed sensor and the not flashed sensor. But it is not working π
All the best, and thx for the great video!
Hannelore
How many temp sensors can you load onto one ESP32?
Hi,
IΒ΄m getting a problem with my Mac adress
“INFO Reading configuration /config/esphome/vidtemp.yaml…
ERROR Error while reading config: Invalid YAML syntax:
mapping values are not allowed here
in “/config/esphome/vidtemp.yaml”, line 29, column 14:
mac_address: A4:C1:38:59:9F:75″
What is the reason?
I set up 8 of these on one ESP32. 4 of them work perfectly, but 4 of them give me crazy temperatures. For example, one of them clearly reads “75.3ΒΊ F” but in home assistant, it displays as “167.5ΒΊ F”. Am I doing something wrong? Do I need to split the number of sensors in half and move them to two separate ESP32’s?
Hi all,
Just discovered that during the initial boot phase the Xiaomi sensor consumes 3.9mA for about 5 seconds. And apparently not all CR2032 batteries are capable of providing that.
2 of my sensors had an empty battery. And somehow the new batteries (tried several brands) didn’t seem to be able to start the sensors. After some measurements, and making sure the new batteries where actually OK, I discovered that at boot up the Xiaomi consumes 3.9mA for a couple seconds and then drops to about 400Β΅A.
Batteries I had at hand (all made out of chinesium) could only deliver peak currents of between 1.3mA and 2mA. I’m now in search of ‘good’ batteries…
Hello,
I would like to get better coverage of ESP32
I meant, I want to setup second ESP32
I noticed, that if I assign one sensor into both ESP32 it gets dublicated in ESPhome.
Anyone experienced and resolved that issue?