Tip: Alternate way to get token for Xiaomi Vacuum

Dear alll,

recently I had to reconnect my Mi Robot (V1) to my Wifi.
As always, a new secret token was generated.
The problem: over the time Xiaomi made it more and more difficult to get this token to communicate to the robot with openHAB.
I found a lot of hints on the internet how to get the token (also here) and really none worked for me. And most of them have some major disadvantages. Just to metion a few:

  1. installation of a russian, modded version of the Mi Home app. Honnestly, You have to trust the developer to do so. And besides it did not work for me (constantly plugin error)

  2. rooted phone needed. I don’t want to root my phone for thiis… and you have to deal wth some SQLite manager and it only works with some versions of the Mi Home app

  3. adb shell: finally to complicated to get it working with a specific phone

Finally I found a relatively easy solution which requires no modification on your phone and it is also an option for iphone users… I just wanted to let you know this option.
Step by step but the short version. The details are more or leess self-explaining.

  1. Download Bluestacks (https://www.bluestacks.com/de/index.html). It’s an Android emulator for gaming but works as well for this purpose.
  2. Install Bluestacks on a Windows PC
  3. Search APK Mirror for the Mi Home App APK Version 5.4.49. Note: it must be exactly this version and does not work with others.
  4. Download the APK
  5. Import the APK into Bluestack (Feature import from Windows)
  6. Install the APK in Bluestacks
  7. Start the app and login into your regular Xiaomi account (be sure to use the same region)
  8. Wait until you robot appears in the app.
  9. Open the filemanager (Explore) in Bluestacks and go to sdcard/SmartHome/logs/Plug_DeviceManager
  10. There you fnd one or more txt files. Export them to Windows.
  11. Open the file(s) with an editor and search for token.

Voila: there is your current token in plain-text. It can be used directly in openHAB’s Things configuration for the robot.

Good luck.

4 Likes

The easiest way now is to get tokens is… OH…
From version 2.5.5 onwards you can simply enter your Xiaomi user ID / password in the binding config and the token will be pulled from the cloud.

That’s great!
This will ease the whole thing A LOT.
I assume you refer to the version of the binding … which will be shipped together with the next OH update right (using OH on Ubuntu server x86_64)?
Currently the blnding still expects the plaintext token to be entered…

Greetings.

Anyone know what the country should be? My Mi home app says Chinese mainland, yet ch in the country doesnt seem to be working to get a token?

Well, by now the current version I think is 2.5.7, but indeed I was refering to the version of the binding/OH.

The thing configuration hasn’t changed, it still expects the (hex) token.
When you enter the credentials, it will get it during discovery.
It also saves a json textfile in the runtime/miio folder with the token(s)

China country code = cn not ch (Switzerland). So if the mihome app has Mainland China use cn BTW, If you can’t find the right server you can also leave the field blank, it will try all known country servers.

Could this be done with the Xiaomi gatways? (I know thats not the binding you´re responsible for. I just wonder if this would be possible to get the gateway token as well).

Yes, I see no reason why it would not work.
I recently posted that as a suggestion [SOLVED] Openhab2 - Xiaomi Mi Gateway - does not respond - #330 by marcel_verpaalen but did not see any response of some one that tried it.
You could prob also request the tokens of the subdevices of the gateway (dunno if that is needed)

If you have one, give it a try… It will show up as unsupported device, but that would not stop it from getting the token and, if needed, send custom commands to it (like get_device_list or similar)

I have an older gateway. It´s connected trough the xiaomi (smart home binding).
But in my inbox I have 3 other devices, which appeared when I installed the Mi iO binding. Except for the gatway device, I have no idea what the other two devices are:

The first 2 are both related to your lumi gateway (there are 2 ways to discover these, that is causing the double entry, you can see they share the same deviceId / number between the brackets).
If you would enable the 2nd one (with token), you will see the token in the thing configuration.