Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update of Mi Flora sensor is taking over 10 seconds #19362

Closed
mlevit opened this issue Dec 16, 2018 · 29 comments
Closed

Update of Mi Flora sensor is taking over 10 seconds #19362

mlevit opened this issue Dec 16, 2018 · 29 comments

Comments

@mlevit
Copy link

mlevit commented Dec 16, 2018

Home Assistant release with the issue: 0.84

Last working Home Assistant release (if known): < 0.83

Operating environment (Hass.io/Docker/Windows/etc.): Hass.io

Component/platform: https://www.home-assistant.io/components/sensor.miflora/

Description of problem: I have 4 Mi Flora sensors. 3 of them are working fine but the 4th is no longer connecting and updating Home Assistant. If I use the Android Flower Care app, the sensor is actually functioning, but Home Assistant is timing out trying to receive updates.

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

# sensor
  - platform: miflora
    mac: 'C4:7C:8D:67:2B:43'
    name: Master Bedroom Palm
    force_update: true
    # median: 3
    monitored_conditions:
      - moisture
      - light
      - temperature
      - conductivity
      - battery

# plant
  master_bedroom_palm:
    sensors:
      moisture: sensor.master_bedroom_palm_moisture
      battery: sensor.master_bedroom_palm_battery
      temperature: sensor.master_bedroom_palm_temperature
      conductivity: sensor.master_bedroom_palm_conductivity
      brightness: sensor.master_bedroom_palm_light_intensity
    min_moisture: 15
    max_moisture: 60
    min_battery: 15
    min_conductivity: 350
    max_conductivity: 2000
    min_temperature: 10
    max_temperature: 32
    max_brightness: 35000

Traceback (if applicable):

Update of sensor.master_bedroom_palm_temperature is taking over 10 seconds
8:54 AM util/async_.py (WARNING)
Update of sensor.master_bedroom_palm_battery is taking over 10 seconds
8:54 AM util/async_.py (WARNING)
Update of sensor.master_bedroom_palm_light_intensity is taking over 10 seconds
8:54 AM util/async_.py (WARNING)
Update of sensor.master_bedroom_palm_conductivity is taking over 10 seconds
8:54 AM util/async_.py (WARNING)
Update of sensor.master_bedroom_palm_moisture is taking over 10 seconds
8:54 AM util/async_.py (WARNING)

Additional information:

@ronytomen
Copy link
Contributor

I struggled with timeouts as well (in previous versions), but I have been steadily adding more MiFlora sensors. I was wondering if the BT driver was having issues, because I sometimes could get it to function correctly if I restarted BT daemon.

I ended up setting up a Plant Gateway on a Raspberry Pi that is more centrally placed in my home.

Watching Plant Gateway working, I have noticed that it will fail to connect to 1 or 2 of the 5 sensors I currently have active. It will eventually connect, get the metrics from the sensor and send the results to Home Assistant via MQTT. I believe it's due to the distance between the Raspberry Pi and some sensors. So, knowing that, I have been wondering if the MiFlora component code is issuing this warning and not retrying? I have yet to inspect the component code.

@raccettura
Copy link
Contributor

raccettura commented Dec 23, 2018

Something did get worse here.

Pre 0.84 Mi Flora threw some "over 10 seconds" errors but otherwise worked ok. Since 0.84 having Mi Flora sensors has resulted in HomeAssistant startup times taking in excess of 15-20 minutes, no UI (http not responding). Commenting out the Mi Flora sensors gets it working again.

This is all via Docker.

@mlevit
Copy link
Author

mlevit commented Dec 29, 2018

@ChristianKuehnel since you've worked on Mi Flora before, would you be able to investigate this?

@ChristianKuehnel
Copy link
Contributor

ChristianKuehnel commented Dec 31, 2018 via email

@PaulAnnekov
Copy link
Contributor

The last release of miflora component was in 0.80.0. I don't see any significant changes after that time.
Checking this issue will require a lot of debugging and it will be faster to debug on place, e.g. to change a distance between miflora sensor and bluetooth transmitter or to patch-restart HA. Also, I don't use miflora anymore.

@raccettura
Copy link
Contributor

Just tried 0.88b and it's not working.

It seems to have broken between 0.83 and 0.84 best I can tell. I don't think it's necessarily a change in the mi flora library/component itself. This smells like a race condition or some other contention issue. It seems to be mainly (or only) impacting people with multiple sensors.

@ChristianKuehnel
Copy link
Contributor

ChristianKuehnel commented Feb 18, 2019

@raccettura Can you please turn on debug logging on miflora, btlewrap and bluepy? Maybe this will give us a better idea of what's going wrong...

You can do this by adding this to your configuration.yaml:

logger:
  default: info
  logs:
    miflora: debug
    btlewrap: debug
    bluepy: debug

Please append these debug log to the ticket.

@raccettura
Copy link
Contributor

raccettura commented Feb 19, 2019

@ChristianKuehnel

Some snippets that seem relevant:

2019-02-18 19:03:08 DEBUG (SyncWorker_16) [miflora.miflora_poller] Received result for handle 56: 5B 15 32 2E 37 2E 30
2019-02-18 19:03:08 DEBUG (SyncWorker_3) [miflora.miflora_poller] Received result for handle 56: 5B 15 32 2E 37 2E 30
2019-02-18 19:03:11 DEBUG (SyncWorker_13) [btlewrap.bluepy] Call to <function BluepyBackend.connect at 0x7f0f36e6e048> failed, try 1 of 3
2019-02-18 19:03:16 DEBUG (SyncWorker_13) [btlewrap.bluepy] Call to <function BluepyBackend.connect at 0x7f0f36e6e048> failed, try 2 of 3
2019-02-18 19:03:18 DEBUG (SyncWorker_13) [miflora.miflora_poller] Received result for handle 56: 0B 15 32 2E 37 2E 30
2019-02-18 19:03:21 DEBUG (SyncWorker_19) [miflora.miflora_poller] Received result for handle 56: 0A 10 32 2E 36 2E 32
2019-02-18 19:03:21 DEBUG (SyncWorker_0) [btlewrap.bluepy] Call to <function BluepyBackend.connect at 0x7f0f36e6e048> failed, try 1 of 3
2019-02-18 19:03:24 DEBUG (SyncWorker_0) [miflora.miflora_poller] Received result for handle 56: 0B 15 32 2E 37 2E 30
2019-02-18 19:03:24 DEBUG (SyncWorker_0) [miflora.miflora_poller] Filling cache with new sensor data.
2019-02-18 19:04:59 DEBUG (SyncWorker_16) [btlewrap.bluepy] Call to <function BluepyBackend.connect at 0x7f0f36e6e048> failed, try 2 of 3
2019-02-18 19:05:40 DEBUG (SyncWorker_16) [btlewrap.bluepy] Call to <function BluepyBackend.connect at 0x7f0f36e6e048> failed, try 3 of 3
2019-02-18 19:05:40 INFO (SyncWorker_16) [homeassistant.components.sensor.miflora] Polling error 

After 3rd attempt it actually loads. Took maybe 3-4 minutes. Interestingly without the debugger turned on I could never get it to start.

@johnflorin
Copy link

I had the same problem - it stopped working suddenly, had the 10 second warnings (though they were also present before, when it worked), tried several restarts (including of the entire VM) and when enabling the debugger it magically started working again!

@daenny
Copy link
Contributor

daenny commented Mar 12, 2019

This seems indeed the same problem as I am facing in #21774,
I think enabling the debug log slows down the startup process in such a way that sometimes not all threads are assigned to the miflora sensor and then the system is able to boot.

@sajikur
Copy link

sajikur commented Mar 14, 2019

Hi all. I have the same problem with my MIFLORA sensors (10 seconds warnings). Moreover, I've tried to make a clean new installation of hassio on new sd card. Well, when rasp rebooted for the first time after upload last snapshot, UI stopped until I've wrote "#" on miflora lines in configurator.yaml. Could someone solve this issue? TY

@Spirituss
Copy link

Have similar problems with Mi Flora. It suddenly stops working but after HA restart could start working again. I turned on debug for Flora and bluetooth, have tons of the following messages in log:
DEBUG (Thread-4) [btlewrap.bluepy] Call to <function BluepyBackend.write_handle at 0x61b44d20> failed, try 1 of 3
and
DEBUG (Thread-3) [btlewrap.bluepy] Call to <function BluepyBackend.connect at 0x61d4e6a8> failed, try 1 of 3

@Weezul
Copy link

Weezul commented Aug 13, 2019

Any news on this?

I started experiencing the same problem (No values from sensor, with the BluepyBackend.connect failed call error) a week or two ago. Not sure what I changed :/ My config file history shows no changes on the MiFlora config, I have updated to a later Hassio version, not sure if that was the cause.

@sajikur
Copy link

sajikur commented Aug 13, 2019 via email

@Weezul
Copy link

Weezul commented Aug 13, 2019

Thanks, will give that a try! (And replace this remark with the results)

@sajikur
Copy link

sajikur commented Aug 13, 2019 via email

@gilbert-grape
Copy link

gilbert-grape commented Aug 29, 2019

I have the same problem with 3 Miflora Sensors. It used to work until the end of year 2018, and since then I have problems.
I am sure it can not be the distance between the sensor and the Raspberry Pi3. I tried the following with no effects:

  • Reduce the distance of the sensor and Pi to 1m and less.
  • Delete all sensors except one from configuration.yaml.
  • Update Hass.io
  • Reinstall / Clean new installation
  • Restarting Hass.io and Home Assistant Server
  • Change battery of the Miflora Sensors (the battery is almost full)
  • Change the refresh rate (in the configuration.yaml file) from 5min to 60min and back

What I see now:

  • It looks like it is working worse for every month.
  • First I thought a restart of Hass.io helps. Most time a restart helps after some time I get values, but very fast the values freeze. And then I need a new restart.
  • Sometimes a restart helps and all sensors have new values. Sometimes 2 sensors have new values and 1 has only the battery value. It is like random.
  • After a restart if I run in command line
bluetoothctl
[bluetooth]# scan on

I get the MAC address and so on...
But later some hours or days I get the following error:

bluetoothctl
[bluetooth]# scan on
bluetoothctl failed to connect org.bluez.error.failed

@sajikur
Copy link

sajikur commented Aug 29, 2019 via email

@gilbert-grape
Copy link

Little tip: I upgraded my system to Intel nuc i3 with 8gb ram and ssd 128 GB. FABOLOUS! Another universe! Reboot in about 5 sec and cameras without stuck. If you can, upgrade to nuc Bye In data 13 agosto 2019 13:03:19 Wessel du Plooy [email protected] ha scritto:

Thanks, will give that a try! — You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

Nice for you. But this is not really helpful for me.
How do you set up your ESP32? Do you have a manual?

@sajikur
Copy link

sajikur commented Aug 29, 2019 via email

@ElGranLoky
Copy link

I do the same like @sajikur, works fine.

And after you can use the esphome to update esp32 & ESP8266 from more devices:

https://blakadder.github.io/templates/

The templates from tasmota help you to find the correct pin use.

@sajikur
Copy link

sajikur commented Aug 30, 2019 via email

@gilbert-grape
Copy link

In Home Assistant exists the attribute scan_interval, where I can define the read interval for the miflora sensor.
But in esp32home does not exist this attribute. In the documenataion is written it depends on the sending of miflora. Esp42 does only listen.

Can you explain how it works exactly?

@sajikur
Copy link

sajikur commented Aug 30, 2019 via email

ChristianKuehnel added a commit to ChristianKuehnel/home-assistant that referenced this issue Aug 30, 2019
fixes dependency issue home-assistant#19362 (only part of the solution)
@ChristianKuehnel
Copy link
Contributor

duplicate of #24453

@ElGranLoky
Copy link

@gilbert-grape The ESPHome Xiaomi integration listens passively to packets the xiaomi device sends by itself. Battery_level is the most slow sensor of all, you can read about the component in this link:

https://esphome.io/components/sensor/xiaomi_miflora.html

@ChristianKuehnel Don't despair. Since version 0.84 this problem exists and not everyone knows how to program or search for errors. For my part I don't usually do many PR but I try to help whenever I have time.

And even if the missing library is added, the problem reappears over time as users comment.

balloob pushed a commit that referenced this issue Sep 2, 2019
fixes dependency issue #19362 (only part of the solution)
@Weezul
Copy link

Weezul commented Sep 2, 2019

For me, the problem was solved by changing to a stronger 3A power supply. I can only assume that something on the RasPi started drawing more power, which underpowered it's BT radio. Maybe this helps someone.

@gilbert-grape
Copy link

Weezul: Thanks for the tip. I changes my power adapter to an Apple iPad adapter which has enough power.
Result: Nothing changed, still only an update on miflora when i restart HA. And not all miflora have values. Sometimes One of 3 has values after a restart. Sometimes 2.

@balloob
Copy link
Member

balloob commented Sep 3, 2019

Closing this as it's a duplicate of #24453 and that has been resolved.

@balloob balloob closed this as completed Sep 3, 2019
peternijssen pushed a commit to peternijssen/home-assistant that referenced this issue Sep 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests