Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon

maybe this will help you:

Thanks, how should the config.ini file look like with the new inbuilt broker? I have now successfully created a miflora.things file and updated my miflora.itemsā€¦ So now I only need to be able to connect to the broker:

[2019-02-05 21:52:26] Connecting to MQTT broker ...
[2019-02-05 21:52:26] MQTT connection error. Please check your settings in the configuration file "config.ini"

Have you installed the addon ā€œEmbedded MQTT Brokerā€ (to be found under Misc) besides the MQTT binding?

1 Like

Thanks that did the trick, I will share my setup sometime next week when everything is working again.

It is a common fact that the physical bluetooth range of the miflora devices are not the bestā€¦ So to extend this my idea is to use a rpi zero. So does anyone has an image for this purpose, it seems overkill to install openhabian for this. (or is it possible to easily deactivate OH server somehow?)

The second thing is that the config.ini file is located on the OH master, and this should be updated to rpi zero slave every time the file are edited on the master, i.e every time you add a new sensor(so not super oftenā€¦).

By this strategy we will spam the MQTT broker with same sensor information, if the sensor are picked up the OH master as well as rpi zero slave, not a big issue but it could be avoided or? So can the slave subscribe to MQTT topic and check if the topic has same value as what is suppose to send just now? Or is this already implemented, that it only send messages if it has changed it value?

openHabian assembles a lot of things. Currently i am not using the script anymore because i use the 3rd Party Bluetooth binding with the mifloras. Anyhow i have range problem too as expected with bluetooth le.

I use some old Raspberry pi version 1 with a DietPi Image. DietPi is small and lightweight and the MiFlora script should run on a pi zero as well

This makes it hard to make a slave, because then miflora needs to be connected to the master only.

Do you have an image file for this? Or should we make one where it comes preinstalled with miflora and share it somewhere here?

Yeah, my approach is different, but you should be able to download a DietPi imange install it on a pi zero and trasfer some scripts from openHabian to the pi zero. i Think an onwn image is to much

Has someone manged to use a BlueGiga Adapter instead of a HCI Adapter? Currently i am struggeling at installing the pygatt library

Any hints?

Ok, slved the problem with pygatt. Just include it in the requirements.txt. Next step is then to change the BT BAckend in the script. Unfortunately the script is not working properly with two sensors and bluegiga adapters. Have to digg in it more deaply.

Hey guys,
having some issues getting updates on the miflora items in OH 2.4 with firmware 3.1.9.
I do get feedback on the command line

[2019-03-28 23:48:51] Retrieving data from sensor "sensor1" ...
[2019-03-28 23:48:51] Result: {"temperature": 19.6, "moisture": 15, "battery": 100, "conductivity": 131, "light": 14}
[2019-03-28 23:48:51] Publishing to MQTT topic "miflora/sensor1"

But when I add items to OH I donā€™t get the updatesā€¦
Thing:

Bridge mqtt:broker:mosquitto "Mosquitto" [ host="localhost", port=1883, secure=false, username="___", password="___", clientID="openhab" ] {
    Thing topic FicusBen "Ficus Benjamin"   {
        Channels:
            Type number : light         "Light Intensity"   [ stateTopic="miflora/sensor1", transformationPattern="JSONPATH:$.light" ]
            Type number : battery       "Battery Charge"    [ stateTopic="miflora/sensor1", transformationPattern="JSONPATH:$.battery" ]
            Type number : temperature   "Temperature"       [ stateTopic="miflora/sensor1", transformationPattern="JSONPATH:$.temperature" ]
            Type number : conductivity  "Soil Fertility"    [ stateTopic="miflora/sensor1", transformationPattern="JSONPATH:$.conductivity" ]
            Type number : moisture      "Soil Moisture"     [ stateTopic="miflora/sensor1", transformationPattern="JSONPATH:$.moisture" ]
    }
}

Item:

Number    Ficus_Moisture      "Soil Moisture Ficus [%d %%]"       <humidity>       { channel="mqtt:broker:mosquitto:FicusBen:moisture" }

The only thing log viewer throws out is this:

Link 'Ficus_Moisture-mqtt:broker:mosquitto:FicusBen:moisture' has been added.

ā€¦but thatā€™s it - no updates.

Any idea whatā€™s wrong here?

Edit: Solved it! Maybe this helps user openhabFan, too.
For the item I used the channel mqtt:broker:mosquitto:FicusBenjamin:moisture while it needed to be mqtt:topic:mosquitto:FicusBenjamin:moisture.
Works like a charm now :slight_smile:

Hi There,

has someone used the miflora deam with the homeassistant message format and the new mqtt binding?

I tried that and the binding discovered a lot of things. As i am nit familiar with the format my question is, if this is right that i get a thing in the inbox for each sensores channel (temperatur, moisture, ā€¦)

My expectation was one Thing with some channels

Thomas

Hi,

i have installed this wonderfull script, but I get no infos back in my openhab sitemap.
I use version 2.4 with the embedded broker. It works very well with my other mqtt things but not with miflora. I tested miflora on my server with mqtt-spy and it shows the desired data.

I hope someone can look at my configration files and find my error:
My mqtt-things file:

Bridge mqtt:broker:oh_embedded [ host="192.168.2.2", secure=false, clientID="openhab2" ]{
 
   Thing topic tomate "miflora" {
      Channels:
         Type number : light  "LichtintensitƤt"      [ stateTopic="miflora/Tomate", transformationPattern="JSONPATH:$.light" ]
         Type number : battery "Batterie"            [ stateTopic="miflora/Tomate", transformationPattern="JSONPATH:$.battery" ]
         Type number : temperature   "Temperature"   [ stateTopic="miflora/Tomate", transformationPattern="JSONPATH:$.temperature" ]
         Type number : conductivity  "Fruchtbarkeit" [ stateTopic="miflora/Tomate", transformationPattern="JSONPATH:$.conductivity" ]
         Type number : moisture      "Feuchtigkeit"  [ stateTopic="miflora/Tomate", transformationPattern="JSONPATH:$.moisture" ]
    }
}

My item-file:

Number:Illuminance      Miflora_Tomate_Light         "Licht IntensitƤt Tomate [%d lx]" <light>       { channel="mqtt:topic:oh_embedded:Tomate:light" }
Number:Dimensionless    Miflora_Tomate_Battery       "Batterie Stand [%d %%]"          <battery>     { channel="mqtt:topic:oh_embedded:Tomate:battery" }
Number:Temperature      Miflora_Tomate_Temperature   "Temperatur Tomate [%.1f Ā°C]"     <temperature> { channel="mqtt:topic:oh_embedded:Tomate:temperature" }
Number:Dimensionless    Miflora_Tomate_Moisture      "Bodenfeuchte Tomate [%d %%]"     <humidity>    { channel="mqtt:topic:oh_embedded:Tomate:moisture" }

and my sitemap-file:


    Frame label="Mi Flora" {
        Text item=Miflora_Tomate_Light label="Tomate Licht"
        Text item=Miflora_Tomate_Temperature label="Tomate Temperatur"
        Text item=Miflora_Tomate_Battery label="Tomate Batterie"
        Text item=Miflora_Tomate_Moisture label="Tomate Bodenfeuchte"
    }

Greetings Kaloschke

Hi @schnibel, did you restore your working configuration?
the same happened to me: all was working great since a couple of days starting from an openHABian+miflora daemon fresh install, but all of a sudden my RaPi started failing to connect to the sensor, I did not change anything with the configuration and code, or RaPi/sensor position.
The Xiaomi MiHome app connects fine, so I guess is not a problem with the sensor.

I cannot even scan devices anymore as the sudo hcitool lescan command fails (returns this error Set scan parameters failed: Connection timed out).
Did you solve your problem?
How?

I have the same issue. Works alright for a day or two, but then it doesnā€™t get updated and I canā€™t find the sensors with lescan.
Rebooting the RasPi, re-scanning and re-running the script brings everything back, but thatā€™s canā€™t be the solution.
Maybe it has something the do with new Openhab bluetooth driversā€¦?

I just bought a xiami flora moisture sensor.
So I wonā€™t nee the python stuff above, but could work with the bluetooth binding instead?
Would you mind sharing your items you use?
Thanks in advance.

Unfortunately i moved back from the bluetooth binding to the phyton scripts. May problem was taht my mifloras are spread all over the house and i did not get a stable dirtibuted bluetooth network to work.

@mancer
Check your ā€œdmesgā€ and ā€œmiflora.serviceā€ status.
In my case it is problem with RPi built-in BT.

[Sun Sep 15 12:44:45 2019] Bluetooth: hci0: Frame reassembly failed (-84)
[Sun Sep 15 12:44:45 2019] Bluetooth: hci0: Frame reassembly failed (-84)
[Sun Sep 15 12:44:45 2019] Bluetooth: hci0: Frame reassembly failed (-84)
Sep 17 17:12:15 openHABianPi miflora-mqtt-daemon.py[1018]: [2019-09-17 17:12:15] Failed to retrieve data from Mi Flora sensor
Sep 17 17:13:16 openHABianPi miflora-mqtt-daemon.py[1018]: [2019-09-17 17:13:16] Failed to retrieve data from Mi Flora sensor
Sep 17 17:19:16 openHABianPi miflora-mqtt-daemon.py[1018]: [2019-09-17 17:19:16] Failed to retrieve data from Mi Flora sensor
Sep 17 17:20:17 openHABianPi miflora-mqtt-daemon.py[1018]: [2019-09-17 17:20:17] Failed to retrieve data from Mi Flora sensor
Sep 17 17:26:18 openHABianPi miflora-mqtt-daemon.py[1018]: [2019-09-17 17:26:18] Failed to retrieve data from Mi Flora sensor
Sep 17 17:27:18 openHABianPi miflora-mqtt-daemon.py[1018]: [2019-09-17 17:27:18] Failed to retrieve data from Mi Flora sensor
Sep 17 17:33:19 openHABianPi miflora-mqtt-daemon.py[1018]: [2019-09-17 17:33:19] Failed to retrieve data from Mi Flora sensor
Sep 17 17:34:19 openHABianPi miflora-mqtt-daemon.py[1018]: [2019-09-17 17:34:19] Failed to retrieve data from Mi Flora sensor

Problem is described here:
https://github.com/raspberrypi/firmware/issues/1150

Solution, which I dindnā€™t try yet, is external USB BT adapter.

1 Like

Quick update for RPI4 Users.
My new RPI4 is under my desktop and closer to my Balcony and the various sensors (which Iā€™ve just replaced all the batteries in). Seemed like a good place to install the Daemon.

Good news is that following all the instructions above the install has worked fine and after matching up all the Mac address (so which I had recorded these the first time - hello OneNote!).

As the batteries have been replaced and paired back my iphone app they have updated to 3.19 and when checking the MQ server they are reporting all details correctly.

To note. Iā€™ve not yet done the integration back into OpenHab, however while using MQTT Explorer (the best MQTT client Iā€™ve found for working on this) all the data is there in JSON using the default settings of this script, so it should be no issue setting up the OpenHab side. I may even try the Homie interface as had have success with that on OpenHab Milestone 2.5.

Set this up on RaspiZero and connected to a couple of devices with no issue. Tried to run the script to create the items and it throws this error:

Generating openHAB items. Copy to your configuration and modify as needed...
Traceback (most recent call last):
  File "/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py", line 245, in <module>
    flores_to_openhab_items(flores, reporting_mode)
  File "/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py", line 113, in flores_to_openhab_items
    print('\n'.join(items))
UnicodeEncodeError: 'ascii' codec can't encode character '\xb0' in position 1006: ordinal not in range(128)