Site icon Intermittent Technology

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!

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

Exit mobile version