|
|
8 年 前 | |
|---|---|---|
| .gitignore | 8 年 前 | |
| AUTHORS | 8 年 前 | |
| LICENSE | 8 年 前 | |
| README.md | 8 年 前 | |
| config.ini | 8 年 前 | |
| demo.gif | 8 年 前 | |
| miflora-mqtt-daemon.py | 8 年 前 | |
| requirements.txt | 8 年 前 | |
| template.service | 8 年 前 |
A simple Linux python script to query arbitrary Mi Flora plant sensor devices and send the data to an MQTT broker, e.g., the famous Eclipse Mosquitto. After data made the hop to the MQTT broker it can be used by home automation software, like openHAB or Home Assistant.
The program can be executed for a single run or in daemon mode to run continuously in the background.
The Mi Flora sensor offers the following plant and soil readings:
| Name | Description |
|---|---|
temperature |
Air temperature, in °C |
light |
Sunlight intensity, in [lux] |
moisture |
Soil moisture, in [%] |
conductivity |
Soil fertility, in [µS/cm] |
battery |
Sensor battery level, in [%] |
On a modern Linux system just a few steps are needed.
The following example shows the installation under Debian/Raspbian below the /opt directory:
sudo apt install git python3 python3-pip bluetooth bluez
git clone https://github.com/ThomDietrich/miflora-mqtt-daemon.git /opt/miflora-mqtt-daemon
cd /opt/miflora-mqtt-daemon
sudo pip3 install -r requirements.txt
To match personal needs, all operation details can be configured using the file config.ini.
vim /opt/miflora-mqtt-daemon/config.ini
Attention: You need to add at least one sensor to the configuration. Scan for available Mi Flora sensors in your proximity with the command:
sudo hcitool lescan
Interfacing your Mi Flora sensor with this program is harmless. The device will not be modified and will still work with the official Xiaomi app.
A first test run is as easy as:
python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py
⚠️️ Attention: Please ensure a good communication link to all Mi Floras. Sensors that can not be reached during the initital communication testing phase will be ignored. To evaluate connection reliability execute the program in from the command line at least once and pay attention to reported communication problems.
With a correct configuration the result should look similar to the the screencap above. Pay attention to communication errors due to distance related weak BLE connections.
The extensive output can be reduced to error messages:
python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py > /dev/null
You most probably want to execute the program continuously in the background. This can be done either by using the internal daemon or cron.
Attention: Daemon mode must be enabled in the configuration file (default).
sudo cp /opt/miflora-mqtt-daemon/template.service /etc/systemd/system/miflora.service
sudo systemctl daemon-reload
sudo systemctl start miflora.service
sudo systemctl status miflora.service
sudo systemctl enable miflora.service
screen -S miflora-mqtt-daemon -d -m python3 /path/to/miflora-mqtt-daemon.py
In the "mqtt-json" reporting mode, data will be published to the MQTT broker topic "miflora/sensorname" (names configurable).
An example:
{"light": 5424, "moisture": 30, "temperature": 21.4, "conductivity": 1020, "battery": 100}
This data can be subscribed to and processed by other applications, like openHAB.
Enjoy!
Xiaomi and Mi Flora are registered trademarks of BEIJING XIAOMI TECHNOLOGY CO., LTD.
This project is a community project not for commercial use. The authors will not be held responsible in the event of device failure or other damages.
This project is in no way affiliated with, authorized, maintained, sponsored or endorsed by Xiaomi or any of its affiliates or subsidiaries.