Python plugin: Xiaomi Mi Flower Mate

Python and python framework

Moderator: leecollings

tonbor
Posts: 153
Joined: Monday 17 February 2014 9:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by tonbor »

First accept new sensors as a default in settings. Second choose the plugin at the new hardware list.
NeoMod
Posts: 21
Joined: Friday 07 July 2017 22:02
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest β
Location: Italy
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by NeoMod »

corederoma82 wrote: Tuesday 19 June 2018 11:38 Hi,
after the installation of the script, how I add the sensor in the dashboard?

Thanks
Let me know how it works out for you.

For me, on Pi 3 B+ with latest Domoticz Beta, the plug-in never worked: the auto-scan feature failed to initialize (generic error code did not help troubleshooting the source problem) and BLE was not triggered properly.

Hence, the sensor (actually 4 dummy dashboard items for temp, hum, lux, and fertilizer) was never added to the dashboard.
Even after forcing “Manual Method” and adding the MiFlower MAC Address the plug-in showed errors while attempting a communication.
tonbor
Posts: 153
Joined: Monday 17 February 2014 9:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by tonbor »

The script Works perfectly, the plug-in is worthless. Does NOT work at alllllll :cry:
blauwebuis
Posts: 331
Joined: Wednesday 21 December 2016 9:11
Target OS: Raspberry Pi / ODroid
Domoticz version: current
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by blauwebuis »

For me the plugin works intermittently.

The problem is difficult to pinpoint.
- Was it a problem with too many devices being called at once? Well, I made it so that it only polls one device per heartbeat. But the problem remained.
- Was it a problem with the switch position? Well, I made it into a push-button now. But the problem remains.
- Is it a problem with the BluePy library? There are similar errors in the library's issue que on Github, but they don't seem to get fixed. One option is to switch to another bluetooth library. I tried to BluePy one because of it's simplicity to install, and it integrates well since it's built in python itself. An alternative option is the Bluez/GATT route, but when people have to (still after all this time) update to a new version of Bluez manually, meaning they have to compile it. This is how the manual script works.
- It could also be a problem with the Domoticz python framework. Python Plugins are not allowed to wait for things. And a plugin of this nature has to wait for the device to be found/communicated with. This could cause the time-out issue. But I simply don't know enough about how the plugin system works internally.
NeoMod
Posts: 21
Joined: Friday 07 July 2017 22:02
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest β
Location: Italy
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by NeoMod »

I don't know about the plug-in (as I said, for me has never worked) but for the other points:

- Try to use Bluez library: easy to install if you are on STRETCH (it's already on the debian repo, nothing more to do than a simple apt-get install bluez) or to manually compile otherwise. It's stable and don't create any problems.
- I have 6 bluetooth devices working fine so I don't thing it's a problem "how many devices" are you trying to pull data from.
- Python framework seems good to me: I'm using other plugins and they are working flawless. But also, I'm using a Python script to pull data from my Mi Flower devices and a simple cronjob to control the timing. So far so good.
tonbor
Posts: 153
Joined: Monday 17 February 2014 9:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by tonbor »

11 devices and no problem with the python script and Stretch.
mariuszwojciuk
Posts: 1
Joined: Monday 06 August 2018 23:54
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by mariuszwojciuk »

Frucoboti wrote: Thursday 17 May 2018 1:22 Hello,

I always get this error:

2018-05-17 01:15:59.613 User: Admin initiated a switch command (693/Huerto - Flip to update Mi Flowermates/Off)
2018-05-17 01:15:59.630 (Huerto) onCommand called for Unit 1: Parameter 'Off', Level: 0
2018-05-17 01:15:59.630 (Huerto) amount of Flower Mates to now ask for data: 1
2018-05-17 01:16:03.050 (Huerto) getting data from sensor: C4:7C:8D:66:14:E2
2018-05-17 01:16:03.058 Error: (Huerto) 'onHeartbeat' failed 'ImportError'.
2018-05-17 01:16:03.058 Error: (Huerto) ----> Line 247 in /home/pi/domoticz/plugins/Mi_Flower_mate_plugin-master/plugin.py, function onHeartbeat
2018-05-17 01:16:03.058 Error: (Huerto) ----> Line 99 in /home/pi/domoticz/plugins/Mi_Flower_mate_plugin-master/plugin.py, function onHeartbeat
2018-05-17 01:16:03.058 Error: (Huerto) ----> Line 154 in /home/pi/domoticz/plugins/Mi_Flower_mate_plugin-master/plugin.py, function getPlantData
2018-05-17 01:16:03.058 Error: (Huerto) ----> Line 103 in /home/pi/domoticz/plugins/Mi_Flower_mate_plugin-master/miflora/miflora_poller.py, function firmware_version
2018-05-17 01:16:03.058 Error: (Huerto) ----> Line 47 in /home/pi/domoticz/plugins/Mi_Flower_mate_plugin-master/miflora/backends/__init__.py, function __enter__
2018-05-17 01:16:03.058 Error: (Huerto) ----> Line 48 in /home/pi/domoticz/plugins/Mi_Flower_mate_plugin-master/miflora/backends/bluepy.py, function connect

This is on a Rasp3. Bluetooth from raspbian discovers the Mi Flora device, so I supose that Domoticz should discover it too.
I have tested with manual or automatic, with no luck.
When button is pressed turns virtual switch off, and get then the error.

Someone?
Workaround:
Change settings Flora Device from automatic to manual scan and at first device type macaddress of nearest device (i have first dev less than 1m).
for example: C4:7C:8D:XX:XX:XX,C4:7C:8D:XX:XX:XX,C4:7C:8D:XX:XX:XX
blauwebuis
Posts: 331
Joined: Wednesday 21 December 2016 9:11
Target OS: Raspberry Pi / ODroid
Domoticz version: current
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by blauwebuis »

Thanks Marius! That really seems to confirm that this is a timeout issue, and thus is more about the way that the plugin system works (plugins are not allowed to wait for anything).
manjh
Posts: 748
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by manjh »

I get a similar error, but it also dies after that:

Code: Select all

2018-08-23 17:29:16.900 (FlowerMate) Manual mode is selected
2018-08-23 17:29:16.291 Status: (FlowerMate) Started.
2018-08-23 17:29:16.886 Status: (FlowerMate) Entering work loop.
2018-08-23 17:29:16.887 Status: (FlowerMate) Initialized version 1.0.0, author 'blauwebuis'
2018-08-23 17:30:05.420 Status: User: Admin initiated a switch command (2630/FlowerMate - update Mi Flowermates/On)
2018-08-23 17:30:06.465 (FlowerMate) amount of Flower Mates to now ask for data: 1
2018-08-23 17:30:16.437 (FlowerMate) getting data from sensor: C4:7C:8D:66:D4:33
2018-08-23 17:30:57.388 Error: (FlowerMate) 'onHeartbeat' failed 'BTLEException'.
2018-08-23 17:30:57.388 Error: (FlowerMate) ----> Line 250 in '/home/pi/domoticz/plugins/Mi_Flower_mate_plugin/plugin.py, function onHeartbeat
2018-08-23 17:30:57.388 Error: (FlowerMate) ----> Line 102 in '/home/pi/domoticz/plugins/Mi_Flower_mate_plugin/plugin.py, function onHeartbeat
2018-08-23 17:30:57.388 Error: (FlowerMate) ----> Line 157 in '/home/pi/domoticz/plugins/Mi_Flower_mate_plugin/plugin.py, function getPlantData
2018-08-23 17:30:57.388 Error: (FlowerMate) ----> Line 103 in '/home/pi/domoticz/plugins/Mi_Flower_mate_plugin/miflora/miflora_poller.py, function firmware_version
2018-08-23 17:30:57.388 Error: (FlowerMate) ----> Line 47 in '/home/pi/domoticz/plugins/Mi_Flower_mate_plugin/miflora/backends/__init__.py, function __enter__
2018-08-23 17:30:57.388 Error: (FlowerMate) ----> Line 55 in '/home/pi/domoticz/plugins/Mi_Flower_mate_plugin/miflora/backends/bluepy.py, function connect
2018-08-23 17:30:57.388 Error: (FlowerMate) ----> Line 361 in '/usr/local/lib/python3.4/dist-packages/bluepy/btle.py, function __init__
2018-08-23 17:30:57.388 Error: (FlowerMate) ----> Line 410 in '/usr/local/lib/python3.4/dist-packages/bluepy/btle.py, function _connect
2018-08-23 17:31:06.910 (FlowerMate) getting data from sensor: C4:7C:8D:66:D4:33
2018-08-23 17:32:12.302 Error: FlowerMate hardware (10) thread seems to have ended unexpectedly
2018-08-23 17:32:26.305 Error: FlowerMate hardware (10) thread seems to have ended unexpectedly
2018-08-23 17:32:40.308 Error: FlowerMate hardware (10) thread seems to have ended unexpectedly
Hans
User avatar
dre68
Posts: 27
Joined: Friday 30 January 2015 20:18
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Noordwijk, Netherlands
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by dre68 »

madrian wrote: Monday 16 April 2018 19:58
blauwebuis wrote: Monday 16 April 2018 10:07 The button already works as a push button really. It just switches back to 'off' after it has scanned all the devices.
Thank you, I understand now.

"I built the plugin, and I now also get the BTLE exception error a lot. If it crashes if it can't find the flower sensor, then we might be able to fix that. Thanks for the tip."

This is my second question. One of my sensors is a little bit far away from my bluetooth receiver and sometimes it fails to read. In this case refresh button stays "on" and it's not possible to update anymore.

2018-04-16 19:51:04.991 User: Admin initiated a switch command (102/Xiaomi Flower Mate - Refresh/Off)
2018-04-16 19:51:04.991 MAIN SwitchLightInt : switchcmd=="On" || level < 0, new level:0

Please, add some more error handling and/or timeout function to the plugin.
Any progress on error handling? I really like this plugin, but I also have regular glitches in the script (probably not finding the sensor) which require a reboot to get functioning again.
PatrickM
Posts: 20
Joined: Wednesday 18 June 2014 15:59
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by PatrickM »

I'm very interested in this but can't make it run reliably either. After a couple of hours there's a bluetooth error and this breaks the domoticz python plugin system. I've modified the script to catch exceptions, updated miflora, attempt better error handling etc. to no avail. The way python support is implemented in domoticz simply doesn't handle one plugin misbehaving.

The same bluetooth issues occur when I run a pure python script on the command-line for a couple of hours. Bluetooth is usually broken after that (i.e. hcitool commands timeout) and needs either a reboot or manually restarting the bt subsystem, the behaviour is quite inconsistent though (sometimes hciconfig hci0 down; hciconfig hci0 up; fixes it, other times systemctl restart bluetooth, or it just starts working without any clear reason, etc).

I wonder if it is caused by the bluetooth dongle? I've a cheap chinese generic one. The Flower Care app on Android works very well so i doubt the issue is with the plant sensors.
manjh
Posts: 748
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by manjh »

PatrickM wrote: Tuesday 04 September 2018 12:00 I wonder if it is caused by the bluetooth dongle? I've a cheap chinese generic one. The Flower Care app on Android works very well so i doubt the issue is with the plant sensors.
I doubt if the dongle is the issue here. I use a Raspberry-Pi model 3 with integrated BT, and have similar issues.
Hans
terrorsource
Posts: 67
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by terrorsource »

manjh wrote: Tuesday 04 September 2018 12:26
PatrickM wrote: Tuesday 04 September 2018 12:00 I wonder if it is caused by the bluetooth dongle? I've a cheap chinese generic one. The Flower Care app on Android works very well so i doubt the issue is with the plant sensors.
I doubt if the dongle is the issue here. I use a Raspberry-Pi model 3 with integrated BT, and have similar issues.
Same here, with a Raspberry Pi 3B+.
Same issue's as everyone else has.
cristiano
Posts: 1
Joined: Wednesday 16 November 2016 19:26
Target OS: -
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by cristiano »

I installed the plugin and when I start it I can see this in the logs (debugging on):

2018-09-16 12:17:58.558 (MIF2) Number of devices found via bluetooth scan = 1
2018-09-16 12:17:58.559 (MIF2) Creating new sensors
2018-09-16 12:17:58.559 (MIF2) Creating new sensors for Mi Flower Mate at C4:7C:8D:66:17:56
2018-09-16 12:17:58.559 (MIF2) Creating first sensor, #2
2018-09-16 12:17:58.560 (MIF2) Creating first sensor, name: #0 Moisture
2018-09-16 12:17:58.560 (MIF2) Creating device '#0 Moisture'.
2018-09-16 12:17:58.560 Error: (MIF2) 'onStart' failed 'KeyError'.
2018-09-16 12:17:58.560 Error: (MIF2) ----> Line 238 in '/home/cristiano/domoticz/plugins/MIFlower/plugin.py', function onStart
2018-09-16 12:17:58.560 Error: (MIF2) ----> Line 68 in '/home/cristiano/domoticz/plugins/MIFlower/plugin.py', function onStart
2018-09-16 12:17:58.560 Error: (MIF2) ----> Line 230 in '/home/cristiano/domoticz/plugins/MIFlower/plugin.py', function floraScan
2018-09-16 12:17:58.561 Error: (MIF2) ----> Line 127 in '/home/cristiano/domoticz/plugins/MIFlower/plugin.py', function createSensors

Sensors are not created.

Can you please help?
tonbor
Posts: 153
Joined: Monday 17 February 2014 9:12
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by tonbor »

Yes, use not the plugin that is not working. The script is working flawlessly, with extern dongle and with intern bluetooth raspberry 3b+.
digger
Posts: 2
Joined: Sunday 21 October 2018 14:01
Target OS: -
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by digger »

Same problem here, crashing randomly.

I have it now to check once 5 minutes after the hour
and I restart the service before the hour with crontab :mrgreen:

Works fine like that

Code: Select all

30 3 * * 0 sudo reboot
56 * * * * sudo service domoticz.sh stop
58 * * * * sudo service domoticz.sh start

@blauwebuis .....

Can I change the value that is displayed into µS/cm to EC ?
Would be value µS/cm devided by 100

Thank you
sterremos
Posts: 3
Joined: Tuesday 16 October 2018 15:09
Target OS: -
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by sterremos »

unfortunately I did not find it anymore, but I came to see a week of a mi flowe sensor in Domoticz and in the overview of the water information indicated if the value was not good, neutral or bad. This gives more information. water intensity of explame 19% does not say much in the overview


does anyone have this script?
my gratitude
Lars65
Posts: 41
Joined: Thursday 14 July 2016 20:49
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by Lars65 »

I am doing a new installation of domoticz, on a raspberry pi 3. I have installed the plugin and it's working.
Except that moisture sensor is not showing any data. It shows 0 and the it's showing it in cb, shouldn't it be in %.
blauwebuis
Posts: 331
Joined: Wednesday 21 December 2016 9:11
Target OS: Raspberry Pi / ODroid
Domoticz version: current
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by blauwebuis »

The plugin was updated to output data in the moisture field instead of a simple percentage, to create compatibility with Homekit.

https://github.com/flatsiedatsie/Mi_Flo ... n/issues/4

If this has broken the plugin please report it.
jandirkv
Posts: 27
Joined: Monday 19 February 2018 6:20
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9117
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by jandirkv »

I installed the latest Xiaomi plant plugin but I still have no percentage for the moisture and the sensor is still General percentage instead of humidty sensor. I've read all the links in this thread but I dont know how to update it to get it to work. Can someone post a tutorial for dummies.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest