Xiaomi Gateway (Aqara) - The Solution

I managed to solve the issue.

Here’s the instructions:
If you have access to an Android phone, you can download a hacked APK for the Mi Home app that shows the hidden token.
Download Mi Home 5.4.54 APK
Install the hacked version of the Mi Home app and try again.

  1. go to a directory named “.storage” under the home assistant config directory
  2. edit “core.config_entries” file
  3. locate two entries that look like [A] and delete them from the list. Please ensure the structure of file to be valid json format while tampering it.
  4. restart home assistant
  5. the device should be re-discovered and can be added normally again.

[A]:

{
“connection_class”: “local_push”,
“data”: {
“host”: “10.0.0.10”,
“interface”: “any”,
“key”: “r12ja593lg1v2qx7”,
“mac”: “00:0a:95:9d:68:16”,
“port”: 9898,
“protocol”: “1.1.2”,
“sid”: “000a959d6816”
},
“domain”: “xiaomi_aqara”,
“entry_id”: “9d5bbfcef9ss4c47ab58w030sd52e791”,
“options”: {},
“source”: “zeroconf”,
“system_options”: {
“disable_new_entities”: false
},
“title”: “Xiaomi Aqara Gateway”,
“unique_id”: “00:0a:95:9d:68:16”,
“version”: 1
}

Change the following:

  1. 00:0a:95:9d:68:16 - MAC address in lower case
  2. 000a959d6816 - MAC address in lower case without “:”.
  3. r12ja593lg1v2qx7 - gateway password from Mi Home application
    (About → Wireless communication protocol - > Password)
  4. 10.0.0.10 - IP address of the gateway
  5. 9d5bbfcef9ss4c47ab58w030sd52e791 - I think it’s just a random GUID for Home Assistant to link the gateway configuration and its devices.

During the test, left one value for both gateways.
If you use two gateways at once, the values should be different.

xiaomi

This was great but only after I read a lot of other data to just understand the instructions.

Clarification 1: The .storage directory is hidden by default when you use both the “File Editor” plugin or Visual Studio Code editor. You can change the settings in Visual Studio Code to show you the directory. I thought the instructions were old but the directory is there, you can find it in the terminal.

Clarification 2: To get the gateway password you have to:

  1. Install the APK from the message above
  2. Log in
  3. Navigate to the Mi Control Hub device (or however you have it)
  4. Click the 3 dots at the top (…) then go to “About”. In case you do not see the entry “Wireless communication protocol” keep tapping on the bottom on the screen the “Plug-in version: xxxx” text until you enable developer mode. After the “Wireless communication protocol” appears make sure you enable the first field “Wireless communication protocol” and use the password from the second field in the instructions above.

Clarification 3: here is the better-formatted JSON

{
  "connection_class": "local_push",
  "data": {
    "host": "10.0.0.10",
     "interface": "any",
     "key": "r12ja593lg1v2qx7",
     "mac": "00:0a:95:9d:68:16",
     "port": 9898,
     "protocol": "1.1.2",
     "sid": "000a959d6816"
  },
  "domain": "xiaomi_aqara",
  "entry_id": "9d5bbfcef9ss4c47ab58w030sd52e791",
  "options": {},
  "source": "zeroconf",
  "system_options": {
    "disable_new_entities": false
  },
  "title": "Xiaomi Aqara Gateway",
  "unique_id": "00:0a:95:9d:68:16",
  "version": 1
}
1 Like

You can use this Xiaomi-cloud-tokens-extractor This tool/script retrieves tokens for all devices connected to Xiaomi cloud and encryption keys for BLE devices.