Mi Flora plant sensor
Step-by-step how-to guide install the Mi Flora plant sensor on a Raspberry Pi 4, with the latest Raspbian Buster image and Domoticz.
For this how-to we will be using our highly regarded Python Plugin Manager. In case you have not installed this yet, take a look at the prerequisites, you will find a link to the related how-to to install this.
Please be aware that when you buy your Flower Mate from China, you need to buy the International model and NOT the Chinese/Asian model!
There are also reports that Xiaomi would or could be bricking these devices using the native Flower Care app. Personally I do not have experienced these issues, but just to be safe:
You don’t need the Flower Mate app to get this device working with Domoticz!!!
This how-to is part of a bigger series of Domoticz how-to’s on sancla.com!
This tutorial has been verified with:
Domoticz 2020.1
Python Plugin Manager version 1.5.1
The Mi Flower Mate plugin version 1.0.0
Prerequisites
- Running Domoticz installation with stable Raspbian Buster release and SSH access. See my previous post for a how-to:
https://sancla.com/domoticz/raspberry-pi-4-with-domoticz/ - Domoticz Python Plugin Manager installed:
https://sancla.com/domoticz/how-to-domoticz-and-python-plugin-manager/
Tested with
- Raspberry Pi 4 (MEM 2GB with 16GB sd-card)
- Raspbian Buster Lite 4.19, Februari 2020
- Domoticz Stable 2020.1 (compile date 22-3-2020)
- Domoticz Python plugin manager dated March 29, 2020
Step 1: Install the Bluepy library
Before we can install the plugin we need to install the bluepy library. This library enables Python to talk to Bluetooth devices under Linux. Without this library, the plugin can’t talk to your Flower Mate. Start by connecting with SSH to your Domoticz installation and run the following commands:
sudo apt-get install python3-pip libglib2.0-dev -y
sudo pip3 install bluepy
Step 2: Install the Mi Flower Mate Plugin
Next is to install the Mi Flower Mate Plugin with the Python Plugin Manager (PP-Manager). Add a new hardware device under Domoticz and use the following settings to create the hardware device (and activate the plugin):
- Enabled: Enabled
- Name: PP-Mi Flower Mate
- Type: Python Plugin Manager
- Data Timeout: Disabled
- Plugin to install: Xiaomi Mi Flower Mate
- Auto Update: All (NotifyOnly)
- Security Scan: False
- Debug: False
Reboot Domoticz once you have installed the new hardware device, to load the plugin within Domoticz. You can reboot Domoticz from the webinterface menu: Setup -> More Options -> Restart System.
Or with SSH: sudo reboot
The next step is to add the Xiaomi Mi Flower Mate hardware device, after the plugin has been activated.
Use the following settings:
- Enabled: Enabled
- Name: Mi Flower Mate
- Type: Xiaomi Mi Flower Mate
- Data Timeout: Disabled
- Device selection: Automatic *
Once a Flower Mate device is found, it will automatically add the found sensors to Domoticz:
* Device selection
For the device selection you can also add the devices manually. This is especially useful if you have multiple devices or if you have ‘interference’ from the flower mate of your neighbor(s).
If you are using the manual option, scan for your Flower Mates to find their mac-addresses by entering this command into a terminal:
sudo hcitool lescan
Let it run for a while (or for the inpatient ones, whip out the battery from the flower mate and put it back in). After a while, bluetooth devices in the area will start to show up. Look for found devices named “Flower care” or similar.
Step 3: Enabling the device in Domoticz
Once you have acquired your Flower Mate device in Domoticz, automatically or manually, you need to enable the device in order to receive updates. This is done this way as this enables the plugin to actively pull an update from the Mi Flower Mate device. But only once, not continuously (by design to save power and put you in control).
Step 4: Automatically update the sensors
However, as great as it is to manually update the sensors every time, automatically updating your Mi Flower Mate sensors would be even better. Luckily, we can do this very easily under Domoticz, thanks to the design choices the developer made.
I present you 2 different options:
- Option A: Using a device timer
- Option B: Using a Blockly script
Option A: Create device timers
The easiest way to automatically trigger an update of the sensors is to enable the devices and enable a timer for this device. After you enabled all the Mi Flower Mate devices, look for it under the Switches tab in Domoticz.
Then click on the “Timers” button to configure the timer:
On of the nice things of working with timers is that you can add multiple timers. In this example I created 4 timers, to the sensors receives an update every 6 hours.
Keep in mind that the more frequent you pull an update from your Mi Flower Mate, the worse the energy consumption will be and the faster the battery will be drained!
Option B: Create a Blockly script
In this example I created a fairly easy to duplicate Blockly script to update the sensors daily. There are others ways to script this, even better with LUA, Python or dzVents scripts. But this example should give you a fairly good start with Blockly. Keep in mind that the more frequent you pull an update from your Mi Flower Mate, the worse the energy consumption will be and the faster the battery will be empty!
Don’t forget:
- Save your script!
- Enable the “update Mi Flowermates” device under Devices!
Chris
Hi, I followed your guide. Worked perfectly the first few days. Then a lot of errors are coming by.
For example, I see the error “PP-Mi Flower Mate hardware (21) thread seems to have ended unexpectedly”. coming by every 2 minutes today. Although the Flower mate has been updated also within Domoticz today. I do not see why I keep getting this message
SANCLA
Hi Chris,
Could be a performance issue but it probably does not hurt. Try to poll less frequently and see if that helps.
I think there is some kind of heartbeat function in Domoticz that frequently checks hardware devices. Although this is a plugin, it presents itself as a hardware device. If the plugin does not respond fast enough (or not at all) you get this error.
Davy Heuts
Thanks a lot for this manual, great! Unfortunately I can’t get it working. I get the error: “Poller error”. Using Domoticz v2020.1 on a Raspberry Pi 4 with Buster. Any ideas?
SANCLA
Hi Davy,
I just verified this tutorial with the latest and greatest, but I cant replicate your error.
Can you manually update the sensors with problems?
Davy Heuts
Thanks a lot! The sensors are generated in Domoticz by the script, but they stay at 0. How to manually edit them?
SANCLA
Hi Davy
See “Step 3: Enabling the device in Domoticz”.
Press the red device button and wait a few seconds…
Davy Heuts
Yes, that is the moment I get the “Poller error”.
SANCLA
Well, there is still the possibility that your plant sensor lost connection.
Battery, distance, interference, to name a few.
Can you see the sensor with a manual scan from the terminal/SSH?
sudo hcitool lescan
You can also try to remove and add the device again, maybe that could help…
Davy Heuts
Hi, Thanks for the fast reply.
Yes, I can see one of them it in The hcitool lescan. I removed all devices and leaved it on Automatic after manual after reinstalling. Now the one most next to my Raspberry is working fine! Thanks a lot!
SANCLA
Glad I could be of help to you!
fidoboulettes
Hi,
thanks a lot for your work.
I’m sorry for my poor english, i’m french and don’t speak it very well (lot of gramatical mistake).
I have two problem.
first, i would like a measure of my plant monitor every half an hour… The most simple thing for me is to use crontab… is it possible? And if yes, wich file do i use in the crontab?
Second, the unit of measure the soil humidity is the cb (centibar) in your file but its a mistake…. In my experience, when i’ve used jeedom (french domotique platform) or if i connect my phone with the xiaomi-android app, the unit mesure is percent (%). How can I modify it (in domoticz or in the plugin) it?
Thanks a lot for yours answer
Best regard
SANCLA
Hi fidoboulettes,
Regarding the polling frequency, I am not familiar with combining the plugin with contrab.
Although, perhaps with a custom script, it can be done.
However, since it’s a Domoticz plugin, I would advise you to automate this in Domoticz, u can use timers or scripting for that.
Regarding the measurement units, what you could do is to ask the developers if it would be possible to integrate this into the plugin.
Perhaps give you the option to choose for yourself.
But you have to ask this on the corresponding Github page of the developers:
https://github.com/flatsiedatsie/Mi_Flower_mate_plugin/issues
Or just rewrite the code yourself and send them a pull request…
Cheers!
fidoboulettes
Hi Sancla,
I’ve used the option A and it’s work well.
Thanks again for your blog
tonbor
This is the way to change cb to %
here is de wrong code part in plugin.py in the mi flora script directory
sensorName = sensorBaseName + “Moisture”
Domoticz.Debug(“Creating first sensor, #”+str(sensorNumber))
Domoticz.Debug(“Creating first sensor, name: “+str(sensorName))
Domoticz.Device(Name=sensorName, Unit=sensorNumber, TypeName=”Soil Moisture”, Used=1).Create()
Domoticz.Log(“Created device: “+Devices[sensorNumber].Name)
Change
Domoticz.Device(Name=sensorName, Unit=sensorNumber, TypeName=”Soil Moisture”, Used=1).Create()
In
Domoticz.Device(Name=sensorName, Unit=sensorNumber, TypeName=”Percentage”, Used=1).Create()
Of you allready active the plugin you have to remote it and, active ut again
SANCLA
Hi Tonbor,
Amazing!
Would it be okay for you if I suggest your changes to the developer?
Peter Calum
Hi,
I have installed the PP plugin ok in Domoticz on a raspberry 3, but the Sensor under devices does not show up. It seems thhat the sensor cant connect to Raspberry Pi.
sudo hcitool lescan
LE Scan …
C4:7C:8D:6B:99:1D (unknown)
C4:7C:8D:6B:99:1D Flower care
sudo bluetoothctl
Agent registered
[bluetooth]# trust C4:7C:8D:6B:99:1D
Changing C4:7C:8D:6B:99:1D trust succeeded
[bluetooth]# pair C4:7C:8D:6B:99:1D
Attempting to pair with C4:7C:8D:6B:99:1D
[CHG] Device C4:7C:8D:6B:99:1D Connected: yes
Failed to pair: org.bluez.Error.AuthenticationFailed
[CHG] Device C4:7C:8D:6B:99:1D Connected: no
Anyone seen this error ??
Henk
Hi, I have installed as described and everything seems fine in domoticz but…. the sensors are nor reading data, the push button does not trigger this. In my Domoticz log I get: ‘Mi flower mate hardware (55) thread seems to have ended unexpectedly”. The Mi flower mate is within 50cm of my raspberry 4. anyone?