Coder Social home page Coder Social logo

thomdietrich / miflora-mqtt-daemon Goto Github PK

View Code? Open in Web Editor NEW
602.0 37.0 142.0 431 KB

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

License: MIT License

Python 97.29% Dockerfile 2.71%
xiaomi xiaomi-smart-home miflora python3 mqtt mqtt-connector openhab openhab2 home-automation home-assistant

miflora-mqtt-daemon's Introduction

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

In case you intent to run the service on a Raspberry Pi OS (64-bit), you need to install this packages as well to prevent the bluepy Building wheel for bluepy (setup.py) ... error error.

sudo apt install libglib2.0-dev
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.

It can be worth deleting any redundant images after building a new image:

docker image prune 

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.

miflora-mqtt-daemon's People

Contributors

alexbarcelo avatar apauly avatar aqualx avatar arossmann avatar bangom avatar chouille avatar chrostek avatar cycl0psg avatar devmafi avatar hakan42 avatar hmmbob avatar hobbyquaker avatar iia avatar individual-it avatar insertjokehere avatar janw avatar jleeca avatar jmservera avatar krikk avatar larsac avatar markkuuss avatar martinlindjarv avatar muhkuhgh avatar nbartels avatar nohum avatar rusitschka avatar skatun avatar the-jeffski avatar thomdietrich avatar tobylorenz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

miflora-mqtt-daemon's Issues

Connection error with result code 2 - Connection Refused: identifier rejected.

Hello,

I'm trying the new openhab internal MQTT broker and so far all my devices are working great.

I can't get the MQTT Daemon to connect though (triple-checked correct credentials):

[2018-11-05 18:51:24] Connecting to MQTT broker ... [2018-11-05 18:51:24] Connection error with result code 2 - Connection Refused: identifier rejected.

Looks like the broker is not happy with the client ID, see here: https://jaimyn.com.au/mqtt-connection-failed-status-codes-connack-return-codes/

But the config.ini does not allow to change the client ID. how is it chosen?

Cheers

Damon stop working

Hi, i install the daemon on a pi 0w with raspbian. Works great for a while, but couple of weeks I got almost every 1 a 2 days an error and my daemon stops working.

* miflora.service - Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
   Loaded: loaded (/etc/systemd/system/miflora.service; enabled; vendor preset: 
   Active: failed (Result: exit-code) since Thu 2018-01-11 10:47:28 UTC; 29min a
     Docs: https://github.com/ThomDietrich/miflora-mqtt-daemon
  Process: 242 ExecStart=/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py (code=e
 Main PID: 242 (code=exited, status=1/FAILURE)
   Status: "Jan 11 10:47:28 - MQTT connection error. Please check your settings 

jan 11 10:47:20 pi-zero-w systemd[1]: Starting Xiaomi Mi Flora Plant Sensor MQTT
jan 11 10:47:28 pi-zero-w miflora-mqtt-daemon.py[242]: [2018-01-11 10:47:28] MQT
jan 11 10:47:28 pi-zero-w systemd[1]: miflora.service: Main process exited, code
jan 11 10:47:28 pi-zero-w systemd[1]: Failed to start Xiaomi Mi Flora Plant Sens
jan 11 10:47:28 pi-zero-w systemd[1]: miflora.service: Unit entered failed state
jan 11 10:47:28 pi-zero-w systemd[1]: miflora.service: Failed with result 'exit-

Provide daemon configuration and sensors via MQTT subscription topic

We'll be using these sensors to monitor outdoor plants, and because of range issues for BLE, will have multiple monitoring daemons. It'd be lovely to be able to inform the daemons at wakeup what sensors they "own" without having to modify the config.ini by hand every time a new sensor gets added or a potted plant gets moved from one coverage area to another.

not updating values

running an mosquitto broker on an RP3b with OH gives me the following output:
'''
[16:55:08] openhabian@smarthome:~$ python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py

Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
Source: https://github.com/ThomDietrich/miflora-mqtt-daemon

[2018-11-16 16:55:13] Connecting to MQTT broker ...
[2018-11-16 16:55:13] MQTT connection established

Adding sensor to device list and testing connection ...
Name: "FlowerCare"
Internal name: "FlowerCare"
Device name: "Flower care"
MAC address: C4:7C:8D:XX:XX:XX
Firmware: 2.7.0
[2018-11-16 16:55:17] Initial connection to Mi Flora sensor "FlowerCare" (C4:7C:8D:XX:XX:XX) successful

[2018-11-16 16:55:17] Announcing Mi Flora devices to MQTT broker for auto-discovery ...

[2018-11-16 16:55:18] Retrieving data from sensor "FlowerCare" ...
[2018-11-16 16:55:18] Result: {"conductivity": 3, "battery": 100, "light": 324, "moisture": 0, "temperature": 19.0}
[2018-11-16 16:55:18] Publishing to MQTT topic "miflora/FlowerCare"

[2018-11-16 16:55:19] Sleeping (300 seconds) ...
'''
But OpenHAB isn't updating any channels. I'm using those:
mqtt="<[broker:miflora/FlowerCare:state:JSONPATH($.anyValue)]"

Problem with adding devices

Hi,
sorry to bother you again. I freshly reinstalled my rpi und the miflora-mqtt-daemon. I see my devices with hcitool lescan but I can't add them. I get the following error:

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

Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
Source: https://github.com/ThomDietrich/miflora-mqtt-daemon

[2017-10-16 13:25:13] Connecting to MQTT broker ...
[2017-10-16 13:25:13] MQTT connection established

Adding sensor to device list and testing connection ...
Name:          "tomato"
Traceback (most recent call last):
  File "/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py", line 188, in <module>
    flora_poller = MiFloraPoller(mac=mac, cache_timeout=miflora_cache_timeout, retries=3, adapter=used_adapter)
TypeError: __init__() missing 1 required positional argument: 'backend'

Checked my config.ini but can't find a mistake. Any idea? Thanks

Integration with HomeAssistant on different RaspberryPi raises wildcard issue

Hi everyone,

I receive the following issue after running the initial execution:

 Announcing Mi Flora devices to MQTT broker for auto-discovery ...
Traceback (most recent call last):
  File "/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py", line 305, in <module>
    mqtt_client.publish('{}/{}_{}/config'.format(topic_path, flora_name, sensor).lower(), json.dumps(payload), 1, True)
  File "/usr/local/lib/python3.5/dist-packages/paho/mqtt/client.py", line 1057, in publish
    raise ValueError('Publish topic cannot contain wildcards.')
ValueError: Publish topic cannot contain wildcards.

The MQTT connection is successfully established. I used mainly the standard configuration with the exception of the hostname which I set to the correct IP of my MQTT broker instance which is using the hass.io add-on for the MQTT broker. My hope was to use the auto-discovery to integrate seamlessly.

I haven't found anything by googling, so I am not sure if this is a very unique issue or just my incompetence.

Home assistant MQTT help

I use Home assiatant (on Synology)
I set reporting_method = homeassistant-mqtt in config.ini

My sensor is
Dwarfbanana = C4:7C:8D:67:3B:13

Help me please with configuration.yaml

sensor:

  • platform: mqtt
    state_topic: homeassistant/sensor/dwarfbanana/state

works but receive all results together:
{"conductivity": 1274, "temperature": 20.1, "moisture": 44, "light": 155, "battery": 99}

I should perfer results separately
conductivity
temperature etc

I need help please

When Temperature is below zero MQTT-daemon returns very high values (<6553.5)

During these cold nights my sensor measure temperatures below zero. The MiFlora App gives the right temperature, while the MQTT-daemon returns
{"conductivity": 1397, "moisture": 35, "temperature": 6553.5, "light": 66, "battery": 98}

This is clearly due to the fact that the temperature is a SIGNED integer while the Miflora-daemon interprets it as an UNSIGNED integer.

first run poller error

My miflora is working with ios app and detected with lescan
When I try running the miflora-mqtt-daemon.py I get following error:

Any ideas where my problem might be?

alexroot@openhabserver /opt/miflora-mqtt-daemon (git)-[master] # python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py

Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
Source: https://github.com/ThomDietrich/miflora-mqtt-daemon

[2018-05-02 11:39:34] Connecting to MQTT broker ...
[2018-05-02 11:39:34] MQTT connection established

Adding sensor to device list and testing connection ...
Name: "Tomato"
Traceback (most recent call last):
File "/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py", line 218, in
flora_poller.fill_cache()
File "/usr/local/lib/python3.6/dist-packages/miflora/miflora_poller.py", line 61, in fill_cache
firmware_version = self.firmware_version()
File "/usr/local/lib/python3.6/dist-packages/miflora/miflora_poller.py", line 104, in firmware_version
res = connection.read_handle(_HANDLE_READ_VERSION_BATTERY) # pylint: disable=no-member
File "/usr/local/lib/python3.6/dist-packages/btlewrap/gatttool.py", line 23, in _func_wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/btlewrap/gatttool.py", line 253, in read_handle
raise BluetoothBackendException("Exit read_ble, no data ({})".format(current_thread()))
btlewrap.base.BluetoothBackendException: Exit read_ble, no data (<_MainThread(MainThread, started -1225293296)>)

Wrong negative Light Value above specific threshold.

I don't know the exact treshold but the light value turns negative above a specific value..

11000 ok
22000 ok
33000 ok

-2461 when it really is 112k.something

In C I would say it's an overflow cause maybe the unsigned 16bit unsigned int ends here or something.. but there are no variable types in python, or? I couldn't find the cause looking in the code on my own :(

Enhancement: Report all discovered sensors

It would be very useful if the daemon would report any and all Plant sensors it found to the MQTT server. That way, I could just configure and deploy a Pi zero in the glasshouse ("Gewächshaus" in german) and won't need to touch it ever again, basically creating a solid-state miflora gateway.

If no "pretty name" has been configured, the Bluetooth MAC could be used as a topic, maybe without the ":" signs in it.

Docker container

Any chance you could create a docker container for raspberry pi 3?

Add timestamp to messages

Adding a timestamp to every MQTT message would make it easy to see, if the message shows the current state of the sensor or if the sensor was unreachable.

Deamon stop to work after some time - not yet merged fork

Hello,
So I could not raise an issue on https://github.com/aqualx/miflora-mqtt-daemon directly so I am doing it here hoping that @aqualx would see it.

I have been using your fork and I believe I run into issue.
I have both miflora sensors and and Mija bluetooth temperature monitor configured, some of the miflora sensors became unavailable from time to time (they are on a balcony and when blinds close BLE connection is lost).
Nevertheless I have noticed that the deamon freeze from time to time.
I had it run in a screen session to see the output:

[2019-03-25 00:51:08] Result: {"humidity": 44.4, "temperature": 23.0, "battery": 93}
[2019-03-25 00:51:08] Publishing to MQTT topic "misensor/XMiTH_Bedroom"

[2019-03-25 00:51:08] Sleeping for Mijia Bluetooth Temperature Smart Humidity (60 seconds) ...

[2019-03-25 00:52:08] Retrieving data from Mijia Bluetooth Temperature Smart Humidity sensor "XMiTH_Bedroom" ...
[2019-03-25 00:52:16] Result: {"humidity": 44.5, "temperature": 23.0, "battery": 93}
[2019-03-25 00:52:16] Publishing to MQTT topic "misensor/XMiTH_Bedroom"

[2019-03-25 00:52:16] Sleeping for Mijia Bluetooth Temperature Smart Humidity (60 seconds) ...

[2019-03-25 00:53:16] Retrieving data from Mijia Bluetooth Temperature Smart Humidity sensor "XMiTH_Bedroom" ...
[2019-03-25 00:53:31] Result: {"humidity": 44.3, "temperature": 23.0, "battery": 93}
[2019-03-25 00:53:31] Publishing to MQTT topic "misensor/XMiTH_Bedroom"

[2019-03-25 00:53:31] Sleeping for Mijia Bluetooth Temperature Smart Humidity (60 seconds) ...

[2019-03-25 00:54:31] Retrieving data from Mijia Bluetooth Temperature Smart Humidity sensor "XMiTH_Bedroom" ...

And today its like almost 24h after the last output being displayed and no new response has show up.
After I restart the deamon everything gets back to normal for like a day.

Let me know if I could add more input to this.

flores_to_openhab_items

Arch Linux RaspPi0W here. Had to delete line 237, got an UnicodeEncodeError, ascii something after fetching ble data. Guess its because no openhab is running here? Im no pro so dono if this is relevant. Wanted to integrate this into node-red and your projekt seemed to be the best way. Cheers

User friendly config

This is a openhab spesific suggestion:
To make it easier for the average user the config.ini file could be located in the conf/scripts folder of the openhab enviroment. So when you open visual studio you can edit the config.ini as well as miflora.items without looking around in the different samba drives for it.

If you wanna take it even one step further, we could generate the config.ini file based on the mqtt.cfg(there the broker is defined..) and use tags on the miflora.items for the mac addresses(or my favourite define miflora.things where we define the mac address)

Deamon stopps working if Sensor not found

Hi !
The demon works fine if the miflora sensor is in range. If not the deamon (or the underlaying library) stops working with the message:

Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
Source: https://github.com/ThomDietrich/miflora-mqtt-daemon

Adding sensor to device list and testing connection ...
Name:          "FloraCare01"
Traceback (most recent call last):
  File "/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py", line 218, in <module>
    flora_poller.fill_cache()
  File "/usr/local/lib/python3.5/dist-packages/miflora/miflora_poller.py", line 61, in fill_cache
    firmware_version = self.firmware_version()
  File "/usr/local/lib/python3.5/dist-packages/miflora/miflora_poller.py", line 104, in firmware_version
    res = connection.read_handle(_HANDLE_READ_VERSION_BATTERY)  # pylint: disable=no-member
  File "/usr/local/lib/python3.5/dist-packages/btlewrap/gatttool.py", line 23, in _func_wrapper
    return func(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/btlewrap/gatttool.py", line 253, in read_handle
    raise BluetoothBackendException("Exit read_ble, no data ({})".format(current_thread()))
btlewrap.base.BluetoothBackendException: Exit read_ble, no data (<_MainThread(MainThread, started -1225092352)>)

I test this by simply add a not existing mac in the config.ini
I have installed miflora v0.4. Any ideas ?

Do not log datetime when in daemon mode

It will already be shown in the systemctl status view.
How to detect? We might need to introduce a command line argument to tell the daemon to run in daemon-no-datetime-mode

cannot import name 'init'

On a clean install of rasbian, I am getting this error when I run miflora:

pi@raspberrypi:~ $ python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py
Traceback (most recent call last):
File "/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py", line 11, in
from colorama import init as colorama_init
ImportError: cannot import name 'init'

Error on testing

Just installed and updated the config.ini with address. then this error.

[2018-01-30 11:35:53] Connecting to MQTT broker ...
[2018-01-30 11:35:53] MQTT connection established

Adding sensor to device list and testing connection ...
Name: "kitchenFlower"
Traceback (most recent call last):
File "/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py", line 208, in
flora_poller = MiFloraPoller(mac=mac, cache_timeout=miflora_cache_timeout, retries=3, adapter=used_adapter)
TypeError: init() missing 1 required positional argument: 'backend'

ESP-32 port ?

Hi,

Sure not the goal of you tool, but have you considered porting it to ESP32 ? Would be nice when Pi is too far from Miflora.

Add Custom Property fo MQTT Message

Hello,

is it possible to add a custom property like "Watering Duration" to the mqtt message? I would like to set a specific watering duration per sensor in the config file and add this watering duration to the mqtt messages.

Thanks

Frank

Mi Kettle - We maybe also can find a way to get data from the MiKettle

#Now MiKettle gets detected! (Xiomi Waterkettle)

Hey to Day I had to Fix something on the mqtt Deamon and suddenly My MiKettle was detected as a Bluetooth Device while running "lescan".

I tried to conected but the MAC is restricted via:
if not re.match("C4:7C:8D:[0-9A-F]{2}:[0-9A-F]{2}:[0-9A-F]{2}", mac):

so that did not work.
The Kettle uses Bluetooth as well and probably works similar to the flora sensors so at least the Water temp should be possible to fetch right?
Any Idea how to Check if this could also work?

bildschirmfoto 2018-02-09 um 22 29 09

1200x800

Not able to get systemd service working

Hi,

first I want to thank you for this great tool. Basically I could make my miflora sensor working.
Now I want to make the systemd service working but got problems.
I installed the service as written in the github documentation:

sudo cp /opt/miflora-mqtt-daemon/template.service /etc/systemd/system/miflora.service
sudo systemctl daemon-reload
sudo systemctl start miflora.service

But then the terminal shows:

Job for miflora.service failed because the control process exited with error code.
See "systemctl status miflora.service" and "journalctl -xe" for details.

If I run systemctl status miflora.service it tells me:

miflora.service - Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
Loaded: loaded (/etc/systemd/system/miflora.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Tue 2018-08-14 11:15:15 CEST; 19min ago
Docs: https://github.com/ThomDietrich/miflora-mqtt-daemon
Process: 27488 ExecStart=/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py (code=exited, status=1/FAILURE)
Main PID: 27488 (code=exited, status=1/FAILURE)

Aug 14 11:15:15 openHABianPi systemd[1]: Failed to start Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon.
Aug 14 11:15:15 openHAB systemd[1]: miflora.service: Unit entered failed state.
Aug 14 11:15:15 openHAB systemd[1]: miflora.service: Failed with result 'exit-code'.
Aug 14 11:15:15 openHAB systemd[1]: miflora.service: Service hold-off time over, scheduling restart.
Aug 14 11:15:15 openHAB systemd[1]: Stopped Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon.
Aug 14 11:15:15 openHAB systemd[1]: miflora.service: Start request repeated too quickly.
Aug 14 11:15:15 openHAB systemd[1]: Failed to start Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon.
Aug 14 11:15:15 openHAB systemd[1]: miflora.service: Unit entered failed state.
Aug 14 11:15:15 openHAB systemd[1]: miflora.service: Failed with result 'exit-code'.`

What I am missing?

Thanks a lot for any help!

Exception when running miflora-mqtt-daemon.py

[21:02:34] root@smarthome:/opt/miflora-mqtt-daemon# python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py

Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
Source: https://github.com/ThomDietrich/miflora-mqtt-daemon

[2019-01-15 21:02:47] Connecting to MQTT broker ...
Adding sensor to device list and testing connection ...
Name:          "Flowercare"
Internal name: "Flowercare"
Device name:   "Flower care"
MAC address:   C4:7C:XX:XX:XX:XX
Firmware:      2.7.0
[2019-01-15 21:02:52] Initial connection to Mi Flora sensor "Flowercare" (C4:7C:8D:67:58:3B) successful

[2019-01-15 21:02:52] Announcing Mi Flora devices to MQTT broker for auto-discovery ...
Traceback (most recent call last):
  File "/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py", line 251, in <module>
    mqtt_client.publish('{}/$announce'.format(base_topic), json.dumps(flores_info), retain=True)
  File "/usr/local/lib/python3.5/dist-packages/paho/mqtt/client.py", line 1057, in publish
    raise ValueError('Publish topic cannot contain wildcards.')
ValueError: Publish topic cannot contain wildcards.

I've commented in base_topic = mqttjson to get it into OpenHAB items.
running the script with this line commented out it works perfect, but the OpenHAB items never get updated.
Can someone help?

New miflora device does not work

I just bought some miflora sensors from aliexpress i did buy 6 sensors but 2 of them don't work.
I can connect to them with gatttool and pull the values from them.

Id Version Data
7  2.7.0   64 15 32 2e 37 2e 30
8  2.7.0   64 15 32 2e 37 2e 30
9  3.2.1   64 2a 33 2e 32 2e 31
10 ?.?.?   64 13 32 2e 36 2e 35
11 3.2.1   64 2a 33 2e 32 2e 31
12 ?.?.?   64 13 32 2e 36 2e 35

If i decoded the data correctly they run version 2.6.5
Both 10 and 12 are the ones that don't work.

Id  Field Data
10  0x38  64 13 32 2e 36 2e 35
10  0x03  46 6c 6f 77 65 72 20 63 61 72 65
10  0x35  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
10  0x33  00 00
12  0x38  64 13 32 2e 36 2e 35
12  0x03  46 6c 6f 77 65 72 20 63 61 72 65
12  0x35  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
12  0x33  00 00

Is there someway to set the logging level to see exactly what goes wrong?
I found the following app https://play.google.com/store/apps/details?id=com.huahuacaocao.flowercare that might allow me to upgrade, but do we know to what version and if it will still work with this software?

"NULL" values in openhab2

First of all, I think your work as awesome and I would like to say thanks for all your effort.

I'm trying to get the deamon running with openhab2. I'm using Mosquitto and everything seems to be working fine, except for the openhab side.
I've already subscribed to my Mosquitto broker with a external MQTT client (MQTTlens) and I can see the messages coming in perfectly fine.
Also I can see openhab connect to the broker:
New client connected from ::1 as be50527e-cf77-4ddb-b94b-30057bdcbeca (c1, k60, u'openhabian').

However when I try to define a dummy component in HABPanel, it keeps saying "NULL".

My configurations for the mqtt binding and openhab are as follows:

services/mqtt.cfg:

mosquitto.url=tcp://127.0.0.1:1883
mosquitto.user=openhabian
mosquitto.pwd=xxx
mosquitto.qos=1
mosquitto.retain=true
mosquitto.async=false

items/miflora.items:

Group gMiFlora "All Mi Flora sensors and elements" (gAll)
Group gLightIntensity "Mi Flora Sunlight Intensity elements" (gAll, gMiFlora)
Group gAirTemperature "Mi Flora Air Temperature elements" (gAll, gMiFlora)
Group gSoilMoisture "Mi Flora Soil Moisture elements" (gAll, gMiFlora)
Group gSoilConductivity "Mi Flora Soil Conductivity/Fertility elements" (gAll, gMiFlora)
Group gBattery "Mi Flora Sensor Battery Level elements" (gAll, gMiFlora)

// Mi Flora "Groot" (C4:7C:8D:65:C1:AA)
Group gGroot "Mi Flora Sensor Groot" (gMiFlora)
Number Groot_LightIntensity "Groot Sunlight Intensity [%d lux]" <text> (gGroot, gLightIntensity) {mqtt="<[mosquitto:miflora/Groot:state:JSONPATH($.light)]"}
Number Groot_AirTemperature "Groot Air Temperature [%.1f °C]" <text> (gGroot, gAirTemperature) {mqtt="<[mosquitto:miflora/Groot:state:JSONPATH($.temperature)]"}
Number Groot_SoilMoisture "Groot Soil Moisture [%d %%]" <text> (gGroot, gSoilMoisture) {mqtt="<[mosquitto:miflora/Groot:state:JSONPATH($.moisture)]"}
Number Groot_SoilConductivity "Groot Soil Conductivity/Fertility [%d µS/cm]" <text> (gGroot, gSoilConductivity) {mqtt="<[mosquitto:miflora/Groot:state:JSONPATH($.conductivity)]"}
Number Groot_Battery "Groot Sensor Battery Level [%d %%]" <text> (gGroot, gBattery) {mqtt="<[mosquitto:miflora/Groot:state:JSONPATH($.battery)]"}

Any suggestions?

Thanks in advance!

Use systemd status for a summary

Currently the status is used to present the last noteworthy action.
Let's replaced or extended it by a summary of all sensors and the success rates.

Feel free to add your thoughts ;)

Stuck sensor

Happend 3 times now, random sensor get stuck. Guess because of failed communication (like this?
basnijholt/miflora#48) and/or failed unpairing/disconnect. Restarting my Py helped. Anybody else?

not working with 3.1.8

I have juste receive lastest miflora with firmware 3.1.8 its seems not working with.

its ok for my olds 2.6.2

if you have any idee

thanks :)

Enhancement: Provide mqtt information if connection to sensor failed or failed to retrieve data fro sensor.

Hello,
Scenario:
MiFlora work for some time and returns data but battery goes off and data stop to flow.

Openhab display value last returned over mqtt. User newer knows that sensor is offline.

I would like to propose enhancement:
In the event of lost connectivity to the sensor or failure to retrieve data, deamon could returned either "N/A" or "connection lost" value in all measurements for lost sensor.

Do you think it would be possible ?

Thanks
Jarek

feature request: reporting_method=mqtt-smarthome

Me again ;)

Would be nice to have the reporting_method mqtt-smarthome - see https://github.com/mqtt-smarthome/mqtt-smarthome

Changes would include:

  • no $announce topics
  • default base topic: miflora/status
  • default publish retain
  • publishing on 4 topics instead of one, e.g. miflora/status/plant1/moisture, miflora/status/plant2/conductivity and so on. Payload following mqtt-smarthome architecture
  • publishing 1 on miflora/connected when the daemon starts, 2 when a bluetooth connection is established, 0 as last-will testament.

Would be willing to do this and send you a PR if you'd like to get one :)

Regards,
Sebastian

Openhab Specific

Just a suggestion, is to store the config under the script folder in openhab, that way we can easily edit(add new sensors) the file within Visual Studio.

For a OH beginner user the only thing he needs to do is to use the openhabian-config tool to add miflora, then open VS stusio(which they will be using anyway) and then add their sensors...

Currently you need to google where the config file is stored, then log in with putty, then edit your file nano instead of the nice VS editor(easily copy paste from the internet, search and replace....)

BTW did you guys see that the miflora now comes in different colours!

Changed value

In very rare cases the sensor get stuck and keep sending out the same values, this case could be picked up the daemon and warn the user that he needs to take out the battery to reset the sensor.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.