Xiaomi Mi Plants Monitor Flower

Also, Strange anomaly, but I am getting the same readings for 3 of my devices… my median is set to 5…

Hi,

i have problems to read out the sensors.
The gatttool is responding with “connect: No route to host (113)”.
If i test it by myself with “gatttool --device=xx:xx:xx:xx:xx:xx --char-read -a 0x03” i get the same error …
But if i run “hcitool lescan” before gatttool, I can read out the data.
The problem is that I have run “hcitool lescan” every ~1minute otherwise the error comes back.

I build and install bluez v5.41 instead of 5.23 from apt-get but no difference.
hciconfig is showing “up running”

everything is running on Orange pi with armbian with bluetooth le dongle.
With the same dongle on my rpi1 it is working.

Has somebody any idea ?

Hi @mattes34,

I’m also running Armbian on an Orange Pi. I have some of the same problems. Sometimes these error messages appear:

Getting data from Mi Flora
FW: 2.8.6
connect: Device or resource busy (16)
Name: Flower care
connect: Device or resource busy (16)
connect: Device or resource busy (16)
connect: Device or resource busy (16)
Temperature: 4804.2
Moisture: 136
Light: 61149
Conductivity: 26231
Battery: 100

Other times this

Getting data from Mi Flora
FW: 2.8.6
connect: Device or resource busy (16)
connect: No route to host (113)
connect: No route to host (113)
connect: No route to host (113)

Interesting thing is that when connected to my computer, I get the expected output (it’s not in soil yet, so no moisture or cond. reading). So probably it has something to do with the armbian distro.
Getting data from Mi Flora
FW: 2.8.6
Name: Flower care
Temperature: 21.0
Moisture: 0
Light: 65
Conductivity: 0
Battery: 100

Good evening @flinkebernt,

today I found some time to test a little bit.
I write a “workaround” to fix the “connect: No route to host (113)” problem by starting a “lescan” for every read or write.
Is is working, but now i get always wrong values. These value like 4804.2 degrees looks like the typical problem if the sensors answer with a Characteristic value/descriptor: aa bb cc dd ee ff 99 88 77 66 00 00 00 00 00 00. To handle this the plugin is writing a special value to the Characteristic 0x33 before reading the sensor data. If i test it by writing and reading via terminal and gattool i always get wrong values. So it is not working.

Now the interesting part: I download a BLE tool from nordic semiconductor for PC and make the write of the special value and a read in one connection cycle ( connect -> write -> read -> disconnect) and now i get the correct values…

So it looks like that there is a timing problem or the gatttool (on our pis) is disconnecting between this cycle.
My problem is that i current don’t know what I can be done without rewriting the plugin…

Ok … is see the “Interesting part” is not really interesting because on PC or rasberry it is also working with the gatttool… but maybe it is a disconnect between the commands.

Is there a way without using the gatttool ? or write a small c program

Hi again @mattes34

Interesting findings you have there.
I just upgraded my kernel from 3.4.? to the 4.9.4 development version. Now I have no problems with “Device or resource busy” or “No route”. The readings all seem normal. BTW I’m running Debian on Orange Pi Plus 2.
Followed the instructions on the Armbian site under my board / kernels to upgrade my kernel. My WiFi stopped working though, but getting the BLE / MiFlora to work with Home Assistant is more important :slight_smile:

Hi,

sounds good… a new evening project :wink:

thank you

To reduce the change of getting invalid data, I have added some extra fail checking: https://github.com/open-homeautomation/miflora/compare/master...Danielhiversen:master

Since I do not have any problem with invalid data, it is difficult to test these changes. So hope some of you could help me with that?
@anon35356645 @moskovskiy82 @FreeSkippy

Edit:
Replace the file with this one
.YOUR_CONFIG_FOLDER//deps/miflora/miflora_poller.py (or something similar)

1 Like

where does this file go?

found and changed, rebooting now

1 Like

At restart all values are off (as usual), I guess the miflora is PUSHING data every XX minutes?

EDIT after 20 minutes, still no update

I’ve been getting crazy values too. It’s started recently and seems fairly random. I’ll give that new code a go and see how I get on. Thanks!

had to do other stuff on my pi3. Now after 37 minutes still no values from the miflora

yeah there’re a bunch of errors in my log file about it so it looks like it doesn’t work at the moment. Reverting back

Could you post the error log?

17-02-11 15:32:22 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step
result = coro.throw(exc)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 387, in _update_entity_states
yield from update_coro
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity.py", line 204, in async_update_ha_state
yield from self.hass.loop.run_in_executor(None, self.update)
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/miflora.py", line 129, in update
data = self.poller.parameter_value(self.parameter)
  File "/home/homeassistant/.homeassistant/deps/miflora/miflora_poller.py", line 245, in parameter_value
self.fill_cache()
  File "/home/homeassistant/.homeassistant/deps/miflora/miflora_poller.py", line 185, in fill_cache
res = write_ble(self._mac, "0x33", "A01F")
  File "/home/homeassistant/.homeassistant/deps/miflora/miflora_poller.py", line 76, in write_ble
return [int(x, 16) for x in res.group(0).split()]
NameError: name 'res' is not defined
17-02-11 15:32:27 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step
result = coro.throw(exc)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 387, in _update_entity_states
yield from update_coro
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity.py", line 204, in async_update_ha_state
yield from self.hass.loop.run_in_executor(None, self.update)
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/miflora.py", line 129, in update
data = self.poller.parameter_value(self.parameter)
  File "/home/homeassistant/.homeassistant/deps/miflora/miflora_poller.py", line 245, in parameter_value
self.fill_cache()
  File "/home/homeassistant/.homeassistant/deps/miflora/miflora_poller.py", line 185, in fill_cache
res = write_ble(self._mac, "0x33", "A01F")
  File "/home/homeassistant/.homeassistant/deps/miflora/miflora_poller.py", line 76, in write_ble
return [int(x, 16) for x in res.group(0).split()]
NameError: name 'res' is not defined

the battery seems to be updated, just none of the other sensors

My mistake. Could you try to use the latest version?

I get a different error now

17-02-11 17:11:31 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step
    result = coro.throw(exc)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 387, in _update_entity_states
    yield from update_coro
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity.py", line 204, in async_update_ha_state
    yield from self.hass.loop.run_in_executor(None, self.update)
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/sensor/miflora.py", line 129, in update
    data = self.poller.parameter_value(self.parameter)
  File "/home/homeassistant/.homeassistant/deps/miflora/miflora_poller.py", line 246, in parameter_value
    self.fill_cache()
  File "/home/homeassistant/.homeassistant/deps/miflora/miflora_poller.py", line 186, in fill_cache
    res = write_ble(self._mac, "0x33", "A01F")
  File "/home/homeassistant/.homeassistant/deps/miflora/miflora_poller.py", line 77, in write_ble
    return [int(x, 16) for x in res.group(0).split()]
AttributeError: 'NoneType' object has no attribute 'group'

I think I have fixed the bugs now.

I updated to 0.38.1, I guess your previous changes are cancelled, correct?

Anyway it still not showing any data, now after 40 minutes of restarting HASS (after update to 0.38.1 not sure if it ever worked)