All Projects → ThomDietrich → Miflora Mqtt Daemon

ThomDietrich / Miflora Mqtt Daemon

Licence: mit
Linux service to collect and transfer Xiaomi Mi Flora plant sensor data via MQTT to your smart home system, with cluster support 🌱🌼🥀🏡🌳

Programming Languages

python
139335 projects - #7 most used programming language
python3
1442 projects

Projects that are alternatives of or similar to Miflora Mqtt Daemon

Homeautomation.codesys3
Home Automation system build in CoDeSys 3 with MQTT communication to any third party Home Automation software
Stars: ✭ 55 (-86.55%)
Mutual labels:  home-assistant, home-automation, openhab, mqtt
Openmqttgateway
MQTT gateway for ESP8266, ESP32, Sonoff RF Bridge or Arduino with bidirectional 433mhz/315mhz/868mhz, Infrared communications, BLE, Bluetooth, beacons detection, mi flora, mi jia, LYWSD02, LYWSD03MMC, Mi Scale, TPMS, BBQ thermometer compatibility, SMS & LORA.
Stars: ✭ 2,413 (+489.98%)
Mutual labels:  home-assistant, home-automation, xiaomi, mqtt
Homeassistant
Home Assistant Configuration Files and Documentation
Stars: ✭ 395 (-3.42%)
Mutual labels:  home-assistant, home-automation, mqtt
Home Assistant Config Fr
🏠Configuration de Home Assistant en français. 👨🏻‍💻 N'hésitez pas à ⭐ mon repo et à copier les bonnes idées ! 🇨🇵
Stars: ✭ 175 (-57.21%)
Mutual labels:  home-assistant, home-automation, mqtt
Home Assistant
Home-Assistant-Config
Stars: ✭ 182 (-55.5%)
Mutual labels:  home-assistant, home-automation, mqtt
Awesome Home Assistant
A curated list of amazingly awesome Home Assistant resources.
Stars: ✭ 3,487 (+752.57%)
Mutual labels:  home-assistant, home-automation, mqtt
Temper Esp8266
Temper is a compact temperature sensor based on ESP8266 and SHT30 with large 13x7 pixel led display.
Stars: ✭ 155 (-62.1%)
Mutual labels:  home-assistant, home-automation, mqtt
Heatpump
Arduino library to control Mitsubishi Heat Pumps via connector cn105
Stars: ✭ 327 (-20.05%)
Mutual labels:  home-assistant, openhab, mqtt
Itead sonoff
Alternative firmware for Itead Sonoff switches, based on the MQTT protocol and a TLS connection
Stars: ✭ 115 (-71.88%)
Mutual labels:  home-assistant, home-automation, mqtt
soma-ctrl
Node util for controlling SOMA smart shade via MQTT or HTTP
Stars: ✭ 19 (-95.35%)
Mutual labels:  home-automation, mqtt, home-assistant
texecom2mqtt-hassio
Home Assistant add-on. Connect to Texecom Premier Elite alarm panels and publish updates to MQTT. Supports arming/disarming as well as zone updates and alarm events.
Stars: ✭ 15 (-96.33%)
Mutual labels:  home-automation, mqtt, home-assistant
amshan-homeassistant
Home Assistant integrasjon for strømmålere (AMS/HAN/P1). Integrasjonen støter både streaming (serieport/TCP-IP) og MQTT (Tibber Pulse, energyintelligence.se etc)
Stars: ✭ 39 (-90.46%)
Mutual labels:  home-automation, mqtt, home-assistant
Kmansonoff
Firmware for ESP8266 based itead Sonoff switches for use with HomeAssistant / mqtt
Stars: ✭ 282 (-31.05%)
Mutual labels:  home-assistant, home-automation, mqtt
Python Miio
Python library & console tool for controlling Xiaomi smart appliances
Stars: ✭ 1,995 (+387.78%)
Mutual labels:  home-assistant, home-automation, xiaomi
Esphome
ESPHome is a system to control your ESP8266/ESP32 by simple yet powerful configuration files and control them remotely through Home Automation systems.
Stars: ✭ 4,324 (+957.21%)
Mutual labels:  home-assistant, home-automation, mqtt
Android Mqtt Alarm Panel
Android Alarm Panel for Home Assistant and Home Automation Platforms (http://thanksmister.com/android-mqtt-alarm-panel/)
Stars: ✭ 124 (-69.68%)
Mutual labels:  home-assistant, home-automation, mqtt
Harmony Api
🗼 A simple server allowing you to query/control multiple local Harmony Home Hubs over HTTP or MQTT
Stars: ✭ 345 (-15.65%)
Mutual labels:  home-assistant, home-automation, mqtt
Home Assistant Configuration
My Home Assistant Config. For more Information visit ->
Stars: ✭ 102 (-75.06%)
Mutual labels:  home-assistant, home-automation, mqtt
Loadcelloccupany
Home automation occupancy sensor using load cells
Stars: ✭ 103 (-74.82%)
Mutual labels:  home-assistant, home-automation, mqtt
Dsckeybusinterface
An Arduino/esp8266/esp32 library to directly interface with DSC security systems.
Stars: ✭ 202 (-50.61%)
Mutual labels:  home-assistant, home-automation, openhab

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

Demo gif for command line execution

The program can be executed in daemon mode to run continuously in the background, e.g., as a systemd service.

About Mi Flora

  • Xiaomi Mi Flora sensors (e.g. 12-17€) are meant to keep your plants alive by monitoring soil moisture, soil conductivity and light conditions
  • The sensor uses Bluetooth Low Energy (BLE) and has a rather limited range
  • A coin cell battery is used as power source, which should last between 1.5 to 2 years under normal conditions
  • Food for thought: The sensor can also be used for other things than plants, like in the fridge or as door and blind sensor

Features

Promotional image

Readings

The Mi Flora sensor offers the following plant and soil readings:

Name Description
temperature Air temperature, in [°C] (0.1°C resolution)
light Sunlight intensity, in [lux]
moisture Soil moisture, in [%]
conductivity Soil fertility, in [µS/cm]
battery Sensor battery level, in [%]

Prerequisites

An MQTT broker is needed as the counterpart for this daemon. Even though an MQTT-less mode is provided, it is not recommended for normal smart home automation integration. MQTT is huge help in connecting different parts of your smart home and setting up of a broker is quick and easy.

Installation

On a modern Linux system just a few steps are needed to get the daemon working. 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

The daemon depends on gatttool, an external tool provided by the package bluez installed just now. Make sure gatttool is available on your system by executing the command once:

gatttool --help

Configuration

To match personal needs, all operation details can be configured using the file config.ini. The file needs to be created first:

cp /opt/miflora-mqtt-daemon/config.{ini.dist,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

LE Scan ...
4B:47:E2:DE:CE:9A (unknown)
C4:7C:8D:62:72:49 Flower care
84:C0:EF:46:B2:8A (unknown)
10:0B:F1:43:59:16 (unknown)
C4:7C:8D:62:40:29 Flower care

By the way: Interfacing your Mi Flora sensor with this program is harmless. The device will not be modified and will still work with the official smartphone app.

Some configuration options can be set via environment variables, see config.ini for details.

Execution

A first test run is as easy as:

python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py

With a correct configuration the result should look similar to the the screencap above. Pay attention to communication errors due to distance related weak Bluetooth connections.

Using the command line argument --config, a directory where to read the config.ini file from can be specified, e.g.

python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py --config /opt/miflora-config

Continuous 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 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
    

Usage with Docker

A Dockerfile in the repository can be used to build a docker container from the sources with a command such as:

docker build -t miflora-mqtt-daemon .

Running the container in interactive mode works like this:

docker run -it --name miflora-mqtt-daemon -v .:/config miflora-mqtt-daemon

To run the container in daemon mode use -d flag:

docker run -d --name miflora-mqtt-daemon -v .:/config miflora-mqtt-daemon

The /config volume can be used to provide a directory on the host which contains your config.ini file (e.g. the . in the above example could represent /opt/miflora-mqtt-daemon). You may need to tweak the network settings (e.g. --network host) for Docker depending on how your system is set up.

Integration

In the "mqtt-json" reporting mode, data will be published to the MQTT broker topic "miflora/sensorname" (e.g. miflora/petunia). An example:

{"light": 5424, "moisture": 30, "temperature": 21.4, "conductivity": 1020, "battery": 100}

This data can be subscribed to and processed by other applications. From this point forward your options are endless.

Enjoy!

openHAB

The following shows an example of a textual configuration using the MQTT binding introduced with openHAB 2.4. The example also uses the new internal broker.

Thing file
Bridge mqtt:systemBroker:MqttBroker "MQTT Broker" [ brokerid="embedded-mqtt-broker" ]
{
    Thing topic FicusBenjamin "Ficus Benjamin"
    {
        Channels:
            Type number : light         "Light Intensity"   [ stateTopic="miflora/FicusBenjamin", transformationPattern="JSONPATH:$.light" ]
            Type number : battery       "Battery Charge"    [ stateTopic="miflora/FicusBenjamin", transformationPattern="JSONPATH:$.battery" ]
            Type number : temperature   "Temperature"       [ stateTopic="miflora/FicusBenjamin", transformationPattern="JSONPATH:$.temperature" ]
            Type number : conductivity  "Soil Fertility"    [ stateTopic="miflora/FicusBenjamin", transformationPattern="JSONPATH:$.conductivity" ]
            Type number : moisture      "Soil Moisture"     [ stateTopic="miflora/FicusBenjamin", transformationPattern="JSONPATH:$.moisture" ]
    }
}
Item file
Number:Illuminance      Miflora_Ficus_Light         "Light Intensity Ficus [%d lx]"     <light>         { channel="mqtt:topic:MqttBroker:FicusBenjamin:light" }
Number:Dimensionless    Miflora_Ficus_Battery       "Battery Charge Ficus [%d %%]"      <battery>       { channel="mqtt:topic:MqttBroker:FicusBenjamin:battery" }
Number:Temperature      Miflora_Ficus_Temperature   "Temperature Ficus [%.1f °C]"       <temperature>   { channel="mqtt:topic:MqttBroker:FicusBenjamin:temperature" }
Number                  Miflora_Ficus_Conductivity  "Soil Fertility Ficus [%d µS/cm]"   <lawnmower>     { channel="mqtt:topic:MqttBroker:FicusBenjamin:conductivity" }
Number:Dimensionless    Miflora_Ficus_Moisture      "Soil Moisture Ficus [%d %%]"       <humidity>      { channel="mqtt:topic:MqttBroker:FicusBenjamin:moisture" }

ThingsBoard

To integrate with ThingsBoard.io:

  1. in your config.ini set reporting_method = thingsboard-json
  2. in your config.ini assign unique sensor names for your plants
  3. on the ThingsBoard platform create devices and use Access token as Credential type and the chosen sensor name as token

Wiren Board

To integrate with Wiren Board in your config.ini set:

  1. reporting_method = wirenboard-mqtt
  2. set hostname with address of Wiren Board controller and optionally username and password

Your sensors will automatically appear on Wiren Board as separate devices.


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. The authors will not be held responsible in the event of device failure or withered plants.

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].