Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon

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: https://github.com/ThomDietrich/miflora-mqtt-daemon/issues/16

1 Like

One of my miflora is down to 19% now! I bought it 26/10/2016 add 3 weeks for shipping from china, and we probably end up with 1.5-1.8 years of battery time at 20C

One thing @ThomDietrich I would like to mentioned what I recently implemented lately is this:
Number Miflora_Sensor4_Moisture “Sensor4 Soil Moisture [%d %%]” <text> (gMiflora, Group_Moisture,Group_Moisture_LivingRoom) {mqtt="<[mosquitto:miflora/sensor4:state:JSONPATH($.moisture)]", expire=“1h” }

Which will tell me if i have not got an update from my sensor in the last hour! Works like a charm.

Also I know that the py script says something about signal strength, maybe we could also forward this info to the broker? And finally I were wondering if you do check if the sensor have changed its value(any of the 4 value it reports) from last reading or not, if it hasn’t the sensor needs to be reset.

1 Like

Wow, that’s impressive: One and a half year out of that tiny battery.
Thanks @skatun for coming back on this!

btw.: How often are you querying your sensors? Is it on the five minute default or have you set a longer interval?

… would be really appreciated too :wink:

That’s some good and interesting news! Could you please file issues for all of them?

  1. Add the battery time to the readme
  2. Add expire to the openHAB generation function
  3. Add signal info to MQTT messages
  4. The changed value question. I’m not sure about the answer.
1 Like

@ThomDietrich I Will file those issues, a bit busy these days due to Olympics :slight_smile:
also
5. Possibility to Overide default polling interval for each sensor.

See this link for more info:

In generally the connection miflora -> RasPi3 -> WLAN -> mqtt-broker -> OpenHAB works for me.
Credentials are correct.
But only ~3-4 packages per day are reaching the broker.

“sudo hcitool lescan” lists a lot of Bluetoothdevices but nearly never the miflora sensor.

It’s not a problem of distance to the sensor.

And sometimes there ar Input/output errors:

[17:35:26] openhabian@ohdata:~$ sudo hcitool lescan
LE Scan …
7E:3E:3E:BC:E4:26 (unknown)
7E:3E:3E:BC:E4:26 (unknown)
49:B0:2C:E1:20:FA (unknown)
49:B0:2C:E1:20:FA (unknown)
48:23:56:6A:0C:F6 (unknown)
48:23:56:6A:0C:F6 (unknown)
6D:E5:81:C7:4D:CC (unknown)
6D:E5:81:C7:4D:CC (unknown)
73:AD:22:D4:1A:D9 (unknown)
73:AD:22:D4:1A:D9 (unknown)
74:D3:40:03:46:E6 (unknown)
74:D3:40:03:46:E6 (unknown)
24:4B:03:F6:E9:F4 (unknown)
E9:74:90:A2:9D:3C SM-9D3C
E9:74:90:A2:9D:3C (unknown)
4C:64:F0:04:61:82 (unknown)
^C[17:35:28] openhabian@ohdata:~$ sudo hcitool lescan
Set scan parameters failed: Input/output error
[17:35:28] openhabian@ohdata:~$ sudo hcitool lescan
Set scan parameters failed: Input/output error
[17:35:30] openhabian@ohdata:~$ sudo hcitool lescan
Set scan parameters failed: Input/output error
[17:35:30] openhabian@ohdata:~$ sudo hcitool lescan
Set scan parameters failed: Input/output error
[17:35:31] openhabian@ohdata:~$

I’m using a new Raspi3 with clean openhabian-install and nothing else.

Is there a way to block all the unwanted MAC-adresses?

(The miflora/$announce message works nearly every 5 minutes)

Hello, just to let you know, I tried to install the Daemon directly from openhabian, with the optional component installation, but it didn’t work (something wrong with the colorama module in python).
for more details, see below

Thank you

HI all,

the miflora service stopped working with the upgrade to openhabian 2.3 any idea what to do?

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-31 22:24:00] Connecting to MQTT broker ...
[2018-05-31 22:24:00] MQTT connection established

Adding sensor to device list and testing connection ...
Name:          "Glueckskastanie"

and

sudo systemctl status miflora.service 
● miflora.service - Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
   Loaded: loaded (/etc/systemd/system/miflora.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2018-05-31 22:25:41 CEST; 2s ago
     Docs: https://github.com/ThomDietrich/miflora-mqtt-daemon
 Main PID: 22458 (python3)
   Status: "May 31 22:25:40 - MQTT connection established."
   CGroup: /system.slice/miflora.service
           ├─ 3467 gatttool --device=C4:7C:8D:66:44:DB --char-read -a 0x38 --adapter=hci0
           ├─22458 python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py
           ├─22467 /bin/sh -c gatttool --device=C4:7C:8D:66:44:D5 --char-read -a 0x38 --adapter=hci0
           └─22468 gatttool --device=C4:7C:8D:66:44:D5 --char-read -a 0x38 --adapter=hci0

May 31 22:25:40 openHABianPi systemd[1]: Starting Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon...
May 31 22:25:41 openHABianPi systemd[1]: Started Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon.

Excited to get this up and going. Want to use it in our greenhouse. Will be quite awesome to keep track of the state of our seedlings. I have two that I have used for some time on the android app but want to integrate into openhab. Having issues right off the bat though.

I’m on OH2.3 and raspi. Installed Bluez per the instructions. Checked I have version 5.43 running. When I run

sudo hcitool lescan

I get Set scan parameters failed: Input/output error. Did some reading but could not overcome that. Found an article here that uses the bluetoothctl to search for bluetooth. That worked in a sense. It finds the controller and says searching but never finds the sensor even though its right by the raspi. I have connect the sensor to my phone and it has the latest version of the plant care software running on it.

Thoughts on how to get them connected? Sounds like most people on here it just connects.

thanks!

Just be aware that the light detection freaks out if placed outside in sunshine…

Same problem here after the upgrade to 2.3… Before it worked so this must be a problem of the new version…

Hmm interestingly it works again today! I did not do anything… and the hcitool lescan works as well… maaagic! :slight_smile:

Unfortunately my status does not show how many missed connection retries have been going on:

sudo systemctl status miflora.service
[sudo] password for openhabian:
● miflora.service - Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
Loaded: loaded (/etc/systemd/system/miflora.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2018-06-02 00:34:49 CEST; 25s ago
Docs: https://github.com/ThomDietrich/miflora-mqtt-daemon
Main PID: 5265 (python3)
Status: “Jun 02 00:34:48 - MQTT connection established.”
CGroup: /system.slice/miflora.service
└─5265 python3 /opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py

Jun 02 00:34:48 openHABianPi systemd[1]: miflora.service: Service hold-off time over, scheduling restart.
Jun 02 00:34:48 openHABianPi systemd[1]: Stopped Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon.
Jun 02 00:34:48 openHABianPi systemd[1]: Starting Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon…
Jun 02 00:34:49 openHABianPi systemd[1]: Started Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon.

Any idea how I could get them? I cannot know at the moment wether the sensor is connected or not… :confused:

No one? :frowning:

I think that’s not possible at the moment, but a feature request was already submitted for that:

But I saw somewhere in old posts that they could see the connection quality. Was that taken out again?
It`s very hard for me to currently find out why it would not work through a window. It did sometimes and then all of a sudden it does not again?! Any idea?

What kind of window do you have. I am moving from the miflora daemon to the Bluetooth binding from @vkolotov and while this i regocnized that the sensore on our veranda are nearly never reached. In the blutooth diskussion some other people have the same problem. Modern Windows …

Good question, I guess they are 10 years old… the other sensor ist through one thick wall of concrete, direct distance lets say 6 meters?

What benefits do you have by moving to the bluetooth binding?

If your windows are about 10 years old, then they are maybe the problem.

There is no particular reason to move to the bluetooth binding except from tha fact that the bluetooth binding does not only recognise the miflora sensors

1 Like

Hey guys…

I am still not able to connect one of my flora sensors… when i search via the hcitool i found booth of them…
I also stand the “problem” sensor in front of my PI…no connection possible…any ideas?

[13:39:44] 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-07-02 13:39:45] Connecting to MQTT broker ...
[2018-07-02 13:39:45] MQTT connection established

Adding sensor to device list and testing connection ...
Name:          "Spathiphyllum"
connect: Device or resource busy (16)
connect: Device or resource busy (16)
[2018-07-02 13:40:56] Initial connection to Mi Flora sensor "Spathiphyllum" (C4:7C:8D:65:DE:85) failed.

Adding sensor to device list and testing connection ...
Name:          "Begonia_Corallina"
Internal name: "Begonia_Corallina"
Device name:   "Flower care"
MAC address:   C4:7C:8D:65:DE:9F
Firmware:      3.1.8
[2018-07-02 13:41:02] Initial connection to Mi Flora sensor "Begonia_Corallina" (C4:7C:8D:65:DE:9F) successful

[2018-07-02 13:41:02] Announcing Mi Flora devices to MQTT broker for auto-discovery ...

[2018-07-02 13:41:02] Retrieving data from sensor "Spathiphyllum" ...
connect: Device or resource busy (16)
connect: Device or resource busy (16)
connect: Device or resource busy (16)
[2018-07-02 13:41:52] Retrying ...
connect: Device or resource busy (16)

Another try…

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

[2018-07-02 13:45:38] Connecting to MQTT broker ...
[2018-07-02 13:45:38] MQTT connection established

Adding sensor to device list and testing connection ...
Name:          "Spathiphyllum"
[2018-07-02 13:47:30] Initial connection to Mi Flora sensor "Spathiphyllum" (C4:7C:8D:65:DE:85) failed.

Adding sensor to device list and testing connection ...
Name:          "Begonia_Corallina"
Characteristic value/descriptor read failed: Internal application error: I/O
connect error: Transport endpoint is not connected (107)
Internal name: "Begonia_Corallina"
Device name:   "Flower care"
MAC address:   C4:7C:8D:65:DE:9F
Firmware:      3.1.8
[2018-07-02 13:48:32] Initial connection to Mi Flora sensor "Begonia_Corallina" (C4:7C:8D:65:DE:9F) successful

[2018-07-02 13:48:32] Announcing Mi Flora devices to MQTT broker for auto-discovery ...

[2018-07-02 13:48:33] Retrieving data from sensor "Spathiphyllum" ...
[2018-07-02 13:50:23] Retrying ...
[2018-07-02 13:52:13] Failed to retrieve data from Mi Flora sensor "Spathiphyllum" (C4:7C:8D:65:DE:85), success rate: 0%

[2018-07-02 13:52:13] Retrieving data from sensor "Begonia_Corallina" ...
[2018-07-02 13:52:17] Result: {"light": 987, "temperature": 23.9, "moisture": 28, "conductivity": 324, "battery": 99}
[2018-07-02 13:52:17] Publishing to MQTT topic "miflora/Begonia_Corallina"

[2018-07-02 13:52:18] Sleeping (300 seconds) ...

[2018-07-02 13:57:18] Retrieving data from sensor "Spathiphyllum" ...

Hi guys,
thanks for the great work. I got everything working except the daemon. I get the following error:

pi@raspberrypi:~ $ sudo systemctl start miflora.service
Job for miflora.service failed because the control process exited with error code.
See "systemctl status miflora.service" and "journalctl -xe" for details.
pi@raspberrypi:~ $ sudo systemctl status miflora.service
● miflora.service - Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon
   Loaded: loaded (/etc/systemd/system/miflora.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Sun 2018-07-08 15:34:49 UTC; 3s ago
     Docs: https://github.com/ThomDietrich/miflora-mqtt-daemon
  Process: 912 ExecStart=/opt/miflora-mqtt-daemon/miflora-mqtt-daemon.py (code=exited, status=203/EXEC)
 Main PID: 912 (code=exited, status=203/EXEC)

Jul 08 15:34:48 raspberrypi systemd[1]: miflora.service: Unit entered failed state.
Jul 08 15:34:48 raspberrypi systemd[1]: miflora.service: Failed with result 'exit-code'.
Jul 08 15:34:49 raspberrypi systemd[1]: miflora.service: Service hold-off time over, scheduling restart.
Jul 08 15:34:49 raspberrypi systemd[1]: Stopped Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon.
Jul 08 15:34:49 raspberrypi systemd[1]: miflora.service: Start request repeated too quickly.
Jul 08 15:34:49 raspberrypi systemd[1]: Failed to start Xiaomi Mi Flora Plant Sensor MQTT Client/Daemon.
Jul 08 15:34:49 raspberrypi systemd[1]: miflora.service: Unit entered failed state.
Jul 08 15:34:49 raspberrypi systemd[1]: miflora.service: Failed with result 'exit-code'.

config.ini has enabled the daemon. I have a Rasperry Zero W.
Can someone help to get the script started as service?
My Linux knowledge is unfortunately very limited.
Thanks,
Matthias