home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.53k stars 30.71k forks source link

Miio Xiaomi Air Purifier availability blinking ({'code': -9999, 'message': 'user ack timeout'}) #36972

Closed denysdovhan closed 3 years ago

denysdovhan commented 4 years ago

The problem

I have connected my Mi Air Purifier 3H (zhimi.airpurifier.mb3) via Xiaomi Air Purifier integration. This model is specified as a supported one.

However, I’ve noticed it gets offline from time to time, every 30-90 minutes.

image

If you take a closer look at the history graph, you’ll notice that availability is blinking and eventually it gets unavailable completely every few hours. Only rebooting a router and/or humidifier helps to get it back online.

image

Environment

Problem-relevant configuration.yaml

fan:
  - platform: xiaomi_miio
    name: purifier
    host: !secret purifier_host
    token: !secret purifier_token

Traceback/Error logs

2020-06-18 12:12:12 WARNING (MainThread) [homeassistant.components.fan] Platform xiaomi_miio not ready yet. Retrying in 90 seconds.
2020-06-18 12:13:48 ERROR (SyncWorker_3) [miio.miioprotocol] Unable to discover a device at address 192.168.0.188
2020-06-18 12:13:48 WARNING (MainThread) [homeassistant.components.fan] Platform xiaomi_miio not ready yet. Retrying in 120 seconds.

2020-06-18 12:31:38 WARNING (MainThread) [homeassistant.helpers.entity] Update of fan.purifier is taking over 10 seconds
2020-06-18 12:36:17 WARNING (MainThread) [homeassistant.helpers.entity] Update of fan.purifier is taking over 10 seconds
2020-06-18 12:36:17 ERROR (SyncWorker_8) [miio.miioprotocol] Unable to discover a device at address 192.168.0.188
2020-06-18 12:36:17 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: Unable to discover the device 192.168.0.188
2020-06-18 12:36:43 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: Unable to discover the device 192.168.0.188
2020-06-18 12:38:46 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: {'code': -9999, 'message': 'user ack timeout'}
2020-06-18 13:05:03 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: {'code': -9999, 'message': 'user ack timeout'}
2020-06-18 13:12:16 WARNING (MainThread) [homeassistant.helpers.entity] Update of fan.purifier is taking over 10 seconds
2020-06-18 13:12:16 ERROR (SyncWorker_3) [miio.miioprotocol] Unable to discover a device at address 192.168.0.188
2020-06-18 13:12:16 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: Unable to discover the device 192.168.0.188
2020-06-18 13:13:47 WARNING (MainThread) [homeassistant.helpers.entity] Update of fan.purifier is taking over 10 seconds
2020-06-18 13:15:51 WARNING (MainThread) [homeassistant.helpers.entity] Update of fan.purifier is taking over 10 seconds
2020-06-18 13:15:51 ERROR (SyncWorker_8) [miio.miioprotocol] Unable to discover a device at address 192.168.0.188
2020-06-18 13:15:51 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: Unable to discover the device 192.168.0.188
2020-06-18 13:17:23 WARNING (MainThread) [homeassistant.helpers.entity] Update of fan.purifier is taking over 10 seconds
2020-06-18 13:17:23 ERROR (SyncWorker_7) [miio.miioprotocol] Unable to discover a device at address 192.168.0.188
2020-06-18 13:17:23 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: Unable to discover the device 192.168.0.188
2020-06-18 13:17:23 ERROR (MainThread) [homeassistant.components.google_assistant.http] Request 
2020-06-18 13:18:56 ERROR (SyncWorker_1) [miio.miioprotocol] Unable to discover a device at address 192.168.0.188
2020-06-18 13:18:56 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: Unable to discover the device 192.168.0.188

The most interesting part here (from my point of view):

[homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: Unable to discover the device 192.168.0.188
[homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: {'code': -9999, 'message': 'user ack timeout'}

Additional information

Probably I've found relevant issues:

probot-home-assistant[bot] commented 4 years ago

xiaomi_miio documentation xiaomi_miio source (message by IssueLinks)

probot-home-assistant[bot] commented 4 years ago

Hey there @rytilahti, @syssi, mind taking a look at this issue as its been labeled with a integration (xiaomi_miio) you are listed as a codeowner for? Thanks! (message by CodeOwnersMention)

hapklaar commented 4 years ago

I suspect this to be a hardware issue. The 3H unit is responding very badly to pings and requests. I see a constant ping response time in the hundreds of ms and even timeouts, with the unit next to my access point.

denysdovhan commented 4 years ago

Having bad pings is OK - it doesn’t break functionality. I’m worried about purifier getting completely unavailable after some time.

This usually happens every 6-12 hours for me and requires reboot of router and Home Assistant.

hapklaar commented 4 years ago

Having bad pings is indicative of the responsiveness of the unit, this will also reflect in its reachability from HA. However I don't have the issue where I need to restart anything to get it working again. It just doesn't respond very often.

image

denysdovhan commented 4 years ago

Seems like I have managed to fix purifier getting completely unavailable every few hours. I manually specified my model:

fan:
  - platform: xiaomi_miio
    name: purifier
    model: zhimi.airpurifier.mb3 # I specified my model here
    host: !secret purifier_host
    token: !secret purifier_token

After that change, my purifier is still up for more than 48 hours.

However, general availability is still blinking:

Screenshot 2020-06-24 at 14 43 01
mrfoxbit commented 4 years ago

I have the same issue

rytilahti commented 4 years ago

Could it be related to cloud connectivity issues? Some xiaomi vacuums are known to have issues if the packets are simply dropped, see https://python-miio.readthedocs.io/en/latest/troubleshooting.html#intermittent-connection-issues-timeouts-xiaomi-vacuum

Sometimes 'user ack timeout' indicates that the command is not supported by the device, but consider it is working sometimes that shouldn't be the case..

denysdovhan commented 4 years ago

After upgrade to 0.112, my purifier gets completely unavailable. Restarting HA, router, or purifier doesn't help.

rytilahti commented 4 years ago

See the already linked 'command error' issue which is the likely the cause, that is however a different problem than this 'user ack timeout' issue.

denysdovhan commented 4 years ago

I've rolled back to the previous 0.111.* release.

rytilahti commented 4 years ago

And it is working just fine with it? Maybe there are differences between devices/firmware version/something, that is causing the timeout instead of that command error. In that case this would be a duplicate of that issue.

matteos1 commented 4 years ago

ade to 0.112, my purifier gets completely unavailable. Restarting HA, router, or purifier doesn't help.

also for me, the update of ha to 0.102 has made the purifier 3h unusable. its status is: not available

KoltesPunti commented 4 years ago

After update i got the same problem :/ [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: {'code': -5001, 'message': 'command error'}

rytilahti commented 4 years ago

For 'command error', see https://github.com/home-assistant/core/issues/36993 which will be fixed with a new python-miio release, sorry for the inconvenience :(

mrfoxbit commented 4 years ago

Still error in HA 0.112.2 and python-miio 0.5.2.1. My device is Xiaomi Air Purifier 3 (zhimi.airpurifier.ma4)

2020-07-04 17:48:52 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: {'code': -9999, 'message': 'user ack timeout'}
2020-07-04 18:24:04 ERROR (SyncWorker_10) [miio.miioprotocol] Unable to discover a device at address 192.168.100.227
2020-07-04 18:24:04 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: Unable to discover the device 192.168.100.227
2020-07-04 18:39:28 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: {'code': -9999, 'message': 'user ack timeout'}
2020-07-04 19:03:17 ERROR (SyncWorker_9) [miio.miioprotocol] Unable to discover a device at address 192.168.100.227
2020-07-04 19:03:17 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: Unable to discover the device 192.168.100.227
2020-07-04 19:05:21 ERROR (SyncWorker_14) [miio.miioprotocol] Unable to discover a device at address 192.168.100.227
2020-07-04 19:05:21 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: Unable to discover the device 192.168.100.227
2020-07-04 19:21:22 ERROR (SyncWorker_4) [miio.miioprotocol] Unable to discover a device at address 192.168.100.227
2020-07-04 19:21:22 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: Unable to discover the device 192.168.100.227
2020-07-04 20:26:52 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: {'code': -9999, 'message': 'user ack timeout'}
2020-07-04 20:39:16 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: {'code': -9999, 'message': 'user ack timeout'}
2020-07-04 20:51:18 ERROR (SyncWorker_13) [miio.miioprotocol] Unable to discover a device at address 192.168.100.227
2020-07-04 20:51:18 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: Unable to discover the device 192.168.100.227
2020-07-04 21:01:02 ERROR (SyncWorker_16) [miio.miioprotocol] Unable to discover a device at address 192.168.100.227
2020-07-04 21:01:02 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: Unable to discover the device 192.168.100.227
2020-07-04 21:22:13 ERROR (SyncWorker_7) [miio.miioprotocol] Unable to discover a device at address 192.168.100.227
2020-07-04 21:22:13 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: Unable to discover the device 192.168.100.227
2020-07-04 21:25:19 ERROR (SyncWorker_5) [miio.miioprotocol] Unable to discover a device at address 192.168.100.227
2020-07-04 21:25:19 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: Unable to discover the device 192.168.100.227
2020-07-04 21:39:46 ERROR (SyncWorker_9) [miio.miioprotocol] Unable to discover a device at address 192.168.100.227
2020-07-04 21:39:46 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: Unable to discover the device 192.168.100.227
2020-07-04 21:51:14 ERROR (SyncWorker_10) [miio.miioprotocol] Unable to discover a device at address 192.168.100.227
2020-07-04 21:51:14 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: Unable to discover the device 192.168.100.227
2020-07-04 21:52:02 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: {'code': -9999, 'message': 'user ack timeout'}
denysdovhan commented 4 years ago

@balloob please, reopen this issue. The error message persists in logs.

AdrinkBeer commented 4 years ago

FYI, I have upgraded to HA 0.113.3 (with the bump of python-miio) but still have an issue (Xiaomi Air Purifier 3H).

2020-08-02 16:16:50 ERROR (MainThread) [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: {'code': -9999, 'message': 'user ack timeout'}

No discovery issues in my logs (python miio fix).

rytilahti commented 4 years ago

Okay, let's reopen this, but I don't really know what would be a suitable fix for this. That {'code': -9999, 'message': 'user ack timeout'} message is coming from the device itself, so for some reason it fails to execute the called method.

On potential way to alleviate this would be either to retry (or ignore it from homeassistant's side and keep the old state) but it feels a bit hacky solution.

alive-corpse commented 3 years ago

The same issue (user ack timeout) with model zhimi.humidifier.ca1 (Air Humidifier v2) Home Assistant 0.113.1 python-miio==0.5.2.1

On potential way to alleviate this would be either to retry (or ignore it from homeassistant's side and keep the old state) but it feels a bit hacky solution.

I think it's really better than got log full of this messages.

syssi commented 3 years ago

@alive-corpse Could you check the error of your device (CA1) a second time? It's a "user ack timeout" or "UART timeout"?

0rsa commented 3 years ago

I add myself to this thread Using miiocli device --ip IP --token TOKEN info It works: Model: zhimi.airpurifier.mb3 Hardware version: esp32 Firmware version: 2.0.5

Using miiocli airpurifiermiot --ip IP --token TOKEN status It doesn't work: Error: {'code': -9999, 'message': 'user ack timeout'}

miiocli, version 0.5.4

freddieleeman commented 3 years ago

I'm getting a lot of these too:

    Got exception while fetching the state: Unable to discover the device 192.168.254.156
    Got exception while fetching the state: {'code': -9999, 'message': 'user ack timeout'}

Retrying the call with a small timeout and a limit of x retries would probably be a good fix.

xiaomihomeDomo commented 3 years ago

I'm getting a lot of these too:

    Got exception while fetching the state: Unable to discover the device 192.168.254.156
    Got exception while fetching the state: {'code': -9999, 'message': 'user ack timeout'}

Retrying the call with a small timeout and a limit of x retries would probably be a good fix.

How ??

freddieleeman commented 3 years ago

I'm getting a lot of these too:

    Got exception while fetching the state: Unable to discover the device 192.168.254.156
    Got exception while fetching the state: {'code': -9999, 'message': 'user ack timeout'}

Retrying the call with a small timeout and a limit of x retries would probably be a good fix.

How ??

I don't know, I'm still learning Python. But as a quick fix setting self._available (line 1097) of fan.py to True would probably fix the unavailable messages. But this is not a good fix in any way, so we should probably wait for someone with more talent then me to resolve this issue.

Seba200086 commented 3 years ago

Got the same problem (with Xiaomi Air Purifier 3H): [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: {'code': -9999, 'message': 'user ack timeout'} Would be nice to have some working solution

0rsa commented 3 years ago

Restart your purifier. If you connect to it after restarting, I agee that it happens when you are querying your purifier too many times in a short delay. I use node red and I can set querying delay, I have no more problem increasing this delay.

gislis2 commented 3 years ago

Restart your purifier. If you connect to it after restarting, I agee that it happens when you are querying your purifier too many times in a short delay. I use node red and I can set querying delay, I have no more problem increasing this delay.

Great suggestion Mind sharing your nodered recipe?

0rsa commented 3 years ago

I use https://python-miio.readthedocs.io/en/latest/ with an "exec" node (executes a system command) image I increased querying time from 5s to 30s.

syssi commented 3 years ago

If you want to reduce the update interval you could change the scan_interval. cp.

https://www.home-assistant.io/docs/configuration/platform_options/

SeraphimSerapis commented 3 years ago

Where does the component increase the scan_interval? fan by default uses 30s and I haven't seen any different in xiaomi_miio: https://github.com/home-assistant/core/blob/13cdf0ba6310c92758a858405dab60ad371e8a46/homeassistant/components/fan/__init__.py#L27

syssi commented 3 years ago

@SeraphimSerapis You are right. The component uses the default value.

freddieleeman commented 3 years ago

I've tried adjusting the scan_interval, but it doesn't solve the issue for me. Although less, I still get 'unavailable' status.

Seba200086 commented 3 years ago

Same here - set scan_interval: 60, but I'm still getting: [homeassistant.components.xiaomi_miio.fan] Got exception while fetching the state: {'code': -9999, 'message': 'user ack timeout'}

Additionally, I noticed that this parameter has no real impact on refreshing, e.g. AQI value refreshes irregularly every 3 to 20 minutes. I also noticed that with longer refresh intervals it helps to use Mi Home application (it forces values to refresh).

colethegamer123 commented 3 years ago

I'm getting a lot of these too:

    Got exception while fetching the state: Unable to discover the device 192.168.254.156
    Got exception while fetching the state: {'code': -9999, 'message': 'user ack timeout'}

Retrying the call with a small timeout and a limit of x retries would probably be a good fix.

Totally Same problem.

vampywiz17 commented 3 years ago

Same problem, but i not get discover problem, only "-9999" message.

It not affect the working, only trash the log.

koldogut commented 3 years ago

Same problem here with HA core-2021.4.6

Got exception while fetching the state: {'code': -9999, 'message': 'user ack timeout'}