core icon indicating copy to clipboard operation
core copied to clipboard

Xiaomii Miio configuration for Roborock S7 not working anymore

Open davinkevin opened this issue 2 years ago • 17 comments

The problem

After a complete reset of the vacuum, I tried to add it again in Home Assistant. When I followed the wizard dedicated to Xiaomii Miio I have the following error

image

If I do the configuration manually, like proposed in the previous capture, the wizard ends up successfully but the integration is stuck in the initialising state.

image

The only log I have is this line:

2022-11-03 13:40:16.175 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Alfred' for xiaomi_miio integration not ready yet; Retrying in background

What version of Home Assistant Core has the issue?

2022.11.0

What was the last working version of Home Assistant Core?

Not relevant, it stopped working while using 2022.4.7 with no reason

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Xiaomii Miio

Link to integration documentation on our website

https://www.home-assistant.io/integrations/xiaomi_miio#xiaomi-mi-robot-vacuum

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

Original thread for this issue, closed maybe a bit too fast 😅.

https://github.com/home-assistant/core/issues/75835

davinkevin avatar Nov 03 '22 12:11 davinkevin

Hey there @rytilahti, @syssi, @starkillerog, mind taking a look at this issue as it has been labeled with an integration (xiaomi_miio) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of xiaomi_miio can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Change the title of the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign xiaomi_miio Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


xiaomi_miio documentation xiaomi_miio source (message by IssueLinks)

home-assistant[bot] avatar Nov 03 '22 12:11 home-assistant[bot]

It looks like the issue with the reload during setup is fixed via #78995 (#75835) but there is another issue that is preventing setup.

https://github.com/home-assistant/core/blob/bad33da2c11e2877bf2671e4353a48cdf237995c/homeassistant/components/xiaomi_miio/init.py#L374

https://github.com/home-assistant/core/blob/bad33da2c11e2877bf2671e4353a48cdf237995c/homeassistant/components/xiaomi_miio/init.py#L393

Its hitting on one of these.

Ideally raise ConfigEntryNotReady is changed to pass the error message so its a bit more obvious whats wrong.

bdraco avatar Nov 03 '22 13:11 bdraco

@davinkevin if you are actually on 2022.11.0 and you get the unknown error occured, you schould then look in the logs. There really schould be an error about an exception that occured. In 2022.11.0 I added general try: excepts to log exceptions.

starkillerOG avatar Nov 03 '22 13:11 starkillerOG

@bdraco line 393 is for gateways only, this is a roborock vacuum, so it then has to be 374. But why is @davinkevin getting the "unknown error occured" during the config flow with the cloud? That error has to have occured in config_flow.py right? Or can you also get "unknown error occured" if you get an exception in the init.py file?

starkillerOG avatar Nov 03 '22 13:11 starkillerOG

Or can you also get "unknown error occured" if you get an exception in the init.py file?

That shouldn’t be possible unless somehow it’s being called.

You are spot on that you’ll need the new error from the logs

bdraco avatar Nov 03 '22 13:11 bdraco

I have nothing else in log part:

s6-rc: info: service s6rc-oneshot-runner: starting
s6-rc: info: service s6rc-oneshot-runner successfully started
s6-rc: info: service fix-attrs: starting
s6-rc: info: service fix-attrs successfully started
s6-rc: info: service legacy-cont-init: starting
s6-rc: info: service legacy-cont-init successfully started
s6-rc: info: service legacy-services: starting
services-up: info: copying legacy longrun home-assistant (no readiness notification)
s6-rc: info: service legacy-services successfully started
2022-11-03 15:24:32.270 WARNING (SyncWorker_0) [homeassistant.loader] We found a custom integration hacs which has not been tested by Home
 Assistant. This component might cause stability problems, be sure to disable it if you experience issues with Home Assistant
2022-11-03 15:24:43.409 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Alfred' for xiaomi_miio integration not ready ye
t; Retrying in background

Where 15:24:32.270 is the startup time, and 15:24:43.409 is almost the moment when I click the submit button in the UI. When the error appears, I don't have any other logs in the app.

If you want me to share more than that, let me know, but here, I can't do more with only logs 🤷

And FYI: image

davinkevin avatar Nov 03 '22 14:11 davinkevin

@davinkevin please first remove the existing (failing) xiaomi miio intergration, then restart HomeAssistant, then try to setup the xiaomi miio integration using the cloud (you will get the unkown error) and then cancel the config flow (cross in top right). Then go to the logs and post the logs here.

So if the cloud config flow setup is indeed failing the xiaomi miio integration will not be setup and you schould not see the "Config entry 'Alfred' for xiaomi_miio integration not ready yet; Retrying in background", but some other error schould be logged.

starkillerOG avatar Nov 03 '22 14:11 starkillerOG

I've been having this issue for probably 2 months, tried moving the vacuums to the same network as my HA server today and then they suddenly started working again. Not sure if this is something to do with me resetting the wifi and having to reregister the vacuum to mi home or just the network difference.

lygris avatar Nov 03 '22 15:11 lygris

@davinkevin please first remove the existing (failing) xiaomi miio intergration, then restart HomeAssistant, then try to setup the xiaomi miio integration using the cloud (you will get the unkown error) and then cancel the config flow (cross in top right). Then go to the logs and post the logs here.

@starkillerOG I have literally nothing in logs with this procedure. Because it's easier to believe me with a recording, I've done this for you:

https://link.davinkevin.fr/hass-issue-81475-r1

Maybe I'm doing something wrong in the process… let me know 🤷‍♂️

@lygris Interesting, I check this… because the roborock S7 software is not compatible with IPv6, I think they are in different networks… but still, the UI / system should display an error.

davinkevin avatar Nov 03 '22 15:11 davinkevin

Follow up on the network comment from @lygris, my HASS instance is able to ping/reach the Roborock S7 without any problem, even if they are in different virtual network, they are both not isolated, just configured differently (to remove IPv6 for the Roborock).

And FYI, the problem happened before I got IPv6 configured and network separation.

davinkevin avatar Nov 03 '22 15:11 davinkevin

@lygris yes it is true that xiaomi devices need to be in the same VLAN/network otherwise they will refuse to communicate. I know there was at some point documentation about this, but I indeed see that is not clear anymore in the docs. There is still a little piece here: https://www.home-assistant.io/integrations/xiaomi_miio#troubleshooting-unable-to-find-device-error-messages

~Someone schould update the docs to have a link to the troubleshooting of python miio: https://python-miio.readthedocs.io/en/latest/troubleshooting.html But if this is the issue we schould be seeing the miio.exceptions.DeviceException: Unable to discover the device x.x.x.x~

starkillerOG avatar Nov 03 '22 15:11 starkillerOG

@davinkevin ping will work accros virtual network, roborock will receive the command accros virtual network, but it will just ignore the command and not respond if it originates from a diffrent virtual network. (Why xiaomi/roborock decided that was a good idea i don't know).

starkillerOG avatar Nov 03 '22 15:11 starkillerOG

As to why we do not see any logs, I have no idea.... ~@bdraco could you maybe go through the config_flow of xiaomi miio and see where a error could occor that is not catched and logged? (I have but I could not find anything)~ I think the error might be occoring in the init.py ~but I thought the config flow has to already be finished and succeeded before anything in init.py is called. (@bdraco do you know how this works?)~

starkillerOG avatar Nov 03 '22 15:11 starkillerOG

PR for the documentation is here: https://github.com/home-assistant/home-assistant.io/pull/24802

starkillerOG avatar Nov 03 '22 15:11 starkillerOG

@davinkevin thank you very much for sharing the video, that makes it a lot clearer. So the integration is actually setup correctly (the config flow completed succesfully and a integration is made). However during initialization something goes wrong, so I was searching in the wrong file (we schould be looking at init.py not config_flow.py)

So @bdraco is right and the problem of the logging is probably here: https://github.com/home-assistant/core/blob/bad33da2c11e2877bf2671e4353a48cdf237995c/homeassistant/components/xiaomi_miio/init.py#L374

As to why it is not working, probably due to the VLANs.

starkillerOG avatar Nov 03 '22 16:11 starkillerOG

Can't wait to test it with a better error 😇.

Like already shared, the problem occurred way before the network modification (~2 months before), so even if this is related, I suspect potentially something else 🤔.

I'll give a new try after a potential patch in hass-core, with the vacuum and HASS in the same network (because it's long to configure and I loose the vacuum on the Xiaomi App).

I've seen some parameters in the integration to use Cloud instead of internal IP, is this something able to bypass my limitation in term of networking configuration?

davinkevin avatar Nov 05 '22 15:11 davinkevin

I had the same error for a while, forgot that I had moved the S7 to another VLAN. Changed it back to the same VLAN as Home Assistant, deleted the integration and added it again, everything works now. I have a S5 too, no problems having that in another VLAN than HA.

mariusjell avatar Nov 06 '22 11:11 mariusjell

I have the same Problem, but in my environment all devices are in the same subnet. no vlans. HA Version is 2022.11.2 - Core Version on RPI Roborock S7 is reachable via ping from RPI.

bbr111 avatar Nov 09 '22 09:11 bbr111

Any Ideas how to fix this issue?

bbr111 avatar Nov 17 '22 20:11 bbr111

How big is your subnet? Roborock may have coded it idiotically and hardcoded in a /24

lygris avatar Nov 17 '22 22:11 lygris

its a /24 HA an Roborock are in the same subnet. I deleted the config entry and re-add the device. Now it is working again.

bbr111 avatar Nov 17 '22 22:11 bbr111

its a /24 HA an Roborock are in the same subnet. I deleted the config entry and re-add the device. Now it is working again.

got exactly the same issue...the thing is...I got Home assistant runninğon Rpi...where to find init.py?

Soepgroenten avatar Jan 23 '23 15:01 Soepgroenten

I'm getting this error for the third time now after a S5 had been setup fine multiple times for weeks. What can I provide to help troubleshoot?

No vlan. /24 subnet. Deleting and re-adding the integration always works but it's really annoying.

Logger: homeassistant.config_entries Source: config_entries.py:424 First occurred: 4:03:45 AM (1 occurrences) Last logged: 4:03:45 AM

Config entry 'Roborock S5' for xiaomi_miio integration not ready yet; Retrying in background

codahq avatar Feb 03 '23 11:02 codahq

Good afternoon. Same problem here with my S7. First setup works fine, but after some hours, the integration doesn't work anymore, with the same error.

Logger: homeassistant.config_entries Source: config_entries.py:424 First occurred: 20:24:39 (1 occurrences) Last logged: 20:24:39

Config entry '' for xiaomi_miio integration not ready yet; Retrying in background

I have home assistant and vacuum both in the same vlan, and I have setted static ip for vacuum and home assistant. It's installed in a RPi 4.

FonteCuntin avatar Feb 06 '23 19:02 FonteCuntin

I'm quite confused, as I can only think of two cases where re-adding would be helpful and fix it:

  1. If the IP address has changed and the zeroconf config flow does not update it, e.g., if homeassistant does not receive the updates, or if the advertisement data does not contain the mac address of the device.
  2. If the token has changed, e.g., if the vacuum is reseted to the factory state / if it is connected to a new wifi.

To exclude the second one, one could install python-miio (from git master) and see if the device still allows communications using the bundled miiocli tool. @FonteCuntin this is likely easiest for you to test, considering it stops working in hours instead of days or weeks.

Step-by-step:

  1. Intallation
git clone https://github.com/rytilahti/python-miio.git
cd python-miio
poetry install
  1. Obtaining tokens and device infos
poetry run miiocli cloud list
  1. Giving it a go, especially after it suddenly stops working in homeassistant
poetry miiocli -d roborockvacuum --ip <ip address> --token <token> status

Some things to pay attention:

  1. Is the device still discovered? I.e., do you get something like Discovered xxxxx with ts: 2023-02-06 20:04:51, token: b'ffffffffffffffffffffffffffffffff' in the log output? If that works, the device at least answers to the discovery handshake.
  2. If you are seeing multiple retries with Unable to decrypt, returning raw bytes: messages that means that the token has changed. You could try miiocli cloud list again to see if the token if still the same.
  3. If it still keeps working using the tool after it fails in homeassistant, there is something really weird going on that needs more investigation...

rytilahti avatar Feb 06 '23 20:02 rytilahti

@rytilahti Thanks, your sentence: _"I can only think of two cases where re-adding would be helpful and fix it:

If the IP address has changed and the zeroconf config flow does not update it, e.g., if homeassistant does not receive the updates, or if the advertisement data does not contain the mac address of the device."_

pointed me into the right direction :-)

I've recently replaced my ISP's hardware by my own...so new network same SSID new IP..

just added the old IP to the DHCP reservations 'et voila' the whole thing is working again.

In the end (should be in the description of the integration), the integration doesn't update the device's IP automatically when it changes. This can be valuable information as it's not possible to configure a static ip onto the robot and most robot's receive a non reserved IP address from DHCP.

Perhaps this helps other users with the same issue too.

Soepgroenten avatar Feb 07 '23 14:02 Soepgroenten

So basically this piece of code should update the IP address based on the mDNS responses from the device: https://github.com/home-assistant/core/blob/dev/homeassistant/components/xiaomi_miio/config_flow.py#L184-L188

You could run avahi-browse -r _miio._udp to see the advertisements from all miio devices, in my case I have valetudo installed which does not seem to offer the mac address -> this does not get automatically updated:

= wlp61s0 IPv4 rockrobo-vacuum-v1_miio49XXXXXX               _miio._udp           local
   hostname = [rockrobo-vacuum-v1_miio49XXXXX]
   address = [192.168.xx.xx]
   port = [54321]
   txt = ["path=/mydevice"]
= wlp61s0 IPv4 yeelink-light-color1_miio45XXX             _miio._udp           local
   hostname = [yeelink-light-color1_miio45XXXX.local]
   address = [192.168.xx.xx]
   port = [54321]
   txt = ["mac=f0b42xxxxx" "epoch=1"]

I'm currently in the progress of rewriting the whole integration, the new one will use the device id (the numerical part of the name, "miio4xxxx") as unique id instead of the mac as it's more robust (i.e., always available in mdns as well as in device handshakes, even if the token is unknown).

rytilahti avatar Feb 07 '23 14:02 rytilahti

So basically this piece of code should update the IP address based on the mDNS responses from the device: https://github.com/home-assistant/core/blob/dev/homeassistant/components/xiaomi_miio/config_flow.py#L184-L188

You could run avahi-browse -r _miio._udp to see the advertisements from all miio devices, in my case I have valetudo installed which does not seem to offer the mac address -> this does not get automatically updated:

= wlp61s0 IPv4 rockrobo-vacuum-v1_miio49XXXXXX               _miio._udp           local
   hostname = [rockrobo-vacuum-v1_miio49XXXXX]
   address = [192.168.xx.xx]
   port = [54321]
   txt = ["path=/mydevice"]
= wlp61s0 IPv4 yeelink-light-color1_miio45XXX             _miio._udp           local
   hostname = [yeelink-light-color1_miio45XXXX.local]
   address = [192.168.xx.xx]
   port = [54321]
   txt = ["mac=f0b42xxxxx" "epoch=1"]

I'm currently in the progress of rewriting the whole integration, the new one will use the device id (the numerical part of the name, "miio4xxxx") as unique id instead of the mac as it's more robust (i.e., always available in mdns as well as in device handshakes, even if the token is unknown).

Sounds great, robust and reliable. Hook me up when you want to test it with a s7 Maxv Ultra

Soepgroenten avatar Feb 07 '23 14:02 Soepgroenten

I'm quite confused, as I can only think of two cases where re-adding would be helpful and fix it:

  1. If the IP address has changed and the zeroconf config flow does not update it, e.g., if homeassistant does not receive the updates, or if the advertisement data does not contain the mac address of the device.
  2. If the token has changed, e.g., if the vacuum is reseted to the factory state / if it is connected to a new wifi.

To exclude the second one, one could install python-miio (from git master) and see if the device still allows communications using the bundled miiocli tool. @FonteCuntin this is likely easiest for you to test, considering it stops working in hours instead of days or weeks.

Step-by-step:

  1. Intallation
git clone https://github.com/rytilahti/python-miio.git
cd python-miio
poetry install
  1. Obtaining tokens and device infos
poetry miiocli cloud list
  1. Giving it a go, especially after it suddenly stops working in homeassistant
poetry miiocli -d roborockvacuum --ip <ip address> --token <token> status

Some things to pay attention:

  1. Is the device still discovered? I.e., do you get something like Discovered xxxxx with ts: 2023-02-06 20:04:51, token: b'ffffffffffffffffffffffffffffffff' in the log output? If that works, the device at least answers to the discovery handshake.
  2. If you are seeing multiple retries with Unable to decrypt, returning raw bytes: messages that means that the token has changed. You could try miiocli cloud list again to see if the token if still the same.
  3. If it still keeps working using the tool after it fails in homeassistant, there is something really weird going on that needs more investigation...

Hi. I am starting in the home assistant world and I am still a very beginner. I can't execute the commands you send me in SSH, none of them work (APT, SUDO, poetry...), and from what I've seen, it's because the set of commands installed with home assistant is very limited. I'm assuming I'm doing something wrong, but I don't have enough knowledge yet to figure out what. I understand there will be an update to the integration, so I'll try to test the changes as well when you roll them out. Thank you ;-)

FonteCuntin avatar Feb 08 '23 20:02 FonteCuntin

the IP address of my vacuum had also changed. a power outage brought the router down and when it came back up a new IP was assigned by the DHCP server. i didn't see that setting a static IP for the vacuum was a requirement. i have done that now but it sounds like a fix is coming that would allow for dynamic IPs. this is good as it will help others coming after us.

codahq avatar Feb 12 '23 17:02 codahq