Xiaomi Gateway Integration

You should read these two pages; https://home-assistant.io/components/group/ and https://home-assistant.io/components/sensor.template/

1 Like

Will post parts of my config as an example for groups and sensors (templates as well) after work…

1 Like

I have the same problem, and it’s not just false srabatyvaeniya. The sensor itself works and does not change its status until it is changed by the sensor

Wow Big Big Thanks!

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