Xiaomi's Vacuum Roborock S7 - Fails to Connect

HA 2021.11.5 - Docker Image on Ubuntu 20.04.

I know the Roborock S7 is a pretty new vacuum, it is listed on the supported devices. I notice the Miio integration now supports Cloud Login, but I also did see open issues about logins not working.

So I’m using the manual method.

Day one of using the device I used the Roborock application, built a map, device worked fine. Upon looking into using with HA, seems that the “Mi Home” app is needed instead.

  • So I installed Mi Home, connected device, did the WiFi pairing and in the Mi Home app device is connected and it can bring up the map created previously
  • I then deleted the vacuum from the Roborock application
  • Used Piotr’s Xiaomi Cloud Token Extractor (ran it multiple times over the day, token has not changed)

I get something that looks like (redacted some info):

Devices found for server "us":
   ---------
   NAME:     Roborock S7
   ID:       46xxx44
   IP:       192.168.22.24
   TOKEN:    7axxx4c
   MODEL:    roborock.vacuum.a15
   ---------

Using the Miio integration Configure Manually option, I enter the IP Address from above and the token and it says “Failed to Connect”. Nothing happens.

I enabled these for debugging:

  • homeassistant.components.vacuum: debug
  • homeassistant.components.miio: debug
  • homeassistant.components.xiaomi_miio: debug

Which yielded a single line:

2021-12-02 14:43:55 DEBUG (MainThread) [homeassistant.components.xiaomi_miio.device] Initializing with host 192.168.22.24 (token 7a4f6...)

From the “Failed to Connect” dialog box, I can select my model “roborock.vacuum.a15” and I get this:

2021-12-02 15:12:31 DEBUG (MainThread) [homeassistant.components.xiaomi_miio.device] Initializing with host 192.168.22.24 (token 7a4f6...)
2021-12-02 15:12:36 DEBUG (MainThread) [homeassistant.components.xiaomi_miio] Initializing with host 192.168.22.24 (token 7a4f6...)
2021-12-02 15:12:41 DEBUG (SyncWorker_3) [homeassistant.components.xiaomi_miio] Unable to fetch timers, this may happen on some devices: Unable to discover the device 192.168.22.24
2021-12-02 15:12:46 DEBUG (MainThread) [homeassistant.components.xiaomi_miio] Finished fetching roborock.vacuum.a15 data in 10.001 seconds (success: False)
2021-12-02 15:12:46 WARNING (MainThread) [homeassistant.config_entries] Config entry 'roborock.vacuum.a15' for xiaomi_miio integration not ready yet; Retrying in background
2021-12-02 15:12:51 DEBUG (MainThread) [homeassistant.components.xiaomi_miio] Initializing with host 192.168.22.24 (token 7a4f6...)
2021-12-02 15:12:56 DEBUG (SyncWorker_4) [homeassistant.components.xiaomi_miio] Unable to fetch timers, this may happen on some devices: Unable to discover the device 192.168.22.24
2021-12-02 15:13:01 DEBUG (MainThread) [homeassistant.components.xiaomi_miio] Finished fetching roborock.vacuum.a15 data in 10.001 seconds (success: False)

From the HA docker instance, I can ping the vacuum:

/config # ping 192.168.22.24
PING 192.168.22.24 (192.168.22.24): 56 data bytes
64 bytes from 192.168.22.24: seq=0 ttl=62 time=6.238 ms
64 bytes from 192.168.22.24: seq=1 ttl=62 time=6.091 ms
64 bytes from 192.168.22.24: seq=2 ttl=62 time=5.984 ms
64 bytes from 192.168.22.24: seq=3 ttl=62 time=5.874 ms
64 bytes from 192.168.22.24: seq=4 ttl=62 time=6.750 ms
64 bytes from 192.168.22.24: seq=5 ttl=62 time=6.811 ms
^C
--- 192.168.22.24 ping statistics ---
6 packets transmitted, 6 packets received, 0% packet loss
round-trip min/avg/max = 5.874/6.291/6.811 ms

I’m not sure where to go from here. Suggestions?

Reading lots of forum posts, I came across the mirobo command which is available from the command line within the HA container. not sure if this is helpful or not.

/config # mirobo --ip 192.168.22.24 --token 7a...4c -d status

INFO:miio.vacuum_cli:Debug mode active
DEBUG:miio.vacuum_cli:Connecting to 192.168.22.24 with token 7a...54c
DEBUG:miio.miioprotocol:Unable to discover a device at address 192.168.22.24
DEBUG:miio.click_common:Exception: Unable to discover the device 192.168.22.24
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/miio/click_common.py", line 59, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1053, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1659, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 1395, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/decorators.py", line 84, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/click/core.py", line 754, in invoke
    return __callback(*args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/miio/vacuum_cli.py", line 113, in status
    res = vac.status()
  File "/usr/local/lib/python3.9/site-packages/miio/vacuum.py", line 286, in status
    return VacuumStatus(self.send("get_status")[0])
  File "/usr/local/lib/python3.9/site-packages/miio/device.py", line 97, in send
    return self._protocol.send(
  File "/usr/local/lib/python3.9/site-packages/miio/miioprotocol.py", line 161, in send
    self.send_handshake()
  File "/usr/local/lib/python3.9/site-packages/miio/miioprotocol.py", line 74, in send_handshake
    raise DeviceException("Unable to discover the device %s" % self.ip)
miio.exceptions.DeviceException: Unable to discover the device 192.168.22.24
Error: Unable to discover the device 192.168.22.24

I just received and setup the Roborock S7. I simply set up the Roborock S7 with the Mi Home app, then added the Xiaomi Miio integration using my email address and password from Mi Cloud (credentials used to create an account in the Mi Home app), set my region and it worked.

However, I do have my Roborock S7 on a different network/VLAN then Home Assistant. This required setting up NAT masquerading. Bottom line is the Roborock S7 has to be on the same network as Home Assistant. If it’s not, then you need to set up NAT masquerading on your router/firewall. More details can be read in this Github issue.

2 Likes

I have 3 subnets, LAN (where HA / Docker runs), WLAN (trusted wireless) and IOT (VLAN on WLAN via Ubiquity WAP) - the S7 is here. I use pfSense to link it all together. I thought it was a mDNS issue as that seems to be what mirobo utility is using.

I have mDNS reflection in place and can put my laptop on any of the 3 IP networks and use mdns-scan to see devices on LAN (Brother Printers, Nvidia Shield, TrueNAS), WLAN (various wyze cams and laptops), but I don’t see any devices on IOT listed (ring, echo dots, S7 vacuum) - but I’m not positive they actually publish a mDNS service.

So I haven’t thought about NAT masquerading to solve this. Thanks for the link, I will review.

Yeah, it’s a very specific issue to the Roborock S7 and some other Xiaomi products. There’s more information in the python-miio documentation here. The Xiaomi Mi Home Binary Protocol uses a UDP packet which will only respond when the source address is on the same subnet as the Roborock S7. So when the Xiaomi Mi integration in HA attempts to send a packet to the Roborock S7, the source address needs to be changed (masquerade) to look like it’s coming from the gateway of the subnet the Roborock S7 is on.

I tried to add a note on the Xiaomi Miio integration page, but it was felt that was beyond the scope of the integration documentation. I’m sure many other folks will run into this same issue, but hopefully they’ll stumble onto this thread or the python-miio documentation.

1 Like

I got the same Roborock a week ago, then spend a few days troubleshooting it. There are 2 problems with this robot and HA:

  1. If robot and HA is in different VLANs then you have to use NAT to translate HA IP address to IOT VLAN specific address, otherwise as @shred described Xiaomi protocol will not respond.

  2. My biggest issue with this protocol/device is that if you block internet access to Xiaomi cloud, connection between robot and HA will not be stable. It will drop every 2-3 minutes and then reestablish. Someone suggested to reject traffic instead of dropping but it doesn’t work with latest firmware. If robot doesn’t see cloud it keeps reseting network. So I ended up allowing access to specific IP address and only HTTPS connection.

P.S My first post here! After being Openhab user for past 6 years, I finally moved my massive installation to HA and I am very happy about it.

1 Like

I was about to try exactly what you did with rejecting outbound traffic from the Roborock S7. Unfortunate to hear that doesn’t seem to work. :frowning:

@shred - thank you. The Github issue you referenced had the screen shot I needed to setup the 1:1 NAT for HA to IOT. The mirobo util within the HA container was then able to pull status from the S7 and then the Miio integration completed.

This really should be referenced in part of the documentation, unfortunate that your effort was denied.

A little more detail which might help someone. The IP address I NAT was the IP of the docker host, not the specific IP of the HA docker instance as I run HA on private docker network with fixed IP behind Trefik (reverse proxy) and this solution worked perfectly with all that.

I assume the intermittent connections issues on my S6 MaxV has the same root cause.

Setup: HA and vacuum are located in different VLANs. The vacuum was supposed to have no internet access, but restricting access it drops every 30s or so.

Based on info found on the internet I’ve attempted the following without success:

  • Disabled Adguard protection in case it blocked relevant local DNS requests
  • Verified that firewall is set to reject for relevant VLAN
  • Opened for NTP and DNS toward the internet (someone mentioned DNS having to be open toward the internet, not sure why. If correct I suppose it might be hardcoded to use a specific DNS server?)

The only way I’ve found of solving the issue is removing all restrictions toward the internet for the vacuum. Since that works I suppose issues are likely not related to the vacuum being in a different VLAN.

I assume it need some sort of verification/communication operative, but no idea what specifically it needs. Ideas appreciated.

@Abscondo - my understanding is that unless you reflash the vacuum firmware with Valetudo to remove the external cloud dependencies it requires internet access. https://valetudo.cloud/

I works and can be controlled by HA, it just has internmittent disconnect every 30s or so. Your’re saying that the intermittent disconnects can’t be remedied witout full internet access? Seems other ppl have been able to solve it with openening for NTP and DNS.

Sorry to drag up something old but can @shred or @reefland please help me with the specifics of teh NAT I need to create? I don’t see a screenshot of the detail anywhere.

Basically my HA server is at 192.168.0.14 and the Roborock is 192.168.20.220

I can ping the Roborock from HA but the Integration won’t work:
image

Log error:

2022-08-04 12:28:11 WARNING (MainThread) [homeassistant.config_entries] Config entry 'Robot vacuum' for xiaomi_miio integration not ready yet; Retrying in background

Which router are you running? I personally use Sophos XG but here’s a screenshot of my NAT rule below. Specifically, you’re looking to translate a source NAT (aka masquerading). You can probably just search for those key words in the documentation of your router and hopefully there’s instructions on how to set it up.

For my setup, I’m basically specifying that anything coming from my “Home Server” (Original source), which is where Home Assistant is hosted, and going to my Roborock S7 (Original destination), for any protocol (Original service), to translate the source NAT to be my “Guest LAN Gateway” (IP address of the gateway for the VLAN the Roborock S7 is on).

1 Like

Thank you. I’m running a Ubiquiti Dream Machine Pro. It should be pretty easy to set this up.

EDIT: It seems this isn’t actually an easy task on the UDM Pro… strange since everything else is a simple GUI workflow.

@sparkydave - I did a quick Google search on UDM Pro 1:1 NAT and found lots of people complaining that Ubiquity lacks this basic feature. I assume that hasn’t changed?

Most of my network is Ubiquity equipment except the firewall because Ubiquity firewalls lack so many features common to other platforms.

It turns out that it can be done, but I have to SSH into the Dream Machine to do it so it’ll have to wait until I get more time. I’ll report back if I have success.

I tried on Mikrotik router without success
SRC-NAT from HA IP to S7 IP action MASQUERADE

Thanks for tip on a Sophos XG.
Works perfect!

1 Like

SNAT configuration seems to work fine with two subnets.
I have wired and wireless network 1 like 192.168.0.1-254
I also have IOT network where pretty much everything is blocked to main network in subnet 192.168.2.1-254.

Did it with OpenWRT this way and got configuration finally through succesfully: