4$ Xiaomi Temperature Sensor for Home Assistant

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!

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!

40 thoughts on “4$ Xiaomi Temperature Sensor for Home Assistant”

  1. 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!

    1. 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.

    2. 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!

      1. 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”.

  2. 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.

  3. Thanks. Flashing was so easy. Can’t believe it’s done through a webpage on your mobile phone 😀

  4. 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

  5. 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

  6. 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

  7. 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!

  8. 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

    1. 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

  9. 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

  10. 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”

  11. 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 !

  12. 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 ?

  13. 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

  14. 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

  15. 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

  16. 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.

  17. Can you explain how to use one ESP32 with multiple sensors? Adding another ‘-platform’ section results in an failure to validate.

  18. 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.

  19. 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

  20. 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.

  21. 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.

  22. 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!

  23. 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”

  24. Maybe a stupid question. But do I need only an ESP32 and the Thermometers? Or do I need also a RaspberryPI that runs HomeAssistant?

  25. 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

Leave a Reply

Your email address will not be published. Required fields are marked *