Xiaomi Air Purifier is one of the best on the market in the price/value category. Like many other Xiaomi devices, it can be controlled using a great home automation system called Domoticz.
The only problem that I had is that for the 2S version, there is no way to obtain the device token needed for controlling the device using the miIO library.
Here are the steps needed to obtain this token using a Linux machine and a non-rooted Android phone.
Getting the Mi Home data backup
- Download and install the Mi Home application. You need to have the 5.0.19 version of this app. The newer versions don't persist the token locally in the SQLite database. You can get it from the APKMirror page. Note, that you will have to allow the Unknown sources to do that. Here's a description on how to do that.
- Enable developer mode and USB debugging on your phone (instruction).
- Download and extract the Android Platform tools for Linux from here.
- Install the most recent Java version if you don't have it.
- Enable developer mode and USB debugging on your phone and connect it to your computer.
- Unlock the phone and allow the computer for data transfers (not USB charging only).
- Authorize the Linux machine on your Android phone.
- Run the following command from your Linux machine:
./adb backup -noapk com.xiaomi.smarthome -f backup.ab
- Unlock your device and confirm the backup operation. If your phone is encrypted, you will also have to provide the backup password.
- If everything went smooth, you should have a backup.ab file in the platform tools for further processing. From this moment, you won't need the phone to be connected to your laptop.
Getting the device token out of the Mi Home backup
- Download and unpack the ADB extractor.
- Navigate to the android-backup-tookit/android-backup-extractor/android-backup-extractor-20180521-bin directory.
- Copy the abe.jar file to where your backup.ab is.
- Run the following command and follow the instructions (if any):
java -jar abe.jar unpack backup.ab backup.tar
- Unpack the extracted backup:
tar -xvf backup.tar
- Go to the apps/com.xiaomi.smarthome/db directory.
- Install and run the DB Browser for SQLite:
sudo apt-get install sqlitebrowser
- Open the miio2.db file using the DB Browsers for SQLite.
- Click on the Execute SQL tab and run the following query:
SELECT localIP, token FROM devicerecord
Now you can take the appropriate token and use it within your Domoticz setup.