Skip to content

Commit 5458264

Browse files
syssiLandrash
authored andcommitted
Xiaomi token retrieval moved and extended (home-assistant#3339)
* Xiaomi token retrieval moved and extended. * Misleading sentence removed. * Additional item added to the trouble shooting section. * API token reference removed from the Xiaomi Gateway introduction. * The iOS app method does not work anymore. The ZToken column contains a 96 character encrypted token now. A 32 character token is still needed.
1 parent 2e0e8d0 commit 5458264

File tree

3 files changed

+66
-72
lines changed

3 files changed

+66
-72
lines changed

source/_components/light.xiaomi_philipslight.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The `xiaomi_philipslight` platform allows you to control the state of your Xiaom
1717

1818
Currently, the supported features are `on`, `off`, `set_cct` (colortemp) , `set_bright` (brightness).
1919

20-
Please follow the instructions on [Retrieving the Access Token](/components/xiaomi/#retrieving-the-access-token) to get the API token to use in the `configuration.yaml` file.
20+
Please follow the instructions on [Retrieving the Access Token](/components/vacuum.xiaomi/#retrieving-the-access-token) to get the API token to use in the `configuration.yaml` file.
2121

2222
To add a Xiaomi Philips Light to your installation, add the following to your configuration.yaml file:
2323

source/_components/vacuum.xiaomi.markdown

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The `xiaomi` vacuum platform allows you to control the state of your [Xiaomi Mi
1717

1818
Current supported features are `turn_on`, `pause`, `stop`, `return_to_home`, `turn_off` (stops goes to dock), `locate`, `clean_spot`, `set_fanspeed` and even remote control your robot.
1919

20-
Please follow the instructions on [Retrieving the Access Token](/components/xiaomi/#retrieving-the-access-token) to get the API token to use in the `configuration.yaml` file.
20+
Please follow the instructions on [Retrieving the Access Token](/components/vacuum.xiaomi/#retrieving-the-access-token) to get the API token to use in the `configuration.yaml` file.
2121

2222
To add a vacuum to your installation, add the following to your `configuration.yaml` file:
2323

@@ -79,3 +79,63 @@ Use this call to enter the remote control mode, make one move, and stop and exit
7979
| `velocity` | no | Speed, between -0.29 and 0.29. |
8080
| `rotation` | no | Rotation, between -179 degrees and 179 degrees. |
8181
| `duration` | no | Parameter affecting the duration of the movement. |
82+
83+
### {% linkable_title Retrieving the Access Token %}
84+
85+
<p class='note'>
86+
This token (32 hexadecimal characters) is required for the Xiaomi Mi Robot Vacuum and Xiaomi Philips Light. The Xiaomi Gateway uses another security method and requires a `key` (16 alphanumeric chars) which can be obtained easily via a hidden menu item at the Mi-Home app.
87+
</p>
88+
89+
Follow the pairing process using your phone and Mi-Home app. You will be able to retrieve the token from a SQLite file inside your phone.
90+
91+
Before you begin you need to install `libffi-dev` and `libssl-dev` by running the command below. This is needed for `python-mirobo` to be installed correctly.
92+
93+
```bash
94+
$ sudo apt-get install libffi-dev libssl-dev
95+
```
96+
97+
If your Home Assistant installation is running in a [Virtualenv](/docs/installation/virtualenv/#upgrading-home-assistant), make sure you activate it by running the commands below.
98+
99+
```bash
100+
$ sudo su -s /bin/bash homeassistant
101+
$ source /srv/homeassistant/bin/activate
102+
```
103+
104+
To fetch the token follow these instructions depending on your mobile phone platform.
105+
106+
#### {% linkable_title Windows and Android %}
107+
108+
1. Configure the robot with the Mi-Home app.
109+
2. Enable developer mode and USB debugging on the Android phone and plug it into the computer.
110+
3. Get and install the [ADB tool for Windows](https://developer.android.com/studio/releases/platform-tools.html).
111+
4. Create a backup of the application `com.xiaomi.smarthome`:
112+
```bash
113+
$ adb backup -noapk com.xiaomi.smarthome -f backup.ab
114+
```
115+
5. If you have this message: "More than one device or emulator", use this command to list all devices:
116+
```bash
117+
$ adb devices
118+
```
119+
and execute this command:
120+
```bash
121+
$ adb -s DEVICEID backup -noapk com.xiaomi.smarthome -f backup.ab # (with DEVICEID the device id from the previous command)
122+
```
123+
6. On the phone, you must confirm the backup. DO NOT enter any password and press button to make the backup.
124+
7. Get and install [ADB Backup Extractor](https://sourceforge.net/projects/adbextractor/).
125+
8. Extract All files from the backup:
126+
```bash
127+
$ java.exe -jar ../android-backup-extractor/abe.jar unpack backup.ab backup.tar ""
128+
```
129+
9. Unzip the ".tar" file.
130+
10. Open the SQLite database `miio2.db` with a tool like SQLite Manager extension for FireFox.
131+
11. Get the token from "devicerecord" table.
132+
133+
#### {% linkable_title Linux and Android (rooted!) %}
134+
135+
1. Configure the light with the Mi-Home app.
136+
2. Enable developer mode, USB debugging and root permission only for ADB on the Android phone and plug it into the computer.
137+
3. Get ADB f.e. `apt-get install android-tools-adb`
138+
4. `adb devices` should list your device
139+
5. `adb root` (does work for development builds only: ones with `ro.debuggable=1`)
140+
6. `adb shell`
141+
7. `echo "select name,localIP,token from devicerecord;" | sqlite3 /data/data/com.xiaomi.smarthome/databases/miio2.db` returns a list of all registered devices including IP address and token.

source/_components/xiaomi.markdown

Lines changed: 4 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ What's not available?
4646

4747
Follow the setup process using your phone and Mi-Home app. From here you will be able to retrieve the key from within the app following [this tutorial](https://community.home-assistant.io/t/beta-xiaomi-gateway-integration/8213/1832)
4848

49-
Please check the instructions in this [section](/xiaomi/#retrieving-the-access-token) to get the API token to use with your platforms.
50-
5149
To enable Xiaomi gateway in your installation, add the following to your `configuration.yaml` file:
5250

5351
### {% linkable_title One Gateway %}
@@ -140,72 +138,8 @@ Automation example
140138

141139
That means that Home Assistant is not getting any response from your Xiaomi gateway. Might be a local network problem or your firewall.
142140
- Make sure you have enabled LAN access: https://community.home-assistant.io/t/beta-xiaomi-gateway-integration/8213/1832
143-
- Turn off the firewall on the system where Home Assistant is running
141+
- Turn off the firewall on the system where Home Assistant is running.
144142
- Try to leave the MAC address `mac:` blank.
145-
- Try to set `discovery_retry: 10`
146-
- Try to disable and then enable LAN access
147-
148-
### {% linkable_title Retrieving the Access Token %}
149-
150-
Follow the pairing process using your phone and Mi-Home app. You will be able to retrieve the token from a SQLite file inside your phone. This token is needed for using various `xiaomi_*` platforms.
151-
152-
Before you begin you need to install `libffi-dev` and `libssl-dev` by running the command below. This is needed for `python-mirobo` to be installed correctly.
153-
154-
```bash
155-
$ sudo apt-get install libffi-dev libssl-dev
156-
```
157-
158-
If your Home Assistant installation is running in a [Virtualenv](/docs/installation/virtualenv/#upgrading-home-assistant), make sure you activate it by running the commands below.
159-
160-
```bash
161-
$ sudo su -s /bin/bash homeassistant
162-
$ source /srv/homeassistant/bin/activate
163-
```
164-
165-
To fetch the token follow these instructions depending on your mobile phone platform.
166-
167-
#### {% linkable_title Windows and Android %}
168-
169-
1. Configure the robot with the Mi-Home app.
170-
2. Enable developer mode and USB debugging on the Android phone and plug it into the computer.
171-
3. Get and install the [ADB tool for Windows](https://developer.android.com/studio/releases/platform-tools.html).
172-
4. Create a backup of the application `com.xiaomi.smarthome`:
173-
```bash
174-
$ adb backup -noapk com.xiaomi.smarthome -f backup.ab
175-
```
176-
5. If you have this message: "More than one device or emulator", use this command to list all devices:
177-
```bash
178-
$ adb devices
179-
```
180-
and execute this command:
181-
```bash
182-
$ adb -s DEVICEID backup -noapk com.xiaomi.smarthome -f backup.ab # (with DEVICEID the device id from the previous command)
183-
```
184-
6. On the phone, you must confirm the backup. DO NOT enter any password and press button to make the backup.
185-
7. Get and install [ADB Backup Extractor](https://sourceforge.net/projects/adbextractor/).
186-
8. Extract All files from the backup:
187-
```bash
188-
$ java.exe -jar ../android-backup-extractor/abe.jar unpack backup.ab backup.tar ""
189-
```
190-
9. Unzip the ".tar" file.
191-
10. Open the SQLite database `miio2.db` with a tool like SQLite Manager extension for FireFox.
192-
11. Get the token from "devicerecord" table.
193-
194-
#### {% linkable_title Linux and Android (rooted!) %}
195-
196-
1. Configure the light with the Mi-Home app.
197-
2. Enable developer mode, USB debugging and root permission only for ADB on the Android phone and plug it into the computer.
198-
3. Get ADB f.e. `apt-get install android-tools-adb`
199-
4. `adb devices` should list your device
200-
5. `adb root` (does work for development builds only: ones with `ro.debuggable=1`)
201-
6. `adb shell`
202-
7. `echo "select name,localIP,token from devicerecord;" | sqlite3 /data/data/com.xiaomi.smarthome/databases/miio2.db` returns a list of all registered devices including IP address and token.
203-
204-
#### {% linkable_title macOS and iOS %}
205-
206-
1. Setup iOS device with the Mi-Home app.
207-
2. Create an unencrypted backup of the device using iTunes.
208-
3. Install [iBackup Viewer](http://www.imactools.com/iphonebackupviewer/).
209-
4. Extract this file: **`/raw data/com.xiami.mihome/1234567_mihome.sqlite`** to your computer, where `_1234567_` is any string of numbers.
210-
5. Open the SQLite database with a tool like SQLite Manager extension for FireFox or DB Browser. You will then see the list of all the devices in your account with their token. The token you need is in the column **`ZToken`** and looks like **`123a1234567b12345c1d123456789e12`**.
211-
(Location of SQLite files directly on iOS devices **/private/var/mobile/Containers/Data/Application/A80CE9E4-AD2E-4649-8C28-801C96B16BD7/Documents/**)
143+
- Try to set `discovery_retry: 10`.
144+
- Try to disable and then enable LAN access.
145+
- Hard reset the gateway: Press the button of the gateway 30 seconds and start again from scratch.

0 commit comments

Comments
 (0)