Xiaomi Gateway Integration

Wow, thank you, that’s amazing

You right my key just change i just updated and now everything works as expected thanlk you

1 Like

Hi all, hoping there’s someone else out there running HA on windows who can help me. This seems like a really great community
I recently purchased a Xiaomi hub and a door sensor to see if it works well with HA. I have been using HA for a while to control my lighting.
The hub is setup and working fine via the android app. I have just logged into my HA machine (server 2016), upgraded HA to 0.53.0 (was 0.44), and added the following to my config

xiaomi:
  gateways:
    - mac: 
      key: <key here>

However, when I start HA I get the following error.

e[31m2017-09-10 19:40:51 ERROR (SyncWorker_5) [homeassistant.util.package] Unable to install package https://github.com/Danielhiversen/PyXiaomiGateway/archive/0.3.2.zip#PyXiaomiGateway==0.3.2: Command "c:\python36\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\2\\pip-build-xc8lxkpd\\pyCrypto\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\ADMINI~1\AppData\Local\Temp\2\pip-lqzoqhgo-record\install-record.txt --single-version-externally-managed --compile --user --prefix=" failed with error code 1 in C:\Users\ADMINI~1\AppData\Local\Temp\2\pip-build-xc8lxkpd\pyCrypto\e[0m

Is this fixable, or is it due to running on Windows?

Thanks

Please install “pycrypto” manually and/or google “pycrypto windows”.

Can anyone help with an issue I am having with the Xioami MiRobot Vacuum Ztoken

I have followed the instructions and getting a token the sqlite backup of the miHome app using IOS but I’m getting a token that is 96 characters and not 32.

I’ve tried the process multiple times and reconnect the vacuum using a new mi home app account but I still get a 96 character key?

I’ve got the gateway working in HA with lots of switches and sensors already, so not sure why I am running into this problem.

Thanks

Please follow this thread: Xiaomi Philips Light token problem - #12 by Noor_Eldin_Shashtari

It looks like the iOS app was updated recently and maybe the token is encrypted now. The token extracted from the android app is still 32 characters long. If you own an android device just give it a try and if you like: Please share the iOS token vs. the extracted android token. May be we can transform a 96 character token to a 32 character one some day.

can you help us to make backup from android and extract it please i tray adb backup but i cant extract it and where the backup save after make it on adb?

same problem

Wondering if anyone can help me with an issue I’m having with the Xiaomi Arqara wireless wall switch. For the life of me, I can’t get it working since my first few tests.

I have a simple automation set up that whenever the switch is clicked, it should toggle the light on /off. HA registers that there is a wall switch, but doesn’t seem to be able to pick up when the switch is being clicked. I’ve tried manually triggering the event, which toggles the event.

I’m suspicious that it may be the gateway that’s the issue. It’s version 1.4.1_149.0143 with the LAN protocol enabled. Completely stumped to what the issue is.

You hit this firmware issue: Aqara Wireless Switch(Double,not in wall) LEFT button FAILURE · Issue #8935 · home-assistant/core · GitHub

Thanks - I was able to get it from an android device.

Here’s an example of the 32 vs 96 character tokens

4a447a41467058496746505541597033 - android token

16a935db276e19b1c7bef0739f2deb7d3aca43c5e26a3c6445351cb2fb8495ea0143db63ee66b0cdff9f69917680151e - ios token

1 Like

Funny discovery: The last 32 char chunk of the 96 char token is always (for all users) the same: 0143db63ee66b0cdff9f69917680151e

If you AES-ECB encrypt an empty string with an empty password the result is 0143db63ee66b0cdff9f69917680151e. :stuck_out_tongue:

2 Likes

Yeay! I managed to decrypt the 96 character token:

# AES-ECB decrypt a 96 character iOS token -> valid 32 character token

from Crypto.Cipher import AES
import binascii
keystring = '00000000000000000000000000000000'
iostoken = '16a935db276e19b1c7bef0739f2deb7d3aca43c5e26a3c6445351cb2fb8495ea0143db63ee66b0cdff9f69917680151e'
key = bytes.fromhex(keystring)
cipher = AES.new(key, AES.MODE_ECB)
token = cipher.decrypt(bytes.fromhex(iostoken[:64]))
print(token)
# Output: b'4a447a41467058496746505541597033'
8 Likes

Hi there,

Is that Python code? Does it need the pycrypto library?

Thanks

Yes. pycrypto is a dependency of python-mirobo. If you are using python-mirobo already just switch to your virtualenv, start the python interpreter and write down the 8 lines of code and change the value of “iostoken”.

I do not know what python I am using. I installed home-assistant on virtual env following the installation guide. Do I need to install pycrypto?

Just switch to your home-assistant user (sudo su - homeassistant), enter the virtualenv (source /srv/homeassistant/bin/activate), execute python (python) and paste the code.

2 Likes

Hi again,

I had to install the pycrypto library before the interpreter could run your code.
What is that “b” at the start of the output string?

Thanks a lot in advance.

The “b” just indicates a byte-string. The important piece (token) is between the quotation marks.

1 Like

Thanks a lot. Did everything but still home assistant cannot see my Aqara gateway. Will have to double check.