Xiaomi Gateway Integration

Does anybody have used 1.0.6 version of xiaomi protocol (availability to play sounds, illumination of gateway)?

At first, create a group in your config:

Sensors:
name: Sensoren
entities:
- sensor.motion_door
- sensor.garage_door

Include the group in your default view:

group:
default_view:
view: no
entities:
- group.sensors

Create the relevant templates and replace the binary sensors to your sensors:

sensor:

  • platform: template
    sensors:
    garage_door:
    value_template: “{% if is_state(‘binary_sensor.door_window_sensor_158d000XXXX’, ‘on’) %}Offen{% else %}Geschlossen{% endif %}”

  • platform: template
    sensors:
    motion_door:
    value_template: “{% if is_state(‘binary_sensor.motion_sensor_158d000XXXX’, ‘on’) %}Bewegung{% else %}Ruhe{% endif %}”

Customize the icons / names:

sensor.garage_door:
  friendly_name: Wohnungstür
  icon: mdi:glassdoor

sensor.motion_door:
  friendly_name: Bewegungsmelder
  icon: mdi:run

This should work for you…

Thorbeen Thannks!

So if i understand.

This line on groups.yaml ?

Sensors:
name: Sensoren
entities:

  • sensor.motion_door
  • sensor.garage_door

also this on groups.yaml ? or to customize.yaml?

group:
default_view:
view: no
entities:

  • group.sensors

this will be add to configuration.yaml?

platform: template
sensors:
garage_door:
value_template: “{% if is_state(‘binary_sensor.door_window_sensor_158d000XXXX’, ‘on’) %}Offen{% else %}Geschlossen{% endif %}”

Thanks!

For me , i have not split my config into single .xml / yaml files atm.

If you wish so,

Groups.yaml:

group:

default_view:
view: no
entities:

  • group.sensors

Sensors:
name: Sensoren
entities:

  • sensor.motion_door
  • sensor.garage_door

Configuration.yaml:

sensor:

platform: template
sensors:
garage_door:
value_template: “{% if is_state(‘binary_sensor.door_window_sensor_158d000XXXX’, ‘on’) %}Offen{% else %}Geschlossen{% endif %}”

platform: template
sensors:
motion_door:
value_template: “{% if is_state(‘binary_sensor.motion_sensor_158d000XXXX’, ‘on’) %}Bewegung{% else %}Ruhe{% endif %}”

Customize.yaml:

sensor.garage_door:
friendly_name: Wohnungstür
icon: mdi:glassdoor

sensor.motion_door:
friendly_name: Bewegungsmelder
icon: mdi:run

Please take care of the correct formatting as the code will not run otherwise.

Formatting like this:

For all other basic questions, please check the HAss Coockbook:

and especially example configs like the one of Daniel Hivesen which helped me a lot when I started a couple of weeks ago

1 Like

Use preformatted text when you post YAML.

1 Like

What’s that protocol version 1.06?

Started to recive that error, removing deps coldnt help

17-03-07 08:39:11 ERROR (MainThread) [homeassistant.bootstrap] Error during setup of component xiaomi
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.4/site-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, AES.MODE_CBC, IV=init_vector)
File “/srv/homeassistant/lib/python3.4/site-packages/Crypto/Cipher/AES.py”, line 264, in new
return _create_cipher(sys.modules[name], key, mode, *args, **kwargs)
File “/srv/homeassistant/lib/python3.4/site-packages/Crypto/Cipher/init.py”, line 130, in _create_cipher
return modes[mode](factory, **kwargs)
File “/srv/homeassistant/lib/python3.4/site-packages/Crypto/Cipher/_mode_cbc.py”, line 232, in _create_cbc_cipher
cipher_state = factory._create_base_cipher(kwargs)
File “/srv/homeassistant/lib/python3.4/site-packages/Crypto/Cipher/AES.py”, line 131, in _create_base_cipher
expect_byte_string(key)
File “/srv/homeassistant/lib/python3.4/site-packages/Crypto/Util/_raw_api.py”, line 175, in expect_byte_string
raise TypeError(“Only byte strings can be passed to C code”)
TypeError: Only byte strings can be passed to C code

@lotohov
Look at this pull request https://github.com/lazcad/homeassistant/pull/27/commits/577d52c6e541726b51a0befe160171baca694dc0
This solved my issue.
Edit this in your …/custom_component/xiaomi.py.

1 Like

what is your issue… ?

you are the best!! Thanks for try to help.

i get error about configure the groups, i need to play it to find what is the issue.

:slight_smile:

this extractly worked for me! big thx!

It’s so strange because i defined the version of pycrypto that needs to be installed which is 2.6.1 in the latest commit and that version should fixed this issue. I wonder how that’s possible

Do you still also have false positives? Have you tried to disable pooling?

Your doing a great job @rave.
Please have a look at https://bugs.launchpad.net/pycrypto/+bug/1084873. It is an old issue.
It seems that pycrypto ==2.6.1 is tested only using python version 2.1 through 3.3 - see https://pypi.python.org/pypi/pycrypto. Am I wrong? Is there an newer alternative for doing crypto in python?

1 Like

@rave Maybe be we should consider changing from pycrypto to pycryptodome?

A lot of people are struggling with pycrypto, and I think pycryptodome might be a better solution.
Anyone here that has tried pycryptodome?

1 Like

Hello @Stewface, maybe it’s a little later, but I had the same issues with home assistant not recognizing the xiaomi gateway. I have checked my router configuration and I have found that igmp snooping was activated in blocking mode. IGMP snooping is good when working with multicast, because it avoids flooding all the network and only resends multicast packages to the host that subscribes previously to that multicast. Not all the router has this functionality. My ISP in Spain uses video services over multicast, so this feature is a must, because without it, the WiFi connection will drop eventually.

So look for IGMP snooping option and try to change from blocking mode to standard mode, if you don’t have this option and you are not using multicast video on your network, you can deactivate IGMP Snooping, and the TP-Link should work withouth reseting it.

Yeah. Looks like a valid replacement. Let me test it out tonight

1 Like

@josepc - I gave troubleshooting that issue a HUGE nudge… It just plain doesn’t work on a TP-link Archer C2600.

Here is the IGMP settings I found - tested V2 and V3 the only options, IPTV mode didn’t really help and I couldn’t figure out the settings.

Unless your saying to disable the Proxy to get it working (although I remember it not working at all until I checked that…)

Anyway - I dusted off my 6 year old Linksys router and it solved the problem completely and now its running a dream.

IGMP Proxy and IGMP snooping have the same goal: reduce traffic replication over your network. If you don’t have multicast video services over your network, you can try to deactivate this option. For sure, this option is the one blocking multicast messages between the gateway and home assistant. It that doesn’t work, go for the Linksys :stuck_out_tongue:

1 Like