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"

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!

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

  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

Leave a Reply

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