DEV Community

Cover image for Homebridge x Xiaomi Roborock S5 Vacuum setup guide
Matt 🦕
Matt 🦕

Posted on • Updated on • Originally published at blog.barnettjones.com

Homebridge x Xiaomi Roborock S5 Vacuum setup guide

I'm super into home automation and I have built a fairly decent setup around Apple Home.

I’m completely sold on being able to control my house by voice, asking Siri to turn on various lights or ask about air the quality.

There is one holdout however, one that I can’t control by voice, my robot vacuum cleaner. HomeKit doesn’t support vacuum cleaners so we’ll have to get creative.

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 involved a bit of trial and error.

Steps

  1. (Homebridge setup and configured with HomeKit)
  2. Get Xiaomi device token
  3. Configure miio device w/ token + ip
    • Test it all works
  4. Configure Homebridge accessory (the robot vacuum)
  5. 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 and there's a good guide available

I'll not go too much into the details for Homebridge but just for context 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. The vacuum in question is the Xiaomi Roborock S5 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 get access to this secure token?

Android

The simplest way to do this is by getting hold of an Android device and run an old version of the Xiaomi MiHome app (4.4.49 to be precise). This version of the MiHome app helpfully prints the device details to a log file which can be extracted and read.

As an Apple household 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 registered. What should happen in the background is a file will be created that you can export to you machine:

sdcard/SmartHome/logs/plug_DeviceManager
Enter fullscreen mode Exit fullscreen mode

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 note 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, a notepad is fine for this but I used a Bitwarden secure note becuase I was moving between computers.

Configure miio

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

...
Enter fullscreen mode Exit fullscreen mode

At this point you should be fairly confident the token is valid and the device is responding. Nice! 👍

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 its 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 as shown below.

  "accessory": "XiaomiRoborockVacuum",
  "name": "Robot Vacuum",
  "ip": "192.168.1.12",
  "token": "my-super-secret-token",
Enter fullscreen mode Exit fullscreen mode

This setup is enough to start test with the Apple Home so once you've added your ip and token start up Homebridge and give 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 parameters 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" }
  ],
Enter fullscreen mode Exit fullscreen mode

The id is arbitrary as far as I can tell (the example 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 will setup 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 like Vacuum the so that you don't have to speak in broken sentences
  • 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 should see 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.

Latest comments (1)

Collapse
 
genarcanov profile image
genarcanov