Domoticz Integration with Xiaomi Mi Temperature & Humidity Monitor
I created a script that automatically reads data from a Xiaomi Mi Temperature & Humidity Monitor sensor and sends it to Domoticz. It provides an easy way to send temperature, humidity and battery level data. You need a device with Bluetooth BLE support (such as Raspberry Pi).
Requirements
A Linux-based device (such as Raspberry Pi) with Python 3 installed. If you decide to use a different device, make sure it has a Bluetooth module that supports BLE (Bluetooth Low Energy). Raspberry Pi supports this standard, but for other devices you need to check the specifications on the manufacturer's website. You can also always buy an external USB module - it costs around PLN 40 on Allegro or about $2 on AliExpress.
Mi Bluetooth Temperature & Humidity Monitor sensor (the first version, which is the round one).
The following Python packages installed on the device: requests , bluepy .
Installation
Step 1: get the MAC address of the sensor's Bluetooth module
I got the address using the BLE Scanner app for Android. The app searches for all BLE devices within range of the phone's Bluetooth module and displays them as a list or graphically, estimating their location based on signal strength. Just walk up to the sensor with your phone and it should appear as the closest device. Note - the app requires access to your location. Unfortunately, this is due to Android permissions, where Bluetooth access is included under the location permission.
If you use an iOS device, try the BLE Scanner 4.0 app. I should point out that I have not had a chance to test it myself, although the reviews seem encouraging.
If you only have a Linux device, use the hcitool command provided by the bluez package.
Step 2: Add the device in Domoticz
Open the Domoticz panel in your browser, then select the "Setup" tab and "Hardware".
Add a device named "Mi TempHum Monitor" with the type "Dummy (Does nothing, use for virtual switches only)". Leave the other options unchanged. Confirm the operation with the "Add" button.
The newly added device should appear in the list above. Now click the "Create Virtual Sensors" button in the "Type" column.
A modal window will open. Add a new sensor named "Temp & Hum" with the type "Temp + Hum".
Now go to the "Temperature" tab.
Find the new sensor and click the "Edit" button.
The newly opened modal contains an "Idx" row. Save its value somewhere.
Step 3: Install the script
Install the required Python packages.
sudo apt-get install libglib2.0-dev
sudo apt-get install libglib2.0-dev
sudo apt-get install libglib2.0-dev
pip3 install requests bluepyClone the repository into any directory on your device, for example your home directory.
cd
git clone https://github.com/paulomac1000/Domoticz-MiTempHum-MonitorGo to the script directory.
cd Domoticz-MiTempHum-MonitorConfigure the script.
nano miTempHumStatus.pyGo to line 8 (the code below) and replace the URL with the address of your Domoticz instance, or leave it unchanged if the script will run on the same device.
DOMOTICZ_SERVER = "127.0.0.1:8080"Go to line 18 (the code below) and replace the value in square brackets with the MAC address of your sensor that you found earlier. Then replace the value after the equals sign with the "Idx" parameter of the sensor added to Domoticz. You can add more lines in the same way to configure additional sensors.
sensor_dict["00:00:00:00:00:00"] = 99Close the file using ctrl+x and save the changes.
Usage
To run the script, start it from the command line.
python3 miTempHumStatus.pyTo run the script automatically, add it to crontab.
crontab -eThen add the script command. The following entry will run the script every 15 minutes.
*/15 * * * * python3 /home/pi/Domoticz-MiTempHum-Monitor/miTempHumStatus.pyComments (0)
No comments yet.
Add a comment
Comments are published after moderation. Your e-mail address stays private.