Python plugin: Xiaomi Mi Flower Mate

Python and python framework
tonbor
Posts: 42
Joined: Monday 17 February 2014 10:12
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by tonbor » Tuesday 19 June 2018 16:15

First accept new sensors as a default in settings. Second choose the plugin at the new hardware list.

NeoMod
Posts: 20
Joined: Friday 07 July 2017 22:02
Target OS: Raspberry Pi
Domoticz version: Latest β
Location: Italy
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by NeoMod » Tuesday 19 June 2018 16:33

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: 42
Joined: Monday 17 February 2014 10:12
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by tonbor » Wednesday 20 June 2018 15:31

The script Works perfectly, the plug-in is worthless. Does NOT work at alllllll :cry:

blauwebuis
Posts: 350
Joined: Wednesday 21 December 2016 10:11
Target OS: Raspberry Pi
Domoticz version: current
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by blauwebuis » Wednesday 11 July 2018 16:33

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: 20
Joined: Friday 07 July 2017 22:02
Target OS: Raspberry Pi
Domoticz version: Latest β
Location: Italy
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by NeoMod » Wednesday 11 July 2018 17:42

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: 42
Joined: Monday 17 February 2014 10:12
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by tonbor » Wednesday 11 July 2018 18:50

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
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by mariuszwojciuk » Tuesday 07 August 2018 0:03

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: 350
Joined: Wednesday 21 December 2016 10:11
Target OS: Raspberry Pi
Domoticz version: current
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by blauwebuis » Tuesday 07 August 2018 9:36

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: 337
Joined: Saturday 27 February 2016 13:49
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: NL
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by manjh » Thursday 23 August 2018 17:33

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: 24
Joined: Friday 30 January 2015 21:18
Target OS: Raspberry Pi
Domoticz version: latest
Location: Noordwijk, Netherlands
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by dre68 » Thursday 23 August 2018 21:52

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: 48
Joined: Wednesday 18 June 2014 15:59
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by PatrickM » Tuesday 04 September 2018 12:00

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: 337
Joined: Saturday 27 February 2016 13:49
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: NL
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by manjh » 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.
Hans

terrorsource
Posts: 53
Joined: Wednesday 10 May 2017 17:57
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by terrorsource » Thursday 06 September 2018 12:35

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: 10
Joined: Wednesday 16 November 2016 20:26
Target OS: -
Domoticz version:
Contact:

Re: Python plugin: Xiaomi Mi Flower Mate

Post by cristiano » Sunday 16 September 2018 12:22

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?

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests