Unable to retrieve Xiaomi Vacuum token

When trying to extract the token from the database, that field was empty. I suspect this might be removed in a new release of the Xiaomi app, but I do not have a source for this.

Does anyone know?

sqlite3 apps/com.xiaomi.smarthome/db/miio2.db 'select name,localIP,token from devicerecord;'
xxx|aaa.bbb.ccc.ddd|

Which method are you using?

A combination of the ones indicated at https://home-assistant.io/components/vacuum.xiaomi_miio/. The MiToolkit crashed, so I tried adb in an Ubuntu VM. That did not work to get a backup, so I installed adb in Windows which worked fine.

Then, I extracted the backup in the Ubuntu VM using abe.jar, and looked at the database using sqlite3. Since I got the other values, I assume everything was correct so far. The only thing missing, was the token…

i suggest you to install an old mi home app version.

Here’s the relevant upstream issue, Xiaomi has changed the app not to save the token into the database: https://github.com/rytilahti/python-miio/issues/185

1 Like

Until a fix is issued you should uninstall the Mi Home app and use version 5.0.29 (can be found on APKMirror).
This version has the token saved in miio2.db. If MiToolkit still crashes (which it did for me) you can do a adb backup and extract the db with Android Backup Extractor.

Thank you, this was what I was looking for!

Unfortunately, it seems like they are working to block out third party apps. Maybe it’s not worth the struggle if it only works for a little while (integrating the vacuum would only be for show off anyways :smiley: )

I really hope there’ll be some clever workaround for this.
Being able to send simple commands to the vacuum is one thing, but the real beauty of having it included in Home Assistant are the possibilities automation gives, like initiating cleanup 30 minutes after all lights are turned off at night. It’s wonderful.

I’ve had no luck retrieving my token either. Deleted current mi home app and installed older 5.0 versions. The token is still absent from the mitoolkit report…
I guess next step is to wipe my android device, install mi home 5.0.29, reset the vacuum and get the new token. Does this token change with updates to mi home or does it stay the same? Can you share mi home devices to other devices with 5.0.29?

Mmh, finally managed to get a token. I now get this error in HA 62.1"

Log Details (ERROR)
Mon Feb 05 2018 13:11:02 GMT+0800 (Malay Peninsula Standard Time)

xiaomi_miio: Error on device update!
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/helpers/entity_component.py", line 397, in _async_add_entity
    yield from entity.async_device_update(warning=False)
  File "/usr/src/app/homeassistant/helpers/entity.py", line 308, in async_device_update
    yield from self.hass.async_add_job(self.update)
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 327, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 250, in _wakeup
    future.result()
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 243, in result
    raise self._exception
  File "/usr/local/lib/python3.6/concurrent/futures/thread.py", line 56, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/src/app/homeassistant/components/vacuum/xiaomi_miio.py", line 368, in update
    state = self._vacuum.status()
  File "/usr/local/lib/python3.6/site-packages/miio/vacuum.py", line 108, in status
    return VacuumStatus(self.send("get_status")[0])
  File "/usr/local/lib/python3.6/site-packages/miio/device.py", line 216, in send
    m = Message.build(msg, ctx)
TypeError: build() takes 2 positional arguments but 3 were given

For the people visiting this thread in the future, how did you get the token?
Your error is probably related to this:

Just used mitoolkit 1.6 with a mi home app v5.019 on Android. It seems that the component no more works with HA 62.0 and 62.1. A fix may be ready for 62.2. More info on GitHub. Wait to update!

For those left stranded by 62.0-62.1, good news: the last dev release has fixed the issues…

I just received my vacuum yesterday and had trouble getting the token. Here is what worked for me:

  1. If the vacuum is already linked to your Xiaomi account make sure to remove it from your account. I also cleared my Mi Home data completely in android just to make sure.

  2. Get the android app 5.019 (I downloaded it here : https://www.apkmirror.com/apk/xiaomi-inc/mihome/mihome-5-0-19-release/mihome-5-0-19-android-apk-download/)

  3. Open the app and connect to the Mainland China server (for some reason the token I got from US server was not working in HomeAssistant)

  4. Add the vacuum to your account

  5. Perform the steps to obtain the token.

This worked for me in HA 0.63

3 Likes

It works for me! Thanks

I’m trying same thing with purifier 2s but from whatever reason I can’t add this device to 5-0-19 mi home app after I got it removed from a latest one. Any idea what could be wrong?