Xiaomi Gateway Integration

Yeah, I plan to do the same to a carbon monoxide detector: http://www.gearbest.com/smart-home/pp_157258.html
And am also considering a door bell.

Hey Guys,

can someone give me some hints? My configuration looks like this:

xiaomi:
gateways:

  • sid:
    key: cdfef84be0XXXXXX

and the result is the following:

17-03-21 20:59:41 INFO (Thread-3) [custom_components.xiaomi] Expecting 1 gateways
17-03-21 20:59:41 INFO (Thread-3) [custom_components.xiaomi] Discovering Xiaomi Gateways (Try 1)
17-03-21 20:59:42 INFO (Thread-3) [custom_components.xiaomi] Xiaomi Gateway f0b429ccXXXX found at IP 192.168.3.110
17-03-21 20:59:42 INFO (Thread-3) [custom_components.xiaomi] Discovering Xiaomi Devices
17-03-21 20:59:42 DEBUG (Thread-3) [custom_components.xiaomi] >> b’{“cmd” : “get_id_list”}’
17-03-21 20:59:42 DEBUG (Thread-3) [custom_components.xiaomi] << {‘token’: ‘jYaOutSrdInNXXXX’, ‘cmd’: ‘get_id_list_ack’, ‘sid’: ‘f0b429ccXXXX’, ‘data’: ‘[“158d000155XXXX”]’}
17-03-21 20:59:42 INFO (Thread-3) [custom_components.xiaomi] Found 2 devices
17-03-21 20:59:42 DEBUG (Thread-3) [custom_components.xiaomi] >> b’{“cmd”:“read”,“sid”:“158d000155XXXX”}’
17-03-21 20:59:42 DEBUG (Thread-3) [custom_components.xiaomi] << {‘token’: ‘oQvRLQZdEXXXXXX’, ‘cmd’: ‘get_id_list_ack’, ‘sid’: ‘f0b429ccXXXX’, ‘data’: ‘[“158d000155XXXX”]’}
17-03-21 20:59:42 ERROR (Thread-3) [custom_components.xiaomi] Non matching response. Expecting read_ack, but got get_id_list_ack
17-03-21 20:59:42 DEBUG (Thread-3) [custom_components.xiaomi] >> b’{“cmd”:“read”,“sid”:“f0b429ccXXXX”}’
17-03-21 20:59:42 DEBUG (Thread-3) [custom_components.xiaomi] << {‘token’: ‘jYaOutSrdIXXXXX’, ‘cmd’: ‘get_id_list_ack’, ‘sid’: ‘f0b429ccXXXX’, ‘data’: ‘[“158d000155XXXX”]’}
17-03-21 20:59:42 ERROR (Thread-3) [custom_components.xiaomi] Non matching response. Expecting read_ack, but got get_id_list_ack
17-03-21 20:59:47 INFO (Thread-3) [custom_components.xiaomi] Gateway finding finished in 5 seconds
17-03-21 20:59:47 INFO (Thread-3) [custom_components.xiaomi] Creating Multicast Socket
17-03-21 20:59:48 INFO (Thread-3) [custom_components.xiaomi] Listening for broadcast
17-03-21 21:29:02 DEBUG (Thread-16) [custom_components.xiaomi] MCAST (report) << {‘model’: ‘sensor_ht’, ‘data’: ‘{“temperature”:“2060”}’, ‘cmd’: ‘report’, ‘sid’: ‘158d000155XXXXX’, ‘short_id’: 27626}
17-03-21 21:29:02 DEBUG (Thread-16) [custom_components.xiaomi] MCAST (report) << {‘model’: ‘sensor_ht’, ‘data’: ‘{“humidity”:“5680”}’, ‘cmd’: ‘report’, ‘sid’: ‘158d000155XXXXX’, ‘short_id’: 27626}
17-03-21 21:29:02 DEBUG (Thread-16) [custom_components.xiaomi] MCAST (heartbeat) << {‘model’: ‘sensor_ht’, ‘data’: ‘{“temperature”:“2060”,“humidity”:“5680”}’, ‘cmd’: ‘heartbeat’, ‘sid’: ‘158d000155XXXXX’, ‘short_id’: 27626}

The first thing is to update to the latest firmware. This component only works with the latest firmware. And multicast will only be sent after you enable developer mode. Steps is all in the readme

No_motion after 2 minutes. A workaround is implemented to make it 1minute

Use Latest firmware my friend

Hi Rave, thanks for your answer. When I try to update it tells me I’m on the latest version, but most likly I have to read the readme file. Can you give me a link where this one is? I’m really new on this forum and I couldn’t find it. So it would help me if you can point out where I can find it. Thanks for your help

Read the first post in this thread and here https://github.com/lazcad/homeassistant

What version of the gateway do you have?
It needs to be a v2 gateway - v2 has radio capability.

Follow this procedure to enable Devmode, which enables the api;

Thanks, that I visit.
I have found out that my app on IOS is different from the one showed here

it has version 1.3.1_140

When I tried to update it told me:

I may have only one image in a post :slight_smile:

On the app there was a lot of chinese and finally I found out that the set locale to China was wrong, I changed it, could update to another version, could follow the guiding in https://github.com/lazcad/homeassistant

and now it works.
So everyone thanks for your help!

Glad you got it working.

Right, I tough it was after 1 minute. Anyway, you could pool it only when it is in “motion” state, and stop pooling and ignore heartbeats as soon as it stops being in “motion”.

I have the same Problem. Currently my version is 1.4.1_143.0141 and it tells my that this is the newest version. How did you change it ???

Hi Nico,

What is your problem at the moment exactly?
No update or also no multicast packets communicating on your network?

About the update:
My version was 1.3.1_140 and now it is updated to 1.4.1_143.0141.
My updated version is the same as yours, so from what I see I expect you have the latest version.

About the multicast packets:
I turned on IGMP-snooping on my router and that made together with the update that I now have communications with the sensors.

Hi,

okay, so my version seems not to be the problem. I guess my router is then the problem, duo to i had some issuces with nat-loopback and so. My output looks as this:
xiaomi:
gateways:

  • sid:
    key: cdfef84be0XXXXXX

and the result is the following:

17-03-21 20:59:41 INFO (Thread-3) [custom_components.xiaomi] Expecting 1 gateways
17-03-21 20:59:41 INFO (Thread-3) [custom_components.xiaomi] Discovering Xiaomi Gateways (Try 1)
17-03-21 20:59:42 INFO (Thread-3) [custom_components.xiaomi] Xiaomi Gateway f0b429ccXXXX found at IP 192.168.3.110
17-03-21 20:59:42 INFO (Thread-3) [custom_components.xiaomi] Discovering Xiaomi Devices
17-03-21 20:59:42 DEBUG (Thread-3) [custom_components.xiaomi] >> b’{“cmd” : “get_id_list”}’
17-03-21 20:59:42 DEBUG (Thread-3) [custom_components.xiaomi] << {‘token’: ‘jYaOutSrdInNXXXX’, ‘cmd’: ‘get_id_list_ack’, ‘sid’: ‘f0b429ccXXXX’, ‘data’: ‘[“158d000155XXXX”]’}
17-03-21 20:59:42 INFO (Thread-3) [custom_components.xiaomi] Found 2 devices
17-03-21 20:59:42 DEBUG (Thread-3) [custom_components.xiaomi] >> b’{“cmd”:“read”,“sid”:“158d000155XXXX”}’
17-03-21 20:59:42 DEBUG (Thread-3) [custom_components.xiaomi] << {‘token’: ‘oQvRLQZdEXXXXXX’, ‘cmd’: ‘get_id_list_ack’, ‘sid’: ‘f0b429ccXXXX’, ‘data’: ‘[“158d000155XXXX”]’}
17-03-21 20:59:42 ERROR (Thread-3) [custom_components.xiaomi] Non matching response. Expecting read_ack, but got get_id_list_ack
17-03-21 20:59:42 DEBUG (Thread-3) [custom_components.xiaomi] >> b’{“cmd”:“read”,“sid”:“f0b429ccXXXX”}’
17-03-21 20:59:42 DEBUG (Thread-3) [custom_components.xiaomi] << {‘token’: ‘jYaOutSrdIXXXXX’, ‘cmd’: ‘get_id_list_ack’, ‘sid’: ‘f0b429ccXXXX’, ‘data’: ‘[“158d000155XXXX”]’}
17-03-21 20:59:42 ERROR (Thread-3) [custom_components.xiaomi] Non matching response. Expecting read_ack, but got get_id_list_ack
17-03-21 20:59:47 INFO (Thread-3) [custom_components.xiaomi] Gateway finding finished in 5 seconds
17-03-21 20:59:47 INFO (Thread-3) [custom_components.xiaomi] Creating Multicast Socket
17-03-21 20:59:48 INFO (Thread-3) [custom_components.xiaomi] Listening for broadcast
17-03-21 21:29:02 DEBUG (Thread-16) [custom_components.xiaomi] MCAST (report) << {‘model’: ‘sensor_ht’, ‘data’: ‘{“temperature”:“2060”}’, ‘cmd’: ‘report’, ‘sid’: ‘158d000155XXXXX’, ‘short_id’: 27626}
17-03-21 21:29:02 DEBUG (Thread-16) [custom_components.xiaomi] MCAST (report) << {‘model’: ‘sensor_ht’, ‘data’: ‘{“humidity”:“5680”}’, ‘cmd’: ‘report’, ‘sid’: ‘158d000155XXXXX’, ‘short_id’: 27626}
17-03-21 21:29:02 DEBUG (Thread-16) [custom_components.xiaomi] MCAST (heartbeat) << {‘model’: ‘sensor_ht’, ‘data’: ‘{“temperature”:“2060”,“humidity”:“5680”}’, ‘cmd’: ‘heartbeat’, ‘sid’: ‘158d000155XXXXX’, ‘short_id’: 27626}

This will return a gateway light status if you’re on the latest firmware. Anyway, i don’t see anything wrong. What doesn’t work?

That’s the latest

Dont you see the errors??
17-03-21 20:59:42 ERROR (Thread-3) [custom_components.xiaomi] Non matching response. Expecting read_ack, but got get_id_list_ack

And i dont see the temperatur in the sensors view. Or do in need to manually define it as a snesor?

I’m as well having issues to get the gateway light work. All other sensors work just fine. Most likely I’m forgetting something stupid :slight_smile:

17-03-23 23:38:32 INFO (Thread-9) [custom_components.xiaomi] Xiaomi Gateway f0b429cc1edd found at IP 192.168.2.240

17-03-23 23:40:42 DEBUG (Thread-5) [custom_components.binary_sensor.xiaomi] Updating xiaomi motion sensor by polling
17-03-23 23:40:42 DEBUG (Thread-5) [custom_components.xiaomi] >> b'{ "cmd":"read","sid":"158d00012daedc"}'
17-03-23 23:40:42 DEBUG (Thread-5) [custom_components.xiaomi] << {'short_id': 37884, 'cmd': 'read_ack', 'sid': '158d00012daedc', 'model': 'motion', 'data': '{"status":"motion"}'}
17-03-23 23:40:42 DEBUG (Thread-5) [custom_components.xiaomi] PUSH >> <Entity Motion Sensor_158d00012daedc: on>: {'status': 'motion'}
17-03-23 23:40:42 DEBUG (Thread-5) [custom_components.binary_sensor.xiaomi] Checking for ghost
17-03-23 23:40:42 DEBUG (Thread-5) [custom_components.xiaomi] >> b'{ "cmd":"read","sid":"158d00012daedc"}'
17-03-23 23:40:42 DEBUG (Thread-5) [custom_components.xiaomi] << {'short_id': 37884, 'cmd': 'read_ack', 'sid': '158d00012daedc', 'model': 'motion', 'data': '{"status":"motion"}'}
17-03-23 23:40:42 DEBUG (Thread-5) [custom_components.xiaomi] PUSH >> <Entity Motion Sensor_158d00012daedc: on>: {'status': 'motion'}
17-03-23 23:40:42 INFO (MainThread) [homeassistant.core] Bus:Handling <Event motion[L]: entity_id=binary_sensor.motion_sensor_158d00012daedc>
17-03-23 23:40:42 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 1855472912: Received {'service_data': {'entity_id': 'light.gateway_light_f0b429cc1edd'}, 'service': 'turn_on', 'id': 9, 'type': 'call_service', 'domain': 'homeassistant'}
17-03-23 23:40:42 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=entity_id=light.gateway_light_f0b429cc1edd, service=turn_on, service_call_id=1980871632-1, domain=homeassistant>
17-03-23 23:40:42 INFO (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: service_data=entity_id=['light.gateway_light_f0b429cc1edd'], service=turn_on, service_call_id=1980871632-2, domain=light>
17-03-23 23:40:42 DEBUG (Thread-6) [custom_components.xiaomi] >> b'{"cmd": "write", "data": {"rgb": 3036676095, "key": "72577c858b44e94ab9040f7e25954c59"}, "sid": "f0b429cc1edd"}'
17-03-23 23:40:42 DEBUG (Thread-6) [custom_components.xiaomi] << {'cmd': 'write_ack', 'data': '{"error":"Invalid key"}', 'sid': 'f0b429cc1edd'}
17-03-23 23:40:42 ERROR (Thread-6) [custom_components.xiaomi] Got error element in data {"error":"Invalid key"}
17-03-23 23:40:42 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1980871632-2>
17-03-23 23:40:42 INFO (MainThread) [homeassistant.core] Bus:Handling <Event service_executed[L]: service_call_id=1980871632-1>
17-03-23 23:40:42 DEBUG (MainThread) [homeassistant.components.websocket_api] WS 1855472912: Sending {'result': None, 'id': 9, 'type': 'result', 'success': True}

Hello Guys,

I have a error when i using Xiaomi Platform , any hints ?

17-03-24 02:38:31 INFO (MainThread) [homeassistant.core] Bus:Handling <Event component_loaded[L]: component=sensor>
17-03-24 02:38:31 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/lib/python3.4/asyncio/tasks.py”, line 233, in _step
result = coro.throw(exc)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/setup.py”, line 60, in async_setup_component
return (yield from task)
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/asyncio/tasks.py”, line 237, in _step
result = next(coro)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/setup.py”, line 144, in _async_setup_component
component = loader.get_component(domain)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/loader.py”, line 141, in get_component
module = importlib.import_module(path)
File “/usr/lib/python3.4/importlib/init.py”, line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 2254, in _gcd_import
File “”, line 2237, in _find_and_load
File “”, line 2226, in _find_and_load_unlocked
File “”, line 1200, in _load_unlocked
File “”, line 1129, in _exec
File “”, line 1467, in exec_module
File “”, line 1572, in get_code
File “”, line 1532, in source_to_code
File “”, line 321, in _call_with_frames_removed
File “/home/homeassistant/.homeassistant/custom_components/xiaomi.py”, line 7

^
SyntaxError: invalid syntax