Xiaomi Gateway Integration

I get this

pi@raspberrypi:~ $ sudo su -s /bin/bash hass
hass@raspberrypi:/home/pi$ source /srv/hass/hass_venv/bin/activate
(hass_venv) hass@raspberrypi:/home/pi$ hass
Config directory: /home/hass/.homeassistant
INFO:homeassistant.core:Bus:Handling <Event service_registered[L]: service=turn_                                                   off, domain=homeassistant>
INFO:homeassistant.core:Bus:Handling <Event service_registered[L]: service=turn_                                                   on, domain=homeassistant>
INFO:homeassistant.core:Bus:Handling <Event service_registered[L]: service=toggl                                                   e, domain=homeassistant>
INFO:homeassistant.core:Bus:Handling <Event service_registered[L]: service=reloa                                                   d_core_config, domain=homeassistant>
INFO:homeassistant.core:Bus:Handling <Event service_registered[L]: service=creat                                                   e, domain=persistent_notification>
INFO:homeassistant.bootstrap:Home Assistant core initialized
INFO:homeassistant.loader:Loaded input_slider from homeassistant.components.inpu                                                   t_slider
INFO:homeassistant.loader:Loaded conversation from homeassistant.components.conv                                                   ersation
INFO:homeassistant.loader:Loaded updater from homeassistant.components.updater
INFO:homeassistant.loader:Loaded http from homeassistant.components.http
INFO:homeassistant.loader:Loaded history from homeassistant.components.history
INFO:homeassistant.loader:Loaded recorder from homeassistant.components.recorder
INFO:homeassistant.loader:Loaded camera from homeassistant.components.camera
INFO:homeassistant.loader:Loaded script from homeassistant.components.script
INFO:homeassistant.loader:Loaded group from homeassistant.components.group
INFO:homeassistant.loader:Loaded mqtt from homeassistant.components.mqtt
INFO:homeassistant.loader:Loaded climate from homeassistant.components.climate
INFO:homeassistant.loader:Loaded switch from homeassistant.components.switch
INFO:homeassistant.loader:Loaded automation from homeassistant.components.automa                                                   tion
Traceback (most recent call last):
  File "/srv/hass/hass_venv/bin/hass", line 11, in <module>
    sys.exit(main())
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/__main__.p                                                   y", line 380, in main
    exit_code = setup_and_run_hass(config_dir, args)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/__main__.p                                                   y", line 293, in setup_and_run_hass
    log_rotate_days=args.log_rotate_days)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/bootstrap.                                                   py", line 463, in from_config_file
    hass.loop.run_until_complete(future)
  File "/usr/lib/python3.4/asyncio/base_events.py", line 276, in run_until_compl                                                   ete
    return future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/bootstrap.                                                   py", line 454, in _async_init_from_config_file
    config_path, hass, verbose, skip_pip, log_rotate_days)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/bootstrap.                                                   py", line 496, in async_from_config_file
    config_dict, hass, enable_log=False, skip_pip=skip_pip)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/bootstrap.                                                   py", line 427, in async_from_config_dict
    for domain in loader.load_order_components(components):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/loader.py"                                                   , line 192, in load_order_components
    key=lambda order: 'group' in order):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/loader.py"                                                   , line 191, in <genexpr>
    for component in components),
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/loader.py"                                                   , line 211, in load_order_component
    return _load_order_component(comp_name, OrderedSet(), set())
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/loader.py"                                                   , line 220, in _load_order_component
    component = get_component(comp_name)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/loader.py"                                                   , line 139, in get_component
    module = importlib.import_module(path)
  File "/srv/hass/hass_venv/lib/python3.4/importlib/__init__.py", line 109, in i                                                   mport_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1467, in exec_module
  File "<frozen importlib._bootstrap>", line 1572, in get_code
  File "<frozen importlib._bootstrap>", line 1532, in source_to_code
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/home/hass/.homeassistant/custom_components/xiaomi.py", line 5
    <!DOCTYPE html>
    ^
SyntaxError: invalid syntax
^CException ignored in: <module 'threading' from '/usr/lib/python3.4/threading.py'>
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 1294, in _shutdown
    t.join()
  File "/usr/lib/python3.4/threading.py", line 1060, in join
    self._wait_for_tstate_lock()
  File "/usr/lib/python3.4/threading.py", line 1076, in _wait_for_tstate_lock
    elif lock.acquire(block, timeout):
KeyboardInterrupt
(hass_venv) hass@raspberrypi:/home/pi$

Nice, just ask if you have any problems.

I managed, I don’t know but if I download the file from github it will not download it correctly. I have to go and copy paste each file (until I discover why does that).

Now it boots, but have this error:

16-12-28 17:38:40 homeassistant.bootstrap: Setting up xiaomi
16-12-28 17:38:40 custom_components.xiaomi: Discovering Xiaomi Gateways
16-12-28 17:38:40 custom_components.xiaomi: Gateway found on IP 192.168.1.215
16-12-28 17:38:40 custom_components.xiaomi: Creating Multicast Socket
16-12-28 17:38:40 custom_components.xiaomi: Listening
16-12-28 17:38:40 custom_components.xiaomi: Discovering Xiaomi Devices
16-12-28 17:38:40 custom_components.xiaomi: Response does not match return cmd
16-12-28 17:38:40 homeassistant.bootstrap: Error during setup of component xiaomi
Traceback (most recent call last):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/bootstrap.py", line 151, 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/hass/.homeassistant/custom_components/xiaomi.py", line 44, in setup
    XIAOMI_HUB = XiaomiHub(key)
  File "/home/hass/.homeassistant/custom_components/xiaomi.py", line 113, in __init__
    self._discover_devices()
  File "/home/hass/.homeassistant/custom_components/xiaomi.py", line 119, in _discover_devices
    self.GATEWAY_TOKEN = resp["token"]
TypeError: 'NoneType' object is not subscriptable
16-12-28 17:38:40 homeassistant.loader: Loaded camera.generic from homeassistant.components.camera.generic
16-12-28 17:38:40 homeassistant.core: Bus:Handling <Event call_service[L]: service_data=title=Invalid config, message=The following components and platforms could not be set up:
* [xiaomi](https://home-assistant.io/components/xiaomi/)
Please check your config, notification_id=invalid_config, service_call_id=1977413680-7, domain=persistent_notification, service=create>
16-12-28 17:38:40 homeassistant.core: Bus:Handling <Event state_changed[L]: old_state=None, 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 @ 2016-12-28T17:38:40.571396+01:00>, entity_id=persistent_notification.invalid_config>
16-12-28 17:38:40 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=1977413680-7>

Did you turn on the developer mode as described in the link?

Hi there, did anyone noticed this error before?

i was able to set up everything and was quite happy setting up some automations, when, out of nothing all values become wacko.

see below:

on the mi home app is working fine, and tha automation i´ve made for the buttton works fine, but the values are completely strange. looking into the logs, there is no reference to errors. a snap of the details whitin HA page:

and

while doing the copy paste 1 sensor started to provide the right values

did anyone faced this?

this? yes

try now to change password and click ok (the password is the 16 characters in this window, correct?), change password in configuration and reboot

not sure if this helps, but when I move (touch) the broadlink RM pro which has a temperature sensor inside, it goes bananas and the temperature goes very high

naa, they are already set up quiet, and also the motion sensors and door sensor is always on, which should not be the case.

still errors

16-12-28 17:57:05 homeassistant.bootstrap: Setting up xiaomi
16-12-28 17:57:05 custom_components.xiaomi: Discovering Xiaomi Gateways
16-12-28 17:57:05 custom_components.xiaomi: Gateway found on IP 192.168.1.215
16-12-28 17:57:05 custom_components.xiaomi: Creating Multicast Socket
16-12-28 17:57:05 custom_components.xiaomi: Listening
16-12-28 17:57:05 custom_components.xiaomi: Discovering Xiaomi Devices
16-12-28 17:57:05 custom_components.xiaomi: Response does not match return cmd
16-12-28 17:57:05 homeassistant.bootstrap: Error during setup of component xiaomi
Traceback (most recent call last):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/bootstrap.py", line 151, 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/hass/.homeassistant/custom_components/xiaomi.py", line 44, in setup
    XIAOMI_HUB = XiaomiHub(key)
  File "/home/hass/.homeassistant/custom_components/xiaomi.py", line 113, in __init__
    self._discover_devices()
  File "/home/hass/.homeassistant/custom_components/xiaomi.py", line 119, in _discover_devices
    self.GATEWAY_TOKEN = resp["token"]
TypeError: 'NoneType' object is not subscriptable
16-12-28 17:57:05 homeassistant.loader: Loaded switch.broadlink from homeassistant.components.switch.broadlink
16-12-28 17:57:05 homeassistant.core: Bus:Handling <Event call_service[L]: domain=persistent_notification, service=create, service_call_id=1977983024-1, service_data=notification_id=invalid_config, title=Invalid config, message=The following components and platforms could not be set up:
* [xiaomi](https://home-assistant.io/components/xiaomi/)
Please check your config>
16-12-28 17:57:05 homeassistant.core: Bus:Handling <Event state_changed[L]: old_state=None, entity_id=persistent_notification.invalid_config, 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 @ 2016-12-28T17:57:05.363204+01:00>>
16-12-28 17:57:05 homeassistant.core: Bus:Handling <Event service_executed[L]: service_call_id=1977983024-1>
16-12-28 17:57:05 homeassistant.bootstrap: Setting up switch

Tried to install it on Ubuntu 16.04 using virtualenv. Put the files in the custom_components folder under /home/pi/.homeassistant/custom_components

Logging:

pi@HomeAssistant:~$ cat /home/hass/.homeassistant/home-assistant.log|grep xiaomi
16-12-28 19:27:52 homeassistant.bootstrap: Setting up xiaomi
16-12-28 19:27:52 custom_components.xiaomi: Discovering Xiaomi Gateways
16-12-28 19:28:02 homeassistant.bootstrap: Error during setup of component xiaomi
  File "/home/hass/.homeassistant/custom_components/xiaomi.py", line 160, in _send_socket
  File "/home/hass/.homeassistant/custom_components/xiaomi.py", line 44, in setup
  File "/home/hass/.homeassistant/custom_components/xiaomi.py", line 91, in __init__
  File "/home/hass/.homeassistant/custom_components/xiaomi.py", line 169, in _send_socket
* [xiaomi](https://home-assistant.io/components/xiaomi/)
* [xiaomi](https://home-assistant.io/components/xiaomi/)

ps: user is pi but I’m not on a raspberry but PC running Ubuntu.

Ok, fixed it. The xiaomi key in the config was incorrect. Works perfectly now !

any other hint on what/how troubleshoot?

@dquancey @nikonaum thanks for the links!

Personally I’ve ordered the 5 in 1 set from http://www.sunsky-online.com/product/default!view.do?subject.id=496900 + some additional sensors.

The hub can also be bought separate of course:
http://www.sunsky-online.com/view/468946/Original%20Xiaomi%20DGNWG02LM%20Intelligent%20Multifunctional%20Gateway%20Upgraded%20Version%20for%20Xiaomi%20Smart%20Home%20Suite%20Devices%20%20Support%20Android%204.0%20and%20IOS%207.0%20Above%20White%20.htm

GearBest is indeed cheaper, but this morning they where out of stock :unamused:

Btw looks like nearly every site has “big sales” but shops without sales are offering just a fraction higher price (1 or 2 dollar).

Hi, can anyone help me?

I can see all my switches, is there a way to simulate a click on a switch to be able to also use them from HA?
I’m searching for this functionality because those switches already turn on/off xiaomi lights so if I could simulate clicks and long presses I could also turn on/off those lights via automation on HA.

Thanks.

Regards,
JS

are you on firmware 1.4.1_142?

Do you mean you’re trying to turn on a xiaomi light which is automated by mi home app by triggering a button click using HA? Unfortunately not, the Zigbee switch is just a one way device. You can’t send a command to the switch

I’m using the latest firmware. Not sure what’s the error you’re having but i can put in more debugging code later today and try to log all the details

This Is using Wifi. So There’s no conflict. My plugin only works for the devices connected directly to the hub, aka Zigbee devices.

I might conbine it together but it’s more like a private project

no conflict, but both not working ahaha. The yeelight component has a bug (I am not alone having it), and yours also is not working for some obscure reason

The easiest way to check for conflct yourself is to take one out and see if the other one works