The Xiaomi Mi sensor provides temperature and humidity over BLE.
This script also supports the ATC custom firmware! Be sure to select atc1441 format.
Create a virtual sensor (Temperature & Humidity) in Domoticz (as much as you need).
Note the IDX value of virtual sensor (Setup/Devices)!
If you want to get the raw voltage of battery, you also need to create the Voltage sensors too. The IDX value of the sensor is also required!
Enable API Basic Auth
Turn on the Xiaomi Mi sensor (Insert the battery).
Run the following command to find the MAC address:
sudo hcitool lescan
Example result:
LE Scan ...
46:4D:55:28:41:CA (unknown)
A4:C1:38:DC:8F:2E LYWSD03MMC
A4:C1:38:4D:D5:F0 ATC_4DD5F0
Note down the MAC address!
Install modules:
sudo apt update
sudo apt upgrade
Wait a minute...
sudo apt install -y python3 python3-pip git
sudo pip3 install requests bluepy
Check the Python version! It must be at least 3.6 or higher!
Clone repository:
git clone https://github.com/erdose/xiaomi-mi-lywsd03mmc.git
Open the config.py and edit the parameters at the top of the script!
cd xiaomi-mi-lywsd03mmc
sudo nano config.py
DOMOTICZ_CREDENTIALS : "username : password" encoded in base 64 https://mixedanalytics.com/tools/basic-authentication-generator/
# domoticz configuration
DOMOTICZ_SERVER_IP = "xxx.xxx.x.xxx"
DOMOTICZ_SERVER_PORT = "xxxx"
# username:password base64 encoded
DOMOTICZ_CREDENTIALS = ""
MAC : MAC address of the Xiaomi Mi sensor.
TH_IDX : IDX value of the Temperature & Humidity sensor(s) in Domoticz.
VOLTAGE_IDX : IDX value of the Voltage sensor(s) in Domoticz.
# sensor dictionary to add own sensors
# if you don't want to use the raw voltage option, just write -1 in the VOLTAGE_IDX value field
sensors = { 1: {"MAC": "xx:xx:xx:xx:xx:xx", "TH_IDX": 1, "VOLTAGE_IDX": -1, "UPDATED": False},
2: {"MAC": "xx:xx:xx:xx:xx:xx", "TH_IDX": 2, "VOLTAGE_IDX": -1, "UPDATED": False},
3: {"MAC": "xx:xx:xx:xx:xx:xx", "TH_IDX": 3, "VOLTAGE_IDX": -1, "UPDATED": False}}
TEMPERATURE_PREC: Accuracy of the temperature value.
# other configuration
TEMPERATURE_PREC = 2
LOG_FILE_NAME: The name of the log file.
LOG_FILE_SIZE: The size of the log file in bytes.
# Logfile configuration
LOG_FILE_NAME = 'loginfo.log'
LOG_FILE_SIZE = 1024 # file size in bytes
Enable the script to run at a regular interval (5 mins):
sudo crontab -e
Add this line (if you use this path):
*/5 * * * * cd /home/pi/xiaomi-mi-lywsd03mmc && timeout -k 10 60 python3 xiaomiBleLywsd03mmc.py