Connecting Roborock S7 to Home Assistant
Written 2022-01-07 by Kalle
2 min read | 296 words
Intro
Connecting my Roboroskc S7 to Home Assistant was trickier than I imagined, so now that it's finally working, I don't want to forget the gained knowledge.
Network setup
Given that Roborock is a Chinese brand, I decided to keep it on a VLAN separate from my main VLAN where Home Assistant resides.
Using Unifi, I configured my static IPs as follows:
- Home Assistant on main VLAN: 192.168.1.221
- Roborock on IoT VLAN: 192.168.20.7
Connecting the Roborock to Home Assistant
I followed the following guide: https://smarthomepursuits.com/how-to-setup-configure-roborock-s7-with-home-assistant/. It went smoothly until I tried to add the Roborock to HA using the Xiaomi Miio addon. The Roborock was discovered and added as an integration, but a connection to it could not be established.
Some googling revealed that the issue is that the vacuum is on other subnet than HA:
- https://community.home-assistant.io/t/xiaomis-vacuum-roborock-s7-fails-to-connect/362715
- https://github.com/rytilahti/python-miio/issues/422
The suggested solution was to use NAT masquerading to trick the Roborock into believing that HA is on the same subnet as the Roborock.
NAT masquerading in Unifi USG using config.gateway.json
Puzzling together info from these two sites gave me the solution:
- https://github.com/rytilahti/python-miio/issues/422
- https://community.home-assistant.io/t/roborock-s7-entity-always-unavailable/330361
-
Save the following to
config.gateway.json
:{ "service": { "nat": { "rule": { "5010": { "description": "MASQ NAT HomeAssistant -> Roborock group", "destination": { "address": "192.168.20.7/24" }, "log": "disable", "outbound-interface": "eth1.20", "protocol": "all", "source": { "address": "192.168.1.221/24" }, "type": "masquerade" } } } } }
- Verify the integrity of the json file by pasting it's content to https://jsoneditoronline.org.
- Move the file to
/Users/<username>/Library/Application Support/UniFi/data/sites/default
, which is the equivalent to/srv/unifi/data/sites/default/
on a cloud controller running linux. - Force provision the USG from the controller by selecting the USG in the "Devices" section in the Unifi control panel, then "Config"->"Manage Device"->"Provision".