Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon

For the next version of the daemon it would be nice if we in the config file could define item specific update interval to override the global one:

I am trying to understand how this can be implemented in the pyton code:

        print('Internal name: "{}"'.format(name_clean))
        print('Device name:   "{}"'.format(flora_poller.name()))
        print('MAC address:   {}'.format(flora_poller._mac))
        print('Firmware:      {}'.format(flora_poller.firmware_version()))
        print('Update Interval:      {}'.format(flora_poller.Interval()))

All-

I found a way to use my other application (DV MEGA for amateur radio) using Raspbian. The scripts installed nicely reverting to that OS.

Many thanks,

-Mark

1 Like

Not sure why!? In general please report such an idea as a GitHub issue :wink:

My plant needs update interval of 600s, while my fridge needs update interval of 60s.(You want to make sure you get notified before you leave the flat that you forgot to close the door, rather than after. With 60s then I will notify the user if its been open for more than two measurements i.e 2-3 minuttes, with 600s this would have been 20-23minutes…). So instead of having the daemon spit out values for all 17 sensor at 60s, it would be awesome to define that the fridge differs from the default value.

I am just trying to reduce the load of the OH server.

I see.
Okay sounds reasonable, even though it’s imho a requirement only for users who “misuse” their sensors like you do. :smile: Could you please open an Issue? Also to be honest I’ll not have the time in the next few weeks. If you can look at the solution yourself, that would be great.

Think outside the box!!

I ran into some deep trouble with the “vim” editor after the

-> vim /opt/miflora-mqtt-daemon/config.ini <- Comand.

not Knowing there were a differents between “nano”, “vim” and other editors and How to Close or Save the File.

This Helped me (JiC Somone has the same beginner problem):

That’s why I never mention one specific editor. The choice is up to you!
(of course vim is the one and only mighty one but you can use others if you really need to :stuck_out_tongue_winking_eye:)

Random fun fact: The “How to exit the Vim editor?” question got some fame recently:

Hi @ThomDietrich,
many thanks for your your work! Had that sensor laying around for a year or so, Few days ago I gave it a try with your deamon: Worked at the first try - excellent job, excellent tutorial!

The range is much better than expected (one reinforced concrete floor between Mi Flora and the bluetooth interface!). So I’m quite happy with it.

Just two questions:
I’ve set the readings to one every 10 minutes. Up to now (running just few days), there is no battery drain reported (still at 100%). What are your experiences of the battery life?

How to check for retries/unsuccessful readings to get a feeling of the signal quality? Probably an idea to include the RSSI/error count/retry count or similar into the MQTT topics?

I did this but now…i got errors too :frowning:

[15:37:58] openhabian@openHABianPi:~$ nano /opt/miflora-mqtt-daemon/config.ini

  GNU nano 2.2.6     File: /opt/miflora-mqtt-daemon/config.ini                  

# Configuration file for Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
# Source: https://github.com/ThomDietrich/miflora-mqtt-daemon
#
# Uncomment and adapt all settings as needed.

[General]

# The operation mode of the program. Determines wether retrieved sensor data is$
# Currently supported:
#      mqtt-json - Publish to an mqtt broker, json encoded (Default)
#     mqtt-homie - Publish to an mqtt broker following the Homie MQTT conventio$
# mqtt-smarthome - Publish to an mqtt broker following the mqtt-smarthome propo$
#                  (https://github.com/mqtt-smarthome/mqtt-smarthome)
#           json - Print to stdout as json encoded string
reporting_method = mqtt-json

# The bluetooth adapter that should be used to connect to Mi Flora devices (De$
adapter = hci0

[Daemon]

# Enable or Disable an endless execution loop (Default: true)
enabled = true

# The period between two measurements in seconds (Default: 300)
period = 300

[MQTT]

# The hostname or IP address of the MQTT broker to connect to (Default: localh$
hostname = localhost

# The TCP port the MQTT broker is listening on. SSL/TLS currently not implemen$
port = 1883

# Maximum period in seconds between ping messages to the broker. (Default: 60)
keepalive = 60

# The MQTT base topic to publish all Mi Flora sensor data topics under.
# Default depends on the configured reporting_mode (mqtt-json, mqtt-smarthome:$
base_topic = miflora
#base_topic = homie

# Homie specific: The device ID for this daemon instance (Default: miflora-mqt$
homie_device_id = miflora-mqtt-daemon

# The MQTT broker authentification credentials (Default: no authentication)
#username = user
#password = pwd123

[Sensors]

# Add your Mi Flora sensors here. Each sensor consists of a name and a Etherne$
# Additional location information can be added to the name, delimited by an '@$
# Scan for sensors from the command line with:
#    $ sudo hcitool lescan
#
# Examples:
#
#Schefflera@Living = C4:7C:8D:11:22:33
#JapaneseBonsai    = C4:7C:8D:44:55:66
#Petunia@Balcony   = C4:7C:8D:77:88:99
Einblatt@Bedroom = C4:7C:8D:65:DE:85
Begonia Corallina@Büeo = C4:7C:8D:65:DE:9F


[15:45:54] openhabian@openHABianPi:~$ 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-02-15 15:45:59] Connecting to MQTT broker ...
[2018-02-15 15:45:59] MQTT connection error. Please check your settings in the configuration file "config.ini"

Hm at the first sight i do not see anything unusual. Maybe in this line

Begonia Corallina@Büeo = C4:7C:8D:65:DE:9F

the special german “ü” or the space is the problem

Used underscore for the space and office as “büro”…still the same error

OK, now i read the error message. Are you are using password and user in mqtt?

maybe a dump question but do i need to setup any other step besides the installation guide from thom?

Never did something with mqtt…so i need to install mqtt separately?

Yes a mqtt broker is needed. the miflora daemon collects the plant data and publishes it to a mqtt broker and to this mqtt broker openhab is connected.

In the openhabian image you will find a mqtt broker (mosquitto). If it is on the same host like the miflora daemon the localhost is ok. i am not sure about the default mqtt user that is installed in the openhabian package.

But thats the first step. Install mqtt

ok i think i got the mqtt broker working…

but when i try to load the item file it seems it is not working

2018-02-15 20:07:57.337 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'miflora.items'

2018-02-15 20:07:57.713 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'miflora.items'

2018-02-15 20:07:57.798 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'miflora.items'

2018-02-15 20:07:57.871 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH

2018-02-15 20:07:57.875 [WARN ] [.core.transform.TransformationHelper] - Cannot get service reference for transformation service of type JSONPATH

You need to install jsonpath transformation in paper ui

1 Like

I think it is going to come to an end :smiley:

Feb 15 20:25:44 openHABianPi miflora-mqtt-daemon.py[29266]: connect error: Transport endpoint is not connected (107)

Is there something wrong with my mqtt.config?

#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
miflora.url=tcp://localhost:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a random default is generated.
miflora.clientId=miflora

# Optional. True or false. If set to true, allows the use of clientId values
# up to 65535 characters long. Defaults to false.
# NOTE: clientId values longer than 23 characters may not be supported by all
# MQTT servers. Check the server documentation.
#<broker>.allowLongerClientIds=false

# Optional. User id to authenticate with the broker.
miflora.user=openhabian

# Optional. Password to authenticate with the broker.
miflora.pwd=testblabla

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.
#<broker>.qos=<qos>

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
#<broker>.retain=<retain>

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
#<broker>.async=<async>

# Optional. Defines the last will and testament that is sent when this client goes offline
# Format: topic:message:qos:retained <br/>
#<broker>.lwt=<last will definition>

Hi,

just to bring us in the same level. The broker ist in the middle and openhab and miflora are connecting to the broker. Based on this you need to understand that the mqtt binding establishes the connection between broker and openhab. If you restart openhab you should find some kind off connection message in the openhab log. Next part is then to connect miflora. It should be possible to use the same credentials as in opnehab. If you have success with that is shown within the miflora status.

To check if the broker is working you should use a tool like mqttspy. With this tool it is possible to establish ab connection to the broker and read all miflora readings.

Miflora ---- ------ Mqtt broker -------- openhab

So i think we should first check if the broker is running

Hey Carsten,

setting up and working with MQTT is out of the scope of the daemon documentation but you should find everything you need to first make sure MQTT is up and running here:

@curlyel happy you got it working right away. The battery information would certainly be something we can add. Please create a GitHub issue! The battery use is something I never looked at closely but I’ve been polling my sensors at home for quite some time now and they report 90-something percent. I wonder if those readings are correct. @skatun do you know more?
Regarding signal quality: Please check the output of sudo systemctl status miflora.service, also there is the idea to enhance this: Use systemd status for a summary · Issue #16 · ThomDietrich/miflora-mqtt-daemon · GitHub

1 Like