On Black Friday the Roborock S5 was discounted heavily enough that I bought one. I gave the Home Assistant Xiaomi Mi Robot Vacuum integration a look over before I did and browsed some reddit posts suggesting it was supported. Approximately 6 hours of frustration later, I finally got my API token. Here's how...

Being no stranger to API keys, Personal Access Tokens and what have you I didn't really think that getting the token required for Home Assistant to connect with the Robot Vacuum could possibly be this involved or difficult. There are sections of the documentation on the Home Assistant integration page that walk you through various steps but they fail to tell you that the order you do these things is vital. Not only that but you also need to use specific versions of the Mi Home app to be able to extract your token.

Bill of Materials

  • 1 Android Phone running the latest version of Mi Home
  • A second Android Phone (ideally rooted) to run an old version 5.4.54 of the Mi Home app. I failed to get any of the non-rooted methods to work but luckily have an old OnePlus phone from a recent upgrade that I rooted.
  • Roborock S5 Robot Vacuum (I presume this works with any other Xiaomi subsiduary bot)
  • A PC type system with Android Debugging Tools such as adb enabled and working

Setup steps

Make sure you follow these steps in order because if you don't, your token will be reset midway through and you'll be sad.

Note that many guides suggest version 5.0.x of the Mi Home app. This app no longer functions and I lost a good while to trying and failing with it. 5.4.54 worked fine and is my recommendation here.

  1. Set up your Robovac with the latest version of Mi Home on your primary Android device as you normally would.
  2. Ensure successful operation using the latest Mi Home app and give the Vacuum a static IP in your router or however you do that on your LAN.
  3. Install version 5.4.54 of Mi Home on your second (rooted) Android device and login.
  4. Ensure you are using the same server on both devices (USA worked fine for me)
  5. Ensure successful operation using 5.4.54 (locate is a nice simple test)
  6. Using adb we will now extract the token from the rooted phone
  7. Use adb shell to connect to your device and become root (I used Magisck root so I have to do adb shell -> su -> whoami to ensure I'm root.
  8. Then run grep -R '"token"' /data/data/com.xiaomi.smarthome and you'll see your token

9. Insert the token into your Home Assistant configuration YAML

## roborock robovac
vacuum:
  - platform: xiaomi_miio
    host: 192.168.1.216
    token: thisisnotmyactualtokenbutyourswillbeexactly32characterslong

10. We can then use the Home Assistant -> Developer Tools -> Call Service function to test out our integration thus

11. Profit

Conclusion

It really is that simple (lol). Xiaomi, if you're reading this, I find the whole process incredibly user hostile and frustratingly obscure. I scoured dozens of Github issues, forum posts and reddit posts for hours to get this working. Would it be so difficult to just give us an option under our account to access the API token like many other manufacturers do?