Skip to content

Jaj0/xiaomi-mi-lywsd03mmc

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Xiaomi Mi Temperature and Humidity Monitor 2 - Domoticz

release Python license open_issue closed_issue

The Xiaomi Mi sensor provides temperature and humidity over BLE.

This script also supports the ATC custom firmware!

This is updated version of script forked from erdose, which works correctly with custom ATC software. Be sure to select atc1441 format.

xiaomi_mi_2

How it works

  1. Preparing Domoticz

    Create a virtual sensor (Temperature & Humidity) in Domoticz (as much as you need).

    virtual_sensor

    Note the IDX value of virtual sensor (Setup/Devices)!

    virtual_sensor_idx

    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!

  2. Finding the Bluetooth MAC Address of the sensor

    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!

  3. Prepare the required modules

    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!

  4. Edit the config.py script

    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 configuration
    DOMOTICZ_SERVER_IP = "xxx.xxx.x.xxx"
    DOMOTICZ_SERVER_PORT = "xxxx"
    DOMOTICZ_USERNAME = ""
    DOMOTICZ_PASSWORD = ""

    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
  5. Schedule the update interval

    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

    Done!


Donate with PayPal

About

Xiaomi Mi BLE Temperature & Humidity Sensor

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%