Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon

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)

I have recently bought one of these as well and getting the data through Bluetooth binding.does anybody know the unit of the different values provided by this device?
I mean moisture - is this percent (currently 41)?
How about fertility? What’s the maximum and the minimum value?
Thanks in advance

Temperatur is degree celsius. Humdidity is percent. Fertility is µs/cm, Sunlight i don’t know. And in addition i do not know the min and max values.

Alright!
Thanks a lot!

Got a batch of Bluetooth Sensors as well and wanted to connect them,
seems the Miflora MQTT Daemon is not compatible with Openhab 2.5 Embedded Moquette MQTT Broker, i get a

Broker doesn't permit MQTT empty client ID. Username: mqtt, channel

error
Seems unlike e.g. Mosquito Moquette doesnt generate ClientID’s when none is passed, and the Miflora MQTT Daemon is missing the config to set one, haven’t figured out yet how to include that

According to this post by @rlkoshak the internal mosquitto broker is not maintained at the moment and it is therefore suggested to use alternative external broker

I get the warning too, but it doesn’t matter. It’s just a hint and it still works.

Which version of the paho-mqtt package is installed?

Command to determine the version: pip3 show paho-mqtt

The 1.4.0 should be installed.

@Lionello_Marrelli Thanks for pointing that out, i wasn’t aware of that,
seems all the components i want to utilize are either abandonen, experimental or broken, would be great if something like that would also be indicated in the documentation…

@mas for me it doesnt seem to work, i don’t get any data from the Miflora Daemon into OH, my milight bridge works though without issue.
the pip3 show paho-mqtt
doesnt show anything for me, it runs a couple seconds but doesnt serve a result…
Note, i got all components on the same Raspbian installation running, don’t know if that makes a difference

I tried “teaching” the MQTT Daemon to transmit a clientID, but didnt have any luck yet, never worked with python before…