HomeKit ⅹ Roborock S5 Vacuum setup
1 Sep 2020 · 📖 in 8 minutes Hey Siri, vacuum the living roomI'm super into home automation and have built a fairly decent setup around Apple Home - with one holdout however, my Xiaomi Roborock S5 Vacuum.
There are a bunch of good resources (links below) out there already for how to do this but I wanted to share my steps as it invovled a bit of trial.
Steps
- (Homebridge setup and configured with HomeKit)
- Get Xiaomi device token
- BlueStacks (or any Android emulator)
- MiHome 4.4.49 (specifically this version)
- Login, extract log and get token (stored in Bitwarden)
- Configure miio device w/ token + ip
- Test it all works
- Configure Homebridge accessory (the robot vacuum)
- Homebridge plugin: homebridge-xiaomi-roborock-vacuum
- Add accessory:
XiaomiRoborockVacuum
- Test in Apple Home
- Configure rooms
- Add timer (for all rooms configured) 12:00am / 00:00
- Add room setup in order selected in timer
- Restart Homebridge
- Check each room (order may vary)
Homebrige
If you're reading this guide there's a good chance you know about Homebridge already. For those who don't Homebridge allows for non-HomeKit devices to be added to you Apple Home.
I'll not go too much into the details for Homebridge but just for cotnext I have Homebridge running on a Raspberry Pi and added to my Apple home.
Xiaomi Device Token
The first hurdle to overcome with this setup is getting the Xiaomi device token which is used to communicate with the vacuum. I assume the device token is a layer of security added to ensure only Xiaomi clients can talk to the device and without it setting up the Homebridge wouldn't be possible.
So how do we can access to this secure token?
Android
The simplest way to do this is by getting hold of an Android device and running an old version of the Xiaomi MiHome app (4.4.49 to be specific). This version of the MiHome app helpfully prints the device details to a log file which can be extracted and read.
As an Apple houshold we don't have any Android devices so that's where BlueStacks comes in. BlueStacks is a powerful emulator aimed at Android gamers who want to play on macOS or Windows 10 and best of all, it's free to download.
Once downloaded, install the MiHome APK and sign in to to the Mi account where the vacuum is registerd. What should happen in the background is a file will be created that you export to you machine:
sdcard/SmartHome/logs/plug_DeviceManager
Looking inside this file you will find a bunch of log messages and a few lines of JSON which will contain the string "token":...
verify the device is the correct one, as any device on the account will show up here. It's also a good idea to not down the deviceId
and ip
at this point too as you might need them later.
Once you have your token(s) store them somewhere for safekeeping, notes is fine for this but I used a Bitwarden secure note becuase I was moving between computers.
miio
Configure The first thing to do with the token is to test it works.
In order to test this use miio
, which provides a slew of useful commands that help with talking to various MiHome devices. Install this on the computer where Homebridge is installed.
npm install -g miio
Once that's installed the command miio discover
can be used to quickly scan the network for devices (if you run this now you might see your vacuum, however it's likely the token will come back as ???
).
To actually talk to the target device the local token cache needs to be updated with the one retrieved from the log. To do this simply run the command miio tokens update
with the IP and token for the device
miio tokens update 192.168.0.12 my-super-secret-token
This will allow you to then query the device with miio inspect
which should return various device stats, state, etc.
$ miio inspect 192.168.0.12
INFO Attempting to inspect 192.168.0.12
Device ID: ________
Model info: roborock.vacuum.s5
Address: 192.168.0.12
Token: my-super-secret-token via stored token
...
At this point you should be faily confident the token is valid and the device responds.
Configure Homebridge
The way different devices / accessories are configured in Homebridge is by plugins. The plugin for setting up the vacuum is the homebridge-xiaomi-roborock-vacuum which you can search for on the Homebridge website or use the link.
Each plugin spcifies it's own accessory config and for homebridge-xiaomi-roborock-vacuum
the accessory XiaomiRoborockVacuum
has a bunch of options. The default ones are things like the token
and ip
"accessory": "XiaomiRoborockVacuum",
"name": "Robot Vacuum",
"ip": "192.168.1.12",
"token": "my-super-secret-token",
This setup is enough to start playing with the Apple Home so once you've added your ip
and token
start up Homebridge and git her a whirl. 🧹
The vacuum should show up in Apple Home as a fan (which sorta makes sense, at least until HomeKit supports vacuums). The power of the vacuum can be controlled by the % of the fan so 100%
is Turbo
on my Roborock S5.
Configure Rooms
Looking back at the config there are a few optional params that might be some use (complete list is available)
Name | Default Value | Notes |
cleanword | "cleaning" | Prefix name of room switches |
room | false | Array of `id`, `name` for room configs |
zones | false | Array of `name`, `zone` configs |
When a room (or zone) Array is specified an additional switch is created in Apple Home with the name that of the entry in the array. The cleanword
prefixes the room name so if there was a room configured with the name "Kitchen" the switch would be labeled "cleaning Kitchen".
There are 5 rooms in my flat so I setup a room config like this
"rooms": [
{ "id": 16, "name": "Bathroom" },
{ "id": 17, "name": "Kitchen" },
{ "id": 18, "name": "Bedroom" },
{ "id": 19, "name": "Hall" },
{ "id": 20, "name": "Livingroom" }
],
The id is arbitrary as far as I can tell (the exmaple config starts at 16) however when I tried starting at 1 it didn't seem to work.
The next step is a little odd but there needs to be a Timer configured in the MiHome app at 00:00 / 12:00am (the first timer in the list). I suspect that the timer setups up some internal id which can be later relied on to allow for the room mapping to work reliably.
When setting up the timer it's important to add room cleaning with Select a room to divide
and add the rooms in the order specified in the config. This should allow for the mapping from Homebridge room to MiHome room.
Once again restart the Homebridge and open the Apple Home app. Test that each of the rooms are mapped correctly - don't panic if not go through each room and make a note of where it's configured, you should find that each room is mapped and only the lables need updating.
Final Tips
- Set the
cleanword
to something likeVacuum the
so that you don't have to speak in broken sentances - In Apple Home rename the device to "Robot Vacuum" or something and separte each switch into its own Tile, this helps with On / Off commands (otherwise there are a number of switches and Siri gets confused.)
- If you look at the main fan you shoul dsee the battery level and filter life percentages
Hey Siri, vacuum the living room
With that you're done! Congrats, it's certainly worth it as now you should be able to trigger a room cleaning using your voice.
First appeared on Trusty Interior, last update 2 Nov 2024