Xiaomi Gateway Integration

I’m sorry. This thread is a mix of various xiaomi products and questions. If you try to setup a xiaomi gateway you need a key and not a token!

The note is important for you: Xiaomi - Home Assistant

Please read the first paragraph of: Xiaomi - Home Assistant

And follow this tutorial: Xiaomi Gateway Integration - #1832 by pplucky

I have never ever had the ghost issue since first setting up my Xiaomi stuff. Home Assistant sends me alerts on my iPhone on mouvement when I’m away and I’ve never had a false alarm.

Hello!

im trying to get my Xiaomi GW to work with HA:

I can see it in HA but cannot control it. I have enabled Lan access and saved the password.

This is my config

xiaomi:
gateways:

  • mac: 00:90:7F:AA:2E:7B
    key: C0869E2REE51321R (This is not my real code, just an example)

I see this error in my log:

raise ValueError(“Incorrect AES key length (%d bytes)” % len(key))
ValueError: Incorrect AES key length (0 bytes)

Could that be something?

Try remove the “:” from mac address.
yesterday I got doorbell sound working and I did not have the ::::

There is something wrong with your key. Could you post the full call trace of your home-assistant.log and a proper formatted version of your configuration.yaml? The number of spaces matters. Is your key in upper-case? I hope not.

This is the log:

[homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.6/asyncio/tasks.py", line 181, in _step
    result = coro.throw(exc)
  File "/usr/lib/python3.6/site-packages/homeassistant/core.py", line 1025, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/light/__init__.py", line 279, in async_handle_light_service
    yield from light.async_turn_on(**params)
  File "/usr/lib/python3.6/asyncio/futures.py", line 331, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.6/asyncio/tasks.py", line 244, in _wakeup
    future.result()
  File "/usr/lib/python3.6/asyncio/futures.py", line 244, in result
    raise self._exception
  File "/usr/lib/python3.6/concurrent/futures/thread.py", line 55, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/light/xiaomi.py", line 97, in turn_on
    if self._write_to_hub(self._sid, **{self._data_key: rgbhex}):
  File "/usr/lib/python3.6/site-packages/PyXiaomiGateway/__init__.py", line 258, in write_to_hub
    data['key'] = self._get_key()
  File "/usr/lib/python3.6/site-packages/PyXiaomiGateway/__init__.py", line 288, in _get_key
    encryptor = AES.new(self.key.encode(), AES.MODE_CBC, IV=init_vector)
  File "/usr/lib/python3.6/site-packages/Crypto/Cipher/AES.py", line 202, in new
    return _create_cipher(sys.modules[__name__], key, mode, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/Crypto/Cipher/__init__.py", line 55, in _create_cipher
    return modes[mode](factory, **kwargs)
  File "/usr/lib/python3.6/site-packages/Crypto/Cipher/_mode_cbc.py", line 232, in _create_cbc_cipher
    cipher_state = factory._create_base_cipher(kwargs)
  File "/usr/lib/python3.6/site-packages/Crypto/Cipher/AES.py", line 92, in _create_base_cipher
    raise ValueError("Incorrect AES key length (%d bytes)" % len(key))
ValueError: Incorrect AES key length (0 bytes)

My config:

xiaomi:
  gateways:
   - mac: 00907FAA2E7B
     key: c0665e2dee33421d

I can see the controller, and if i manualy turn on the light it turns on in HA. But if I turn it on i HA nothing happends.
Yes it was in upper-case, did change that now. Still dont work

@hijinx I did have : tried too change it now, dident matter.

Where did you find your key? The key must be alphanumeric and is case-sensitive. It looks like the key is just wrong. Please follow this tutorial.

Yes I did follow that one.

That should be it right? Or im I at the wrong place?

This is perfect. Did you confirm the key?

How do I confirm the key?

First press refresh, the symbol next to the key. Write down the key and press “confirm” the button at the bottom.

Yes, i did that

I Will try again when the Champions Leauge game is over :slight_smile:

I see the upper-case token the first time today. This is how it looks like on android:

Hey guys, how do I use the Gateway Motion Sensor?
I can’t seem to find it anywhere?

The gateway has no (internal) motion sensor.

Woops, thought I read that somewhere :stuck_out_tongue:

There is a illumination sensor integrated, you can toggle the light and play some ringtones.

Just following your conversation, I’ve checked my key and mine is all uppercase and working fine - iOS user.

@Daniel_Gronlund is that the actual MAC of the gateway? 00:90:74 is owned by Watchgaurd, so assume you have some sort of Watchgaurd AP/Router?
I suspect you have entered the “gw_mac=” ? This is the MAC of your router, you need to use the “mac=” and it should start with 34:CE:00

1 Like

@garmck Yes thats correct, it was my Firewall. Its a WatchGuarx XTM 500 series.

I did change that now to the gateway, still same problem :frowning:

I did make some scens yesterday for the wireless button in HA, works very well. So i guess it does comunicate but just cant make any changes.