Xiaomi Gateway Integration

It Worked! THANK YOU!

Hey folks. Just got my V2 gateway from china (after a mishap receiving V1 GW) and want to get this baby installed.
I’m using docker for HA. Does anyone know if there is any guide to install custom components (or specifically the xiaomi component) with Docker?
I searched in this thread for “Docker” and from some posts in the thread (some of which are quite old) it appears that the approach is to hack the docker image to copy in the custom component.
Is this the way that HA needs this to be done? I was thinking it would be possible to map a volume instead (in same way that the config dir volume is mapped).
Any pointers gratefully received. Thanks!

hi all,

how to turn on the alarm of gateway with door sensor?

Thanks

Where do you have your configuration? You just need to place the component files in a folder named custom_components, which should be on the same directory of your HA config files.

Thanks @abmantis. That’s fantastic news. I saw a post from @rave mentioning it might be implemented but did see any follow to confirm.

Great. worked 1st time no messing about :slight_smile: I can see sensor events in the HA log :smiley:

This is what I did for Docker based install. (as sudoed user)
cd
mkdir custom_components
cd custom_components
sudo git clone https://github.com/lazcad/homeassistant

then I moved the contents of /custom_components/homeassistant/components back two dirs so that everything is in /custom_components… not sure if this is necessary, but the github readme says to copy all the files into the Home Assistant location/custome_components dir.

Before I buy, does anyone know if the Xiaomi Mi Smart Power Strip with 6 outlets (http://www.gearbest.com/plugs-sockets/pp_609502.html?wid=21) can be controlled via Home Assistant?

I know the single one can be.

as far as I can tell from the xiaomi mi app the answer is no.
These are the supported subdevices for the gateway:

1 Like

Hey Guys,

can someone help me please. Got a problem with getting it working:

I got the following messages:

17-03-13 20:39:01 ERROR (Thread-8) [custom_components.xiaomi] Non matching response. Expecting read_ack, but got get_id_list_ack
17-03-13 20:39:01 ERROR (Thread-8) [custom_components.xiaomi] Non matching response. Expecting read_ack, but got get_id_list_ack

I testet ihr with homebridge and it worked well. I do have the gateway and a temperatur sensor.
Currently i only have the key in my configuration. If i paste the mac as sid in it i got the following error:

17-03-13 20:46:17 ERROR (MainThread) [homeassistant.bootstrap] Error during setup of component xiaomi
Traceback (most recent call last):
File “/usr/local/lib/python3.4/dist-packages/homeassistant/bootstrap.py”, line 153, in _async_setup_component
None, component.setup, hass, config)
File “/usr/lib/python3.4/asyncio/futures.py”, line 388, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.4/asyncio/tasks.py”, line 286, in _wakeup
value = future.result()
File “/usr/lib/python3.4/asyncio/futures.py”, line 277, in result
raise self._exception
File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/homeassistant/.homeassistant/custom_components/xiaomi.py”, line 77, in setup
PY_XIAOMI_GATEWAY.discover_gateways()
File “/home/homeassistant/.homeassistant/custom_components/xiaomi.py”, line 167, in discover_gateways
self.gateways[ip_add] = XiaomiGateway(ip_add, port, sid, gateway_key, self._socket)
File “/home/homeassistant/.homeassistant/custom_components/xiaomi.py”, line 262, in init
if self._discover_devices():
File “/home/homeassistant/.homeassistant/custom_components/xiaomi.py”, line 271, in _discover_devices
self.update_key(resp[“token”])
File “/home/homeassistant/.homeassistant/custom_components/xiaomi.py”, line 370, in update_key
encryptor = AES.new(self.key.encode(), AES.MODE_CBC, IV=init_vector)
File “/home/homeassistant/.homeassistant/deps/Crypto/Cipher/AES.py”, line 95, in new
return AESCipher(key, *args, **kwargs)
File “/home/homeassistant/.homeassistant/deps/Crypto/Cipher/AES.py”, line 59, in init
blockalgo.BlockAlgo.init(self, _AES, key, *args, **kwargs)
File “/home/homeassistant/.homeassistant/deps/Crypto/Cipher/blockalgo.py”, line 141, in init
self._cipher = factory.new(key, *args, **kwargs)
ValueError: Key cannot be the null string

Make sure you are not running homebridge aqara. For the mac part, it should be

12 characters sid can be obtained from the gateway’s MAC address (in lowercase without semicolon).

I did stop homebridge and pasted the sid and key in as follows:

xiaomi:
gateways:

  • sid: e06066XXXXXX
    key: CDFEFXXXXXXXXXXX

Still the same:
17-03-13 20:46:17 ERROR (MainThread) [homeassistant.bootstrap] Error during setup of component xiaomi
Traceback (most recent call last):
File “/usr/local/lib/python3.4/dist-packages/homeassistant/bootstrap.py”, line 153, in asyncsetup_component
None, component.setup, hass, config)
File “/usr/lib/python3.4/asyncio/futures.py”, line 388, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.4/asyncio/tasks.py”, line 286, in _wakeup
value = future.result()
File “/usr/lib/python3.4/asyncio/futures.py”, line 277, in result
raise self._exception
File “/usr/lib/python3.4/concurrent/futures/thread.py”, line 54, in run
result = self.fn(*self.args, **self.kwargs)
File “/home/homeassistant/.homeassistant/custom_components/xiaomi.py”, line 77, in setup
PY_XIAOMI_GATEWAY.discover_gateways()
File “/home/homeassistant/.homeassistant/custom_components/xiaomi.py”, line 167, in discover_gateways
self.gateways[ip_add] = XiaomiGateway(ip_add, port, sid, gateway_key, self._socket)
File “/home/homeassistant/.homeassistant/custom_components/xiaomi.py”, line 262, in init
if self.discoverdevices():
File “/home/homeassistant/.homeassistant/custom_components/xiaomi.py”, line 271, in discoverdevices
self.update_key(resp[“token”])
File “/home/homeassistant/.homeassistant/custom_components/xiaomi.py”, line 370, in update_key
encryptor = AES.new(self.key.encode(), AES.MODE_CBC, IV=init_vector)
File “/home/homeassistant/.homeassistant/deps/Crypto/Cipher/AES.py”, line 95, in new
return AESCipher(key, *args, **kwargs)
File “/home/homeassistant/.homeassistant/deps/Crypto/Cipher/AES.py”, line 59, in init
blockalgo.BlockAlgo.init(self, _AES, key, *args, **kwargs)
File “/home/homeassistant/.homeassistant/deps/Crypto/Cipher/blockalgo.py”, line 141, in init
self._cipher = factory.new(key, *args, **kwargs)
ValueError: Key cannot be the null string

@rave Thanks for this software - it’s working great for me so far! Bought you a beer. Enjoy! :beers:

2 Likes

Check the indentation of the key. Make sure it is the same line as sid. Also, key looks strange. It should be all lowercase if i remembers correctly

I think the indentation looks good. Also i used the same key and sid for homebridge and everythin works good from within siri/homekit:

HA:

Homebridge-config:

Screen from homekit:

Someone any ideas??

please respond. thanks

Currently managing alarm, getting battery status, managing radio is not supported by HASS component.
Xiaomi should open API first, than push FW update to our Gateways.

1 Like

please mind your manners, thanks.

please and thanks isn’t a good manners ???