Xiaomi Gateway Integration

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

Hi all,

First of all thank you for your work.

I’ve just tried to add the gateway on my homeassistant setup without results.

I’ve installed on my android the mi home app and flagged the voice in the menu for the gateway Password.
But when I try to save I receive an error message.

I’ve tried to add the gateway key on configuration.yaml file but I see and error (Xiaomi component don’t find) and no sensor is visible.

Your wifi network doesn’t have internet connection, and android is using the mobile data connection (look at the network icons on your screenshot).

The issue was present also at home (I was commuting when I’ve done the screenshot).

I solved the bind error unistallind and reinstalling the mi home app.

But I’m still unable to see xioami gateway on my HA dashboard.

This is the error that I see on my configuration tab:

Testing configuration at /home/homeassistant/.homeassistant
17-03-11 00:49:54 ERROR (MainThread) [homeassistant.loader] Unable to find component xiaomi
Failed config
General Errors:
- Component not found: xiaomi

This may be generated by an error on my config.yaml?

I mean maybe I’ve written the code wrong?

It appears like this:

xiaomi:
  - sid: lumigatewayv3_xxxxxxx
    gateways:
      key: xxxxxxx

Thank you in advance

Have you copied the component to the custom_components folder?

Yes.

This is what my folder looks like (so you che check if everything is ok):

I created a empy folder called “custom_components” and then copied the elements inside the file .zip .

Thank you

That is not correct.It should be custom_components/xiaomi.py, custom_components/sensor/xiaomi.py, …
Described here: https://github.com/lazcad/homeassistant#installation-raspberry-pi

Sorry. I change all and try again.

Thank you!

Hey guys,

trying to add a dimmer for my livingroom yeelight using the cube. Iam new to HASS, so please be patient :smiley:

Ok. My ~/.homeassistant/automation/lights/wohnzimmer_dimmer.yaml so far:

	#### AUTOMATION - LIGHTS - WOHNZIMMER - DIMMER ##################################

	alias: Wohnzimmer Licht DIMMER
	trigger:
	  platform: event
	  event_type: cube_action
	  event_data:
	    entity_id: binary_sensor.cube_158d00010d110b
	    action_type: rotate
	action:
	  service:
	    notify.telegramnofity
	  data:
	    title: Test
	    message: >
	      {{ trigger.event.data.action_value|float }}

For testing i just want to telegram the acton_value to my bot.
But i got this error:

Traceback (most recent call last):
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/template.py", line 99, in async_render
    return self._compiled.render(kwargs).strip()
  File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "<template>", line 1, in top-level template code
  File "/srv/homeassistant/lib/python3.4/site-packages/jinja2/sandbox.py", line 385, in getattr
    value = getattr(obj, attribute)
jinja2.exceptions.UndefinedError: 'trigger' is undefined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
    result = next(coro)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py", line 1001, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/notify/__init__.py", line 133, in async_notify_message
    kwargs[ATTR_MESSAGE] = message.async_render()
  File "/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/template.py", line 101, in async_render
    raise TemplateError(err)
homeassistant.exceptions.TemplateError: UndefinedError: 'trigger' is undefined

I realy dont know what i am doing wrong?

Is this your only automation? If not, express them as a list by prefixing “alias” with a -

- alias: Wohnzimmer Licht DIMMER
  trigger: .....

Also - it looks like you may have tabs instead of spaces. YAML cares about that. Set your text editor to use spaces instead of tabs.

Any one know if can i make the switch button on/off via ha?
As for now he just show on HA without to make anything.

Thanks!

MP

Hi,

edit: … for anyone reading that has the same problem, the solve is at the end of this post… :slight_smile:

I do not have an Apple device. I downloaded the app from here on Google Play, which is where the QR code in the Xiaomi box led me to. I’m failing to understand how to activate developer mode in this app.

All files are in /home/homeassistant/.homeassistant/custom_components … I have this device and two of these devices.

##config.yaml

...
xiaomi:
  gateways:
    - sid:
      key: xxxxxxxxxxxxxxxx
...

##log result

17-03-11 19:47:06 WARNING (Thread-6) [custom_components.xiaomi] Gateway Key is not provided. Controlling gateway device will not be possible.
17-03-11 19:47:21 ERROR (Thread-6) [custom_components.xiaomi] No gateway discovered
17-03-11 19:47:21 ERROR (MainThread) [homeassistant.bootstrap] component xiaomi failed to initialize

I don’t really care yet to control the gateway. The app in this link does not have the same UI as the app I am using. The gateway is set up and showing 2 connected devices in my app. I purchased and paired 2 door sensors.

Tapping on the gateway does nothing. Nothing in my settings panel helps me configure the gateway.

Thank you for any help you provide,

  • SN


SOLVE: Well this is pretty insane from a UX standpoint, but it looks like within the app, the Chinese Mainland option shows a completely different UI from the United States option. Changing my Locale to Chinese Mainland seemed to do the trick and solve my problem.

Hi Daniel,

I’ve done what you kindly suggest me.

Now It seems that I can load the custom component but I’m still unable to use the xiaomi gateway.

Below the error:

17-03-12 00:20:31 INFO (MainThread) [homeassistant.bootstrap] Setting up xiaomi
17-03-12 00:20:31 INFO (Thread-1) [custom_components.xiaomi] Expecting 1 gateways
17-03-12 00:20:31 INFO (Thread-1) [custom_components.xiaomi] Discovering Xiaomi Gateways (Try 1)
17-03-12 00:20:31 INFO (Thread-1) [custom_components.xiaomi] Xiaomi Gateway 286c0788ab7e found at IP 192.168.2.13
17-03-12 00:20:31 INFO (Thread-1) [custom_components.xiaomi] Discovering Xiaomi Devices
17-03-12 00:20:31 DEBUG (Thread-1) [custom_components.xiaomi] >> b'{"cmd" : "get_id_list"}'
17-03-12 00:20:31 DEBUG (Thread-1) [custom_components.xiaomi] << {'data': '["158d000159edf6","158d00015af2d3","158d0001584132","158d00010b2b6b","158d00011c7c9e"]', 'token': 't6sRYEBP8AJy9iwR', 'sid': '286c0788ab7e', 'cmd': 'get_id_list_ack'}
17-03-12 00:20:31 ERROR (MainThread) [homeassistant.bootstrap] Error during setup of component xiaomi
Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant_venv/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.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
17-03-12 00:20:31 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=title=Invalid config, notification_id=invalid_config, message=The following components and platforms could not be set up:
* [xiaomi](https://home-assistant.io/components/xiaomi/)
Please check your config, service=create, service_call_id=1978650448-1, domain=persistent_notification>
17-03-12 00:20:31 INFO (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: new_state=<state persistent_notification.invalid_config=The following components and platforms could not be set up:
* [xiaomi](https://home-assistant.io/components/xiaomi/)
Please check your config; title=Invalid config @ 2017-03-12T00:20:31.697242+01:00>, entity_id=persistent_notification.invalid_config, old_state=None>

Please notice that I’ve added the key from the Mi Home into the configuration.yaml

xiaomi:
  gateways:
    - sid: Xiaomi Gateway
      key: xxxxxxxxxxxxx

Thank you in advance

only work on zigbee version of power plug? how to control gateway light or radio, can’t see any gateway on frontend

The gateway light comes up in my system as Gateway Light_xxxxxxxxxxx, where I assume xxxxxxxx is unique to my device.

I haven’t seen any way of making the radio work with HASS, but there are ways to make it work wit your own music if you google.

1 Like

Thanks for your advice!

There are no tabs in the real config, i promise :smiley: Just needed to justify the code for the forum.

Yes, my automation files are splitted. I load them via !include_dir_list like discribed in the doku (https://home-assistant.io/docs/configuration/splitting_configuration/). So i belive i dont need “-”? In general the automations seem to work.

Anyway, why is my “trigger” undefined? In examples like Xiaomi Gateway Integration it seems to work?

Try using the MAC-adress of the gateway as SID (lowercase, no colon (double point)) or leave it empty. Check https://github.com/lazcad/homeassistant#installation-raspberry-pi