Нет описания

Thomas Dietrich 0914cf8b44 Add systemd service, sdnotify and local config 8 лет назад
.gitignore 0914cf8b44 Add systemd service, sdnotify and local config 8 лет назад
AUTHORS 77c154e924 Add functionality, improve error handling 8 лет назад
LICENSE 356d12f556 Added README and LICENSE 8 лет назад
README.md 0914cf8b44 Add systemd service, sdnotify and local config 8 лет назад
config.ini 2fe2f9e579 Adapt cache timeout to sleep period, cleanup 8 лет назад
demo.gif 42803693c4 Add demo.gif 8 лет назад
mqtt-flora.py 0914cf8b44 Add systemd service, sdnotify and local config 8 лет назад
requirements.txt 0914cf8b44 Add systemd service, sdnotify and local config 8 лет назад
template.service 0914cf8b44 Add systemd service, sdnotify and local config 8 лет назад

README.md

Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon

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 or the embedded MQTT broker in Home Assistant. After data made the hop to the MQTT broker it can be used by home automation software like Home Assistant or openHAB.

Demo gif for command line execution

The program can be executed for a single run or in daemon mode to run continuously in the background.

Features

  • Support for Xiaomi Mi Flora sensors (tested with firmware v2.6.2, v2.6.4, v2.6.6, v3.1.4, others anticipated)
  • Build on top of open-homeautomation/miflora
  • Highly configurable
  • Data publication via MQTT
  • JSON encoded
  • MQTT authentication support
  • Daemon mode (default)
  • Systemd service file included, sd_notify messages generated
  • MQTT-less mode, printing data directly to stdout/file
  • Reliable and inituitive
  • Tested on Raspberry Pi

Promotional image

Readings

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](https://observant.zendesk.com/hc/en-us/articles/208067926-Monitoring-Soil-Moisture-for-Optimal-Crop-Growth), in [%]
conductivity Soil fertility, in [µS/cm]
battery Sensor battery level, in [%]

Installation

On a modern Linux system just a few steps are needed. The following example shows the installation under Debian/Raspbian:

sudo apt install git python3 python3-pip bluetooth

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

Configuration

To match personal needs, all operation details can be configured using the file config.ini.

You need to add at least one sensor to the configuration. Scan for available Miflora sensors in your proximity with the command:

sudo hcitool lescan

Execution

A first test run is as easy as:

python3 mqtt-flora.py

With a correct configuration the result should look similar to the the screencap above. The extensive output can be reduced to error messages:

python3 mqtt-flora.py > /dev/null

Continous Daemon/Service

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).

  1. Systemd service - on systemd powered systems the recommended option
   sudo ln -s /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
  1. Screen Shell - Run the program inside a screen shell:
   screen -S mqtt-flora -d -m python3 /path/to/mqtt-flora.py
  1. Cron job - Add a new con job, e.g., /etc/cron.d/miflora, execute every 5 minutes
   */5 * * * * root python3 /path/to/mqtt-flora.py > /dev/null

Integration

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 Home Assistant or openHAB.

Enjoy!


Disclaimer and Legal

Xiaomi and Mi Flora are registered trademarks of BEIJING XIAOMI TECHNOLOGY CO., LTD.

This project is a community project not for commercial use.

This project is in no way affiliated with, authorized, maintained, sponsored or endorsed by Xiaomi or any of its affiliates or subsidiaries.