Xiaomi gateway integration - help needed

Tested on my end, I’m using a totolink nr302 router with gateway connected wirelessly to router and pi over ethernet. Same issue invalid key. Anything else I can try?

Here is the trace:

U 192.168.1.21:35874 -> 192.168.1.22:9898
{“cmd”: “write”, “sid”: “34ce00906b44”, “data”: {“rgb”: 3036676095, “key”: “453cc0c71692ecde0474788b0f3c9da3”}}

U 192.168.1.22:9898 -> 192.168.1.21:35874
{“cmd”:“write_ack”,“sid”:“34ce00906b44”,“data”:"{“error”:“Invalid key”}"}

192.168.1.21 => HA
192.168.1.22 => Gateway Xiaomi

But you have received a package with the token during discovery of the gateway. Otherwise the gateway would not have shown up in HA:
https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/PyXiaomiGateway/init.py#L214

Could you try ngrep port 9898 and start it before you start HA?

You should see multicast packages like this:

U 192.168.1.206:4321 -> 224.0.0.50:9898
  {"cmd":"heartbeat","model":"gateway","sid":"XXXXXXXXXXXX","short_id":"0","token":"XXXXXXXXX","data":"{\"ip\":\"192.168.1.206\"}"}   

If you do not see these packages, I think there must be a network issue.

1 Like

Indeed, i can see the token when i restart:

U 172.17.0.3:60517 -> 192.168.1.22:9898
{“cmd” : “get_id_list”}

U 172.17.0.3:60517 -> 192.168.1.22:9898
{“cmd” : “get_id_list”}

U 192.168.1.21:60517 -> 192.168.1.22:9898
{“cmd” : “get_id_list”}

U 192.168.1.22:9898 -> 192.168.1.21:60517
{“cmd”:“get_id_list_ack”,“sid”:“34ce00906b44”,“token”:“ORMz9RvTpACmhCtw”,“data”:"[“158d0001ab1713”,“158d0001d62e82”,“158d0001d62f70”]"}

U 192.168.1.22:9898 -> 172.17.0.3:60517
{“cmd”:“get_id_list_ack”,“sid”:“34ce00906b44”,“token”:“ORMz9RvTpACmhCtw”,“data”:"[“158d0001ab1713”,“158d0001d62e82”,“158d0001d62f70”]"}

U 192.168.1.22:9898 -> 172.17.0.3:60517
{“cmd”:“get_id_list_ack”,“sid”:“34ce00906b44”,“token”:“ORMz9RvTpACmhCtw”,“data”:"[“158d0001ab1713”,“158d0001d62e82”,“158d0001d62f70”]"}

U 172.17.0.3:60517 -> 192.168.1.22:9898
{“cmd”:“read”,“sid”:“158d0001ab1713”}

U 172.17.0.3:60517 -> 192.168.1.22:9898
{“cmd”:“read”,“sid”:“158d0001ab1713”}

U 192.168.1.21:60517 -> 192.168.1.22:9898
{“cmd”:“read”,“sid”:“158d0001ab1713”}

Fyi, hass is in docker container.

It seems that you do not get any of the multicast packages.
So I think there is something with your network that blocks the multicast packages.

@wuns : Have you seen this? https://github.com/home-assistant/home-assistant/issues/8929#issuecomment-321887577
And this: https://github.com/home-assistant/home-assistant/issues/8355

Thank you @Danielhiversen.

My bad… I didn’t use --net=host for my docker run. Now it works!

1 Like

Could you add a note describing your solution to the docs?

In the upper right corner of any documentation page, you will find “Edit this page on GitHub”. Follow the link and submit your suggested change. Demonstrated here: https://youtu.be/dRfk9JAlPJk?t=1h16m17s

@Danielhiversen done.

2 Likes

Great.
But I can not find your pull request.
What is your github username?

My username is jvimont. I edit the github page and “Propose file change”.

Am i right?

You forgot the last step.
Go to https://github.com/home-assistant/home-assistant.github.io/compare/current...jvimont:patch-1
And press Create pull request

Great, I will merge your pull request when the tests are finished.

3 more pull requests in October, and you will get a free T-shirt: https://home-assistant.io/blog/2017/09/29/hacktoberfest/

Hey everyone is there a way to Activate/Control the RGB portion of the Gateway’s light? HASS only sees it as a Normal Light not a Colour Light.

Hi,

Ones you switched on light, then you can control brightness and colour.

When it’s off, then you can’t.

imagen

Hi @Danielhiversen. Thanks for the explanation. I ran the ngrep command and it seems those packages are also lost (results below). However, I have no idea how to fix it. I’m not using docker, I’m running HA on a Ubuntu Sever machine on Virtualbox. Any ideas? Thank you!

U 192.168.1.158:58941 → 192.168.1.190:9898
{“cmd” : “get_id_list”}

U 192.168.1.190:9898 → 192.168.1.158:58941
{“cmd”:“get_id_list_ack”,“sid”:“34ce008392d4”,“token”:“pYXWDM7yty4AbB38”,“data”:“["158d0001716fbc","158d0001228
96c","158d000183fa7a","158d0001225b3b","158d0001107e27","158d00016bfb96","158d000124408d"]”}

U 192.168.1.158:58941 → 192.168.1.190:9898
{“cmd”:“read”,“sid”:“158d0001716fbc”}

U 192.168.1.190:9898 → 192.168.1.158:58941
{“cmd”:“read_ack”,“model”:“plug”,“sid”:“158d0001716fbc”,“short_id”:7524,“data”:“{"voltage":3600,"status":"off
","inuse":"0","power_consumed":"240","load_power":"0.00"}”}

U 192.168.1.158:58941 → 192.168.1.190:9898
{“cmd”:“read”,“sid”:“158d000122896c”}

U 192.168.1.190:9898 → 192.168.1.158:58941
{“cmd”:“read_ack”,“model”:“motion”,“sid”:“158d000122896c”,“short_id”:33372,“data”:“{"voltage":3035,"status":"
motion"}”}

U 192.168.1.158:58941 → 192.168.1.190:9898
{“cmd”:“read”,“sid”:“158d000183fa7a”}

U 192.168.1.190:9898 → 192.168.1.158:58941
{“cmd”:“read_ack”,“model”:“magnet”,“sid”:“158d000183fa7a”,“short_id”:31442,“data”:“{"voltage":2995,"status":"
close"}”}

U 192.168.1.158:58941 → 192.168.1.190:9898
{“cmd”:“read”,“sid”:“158d0001225b3b”}

U 192.168.1.190:9898 → 192.168.1.158:58941
{“cmd”:“read_ack”,“model”:“switch”,“sid”:“158d0001225b3b”,“short_id”:10990,“data”:“{"voltage":3022}”}

U 192.168.1.158:58941 → 192.168.1.190:9898
{“cmd”:“read”,“sid”:“158d0001107e27”}

U 192.168.1.190:9898 → 192.168.1.158:58941
{“cmd”:“read_ack”,“model”:“cube”,“sid”:“158d0001107e27”,“short_id”:44228,“data”:“{"voltage":2975}”}

U 192.168.1.158:58941 → 192.168.1.190:9898
{“cmd”:“read”,“sid”:“158d00016bfb96”}

U 192.168.1.190:9898 → 192.168.1.158:58941
{“cmd”:“read_ack”,“model”:“switch”,“sid”:“158d00016bfb96”,“short_id”:4833,“data”:“{"voltage":3042}”}

U 192.168.1.158:58941 → 192.168.1.190:9898
{“cmd”:“read”,“sid”:“158d000124408d”}

U 192.168.1.190:9898 → 192.168.1.158:58941
{“cmd”:“read_ack”,“model”:“switch”,“sid”:“158d000124408d”,“short_id”:31253,“data”:“{"voltage":3022}”}

U 192.168.1.158:58941 → 192.168.1.190:9898
{“cmd”:“read”,“sid”:“34ce008392d4”}

U 192.168.1.190:9898 → 192.168.1.158:58941
{“cmd”:“read_ack”,“model”:“gateway”,“sid”:“34ce008392d4”,“short_id”:0,“data”:“{"rgb":0,"illumination":356,"pr
oto_version":"1.0.9"}”}

U 192.168.1.158:58941 → 192.168.1.190:9898
{ “cmd”:“read”,“sid”:“158d000122896c”}

U 192.168.1.190:9898 → 192.168.1.158:58941
{“cmd”:“read_ack”,“model”:“motion”,“sid”:“158d000122896c”,“short_id”:33372,“data”:“{"voltage":3035,"status":"
motion"}”}

U 192.168.1.158:58941 → 192.168.1.190:9898
{ “cmd”:“read”,“sid”:“158d000122896c”}

U 192.168.1.190:9898 → 192.168.1.158:58941
{“cmd”:“read_ack”,“model”:“motion”,“sid”:“158d000122896c”,“short_id”:33372,“data”:“{"voltage":3035,"status":"
motion"}”}

U 192.168.1.158:58941 → 192.168.1.190:9898
{ “cmd”:“read”,“sid”:“158d000122896c”}

U 192.168.1.190:9898 → 192.168.1.158:58941
{“cmd”:“read_ack”,“model”:“motion”,“sid”:“158d000122896c”,“short_id”:33372,“data”:“{"voltage":3035,"status":"
motion"}”}

U 192.168.1.158:58941 → 192.168.1.190:9898
{ “cmd”:“read”,“sid”:“158d000122896c”}

U 192.168.1.190:9898 → 192.168.1.158:58941
{“cmd”:“read_ack”,“model”:“motion”,“sid”:“158d000122896c”,“short_id”:33372,“data”:“{"voltage":3035,"status":"
motion"}”}

U 192.168.1.158:58941 → 192.168.1.190:9898
{ “cmd”:“read”,“sid”:“158d000122896c”}

U 192.168.1.190:9898 → 192.168.1.158:58941
{“cmd”:“read_ack”,“model”:“motion”,“sid”:“158d000122896c”,“short_id”:33372,“data”:“{"voltage":3035,"status":"
motion"}”}

U 192.168.1.158:58941 → 192.168.1.190:9898
{ “cmd”:“read”,“sid”:“158d000122896c”}

U 192.168.1.190:9898 → 192.168.1.158:58941
{“cmd”:“read_ack”,“model”:“motion”,“sid”:“158d000122896c”,“short_id”:33372,“data”:“{"voltage":3035,"status":"
motion"}”}

You can also create scripts to turn on the light to a specific color.

purple_night_light:
  alias: Purple
  sequence:
    - service: homeassistant.turn_on
      entity_id: light.gateway_light_34ce008d4aae
      data:
        brightness: 255
        rgb_color: [88,0,82]

white_night_light:
  alias: White
  sequence:
    - service: homeassistant.turn_on
      entity_id: light.gateway_light_34ce008d4aae
      data:
        brightness: 255
        rgb_color: [255,255,255]
1 Like

Are you using --net=host ?

Sorry, I have no idea about how to check it. Anyway, I’m not using Docker, so that shouldn’t be affecting me, right?

However, I’m starting to think that my router does not support multicast…

Thank you

I’ve also been struggling with getting Home Assistant to find my gateway. I’ve tried pretty much everything in the Troubleshooting section of the documentation, I just can’t verify if my router is allowing Multicast traffic. Not sure how to debug that. Any tips on that? I’m running Home Assistant using Hass.io.

UPDATE: I tried messing around with this library https://github.com/quibusus/node-xiaomi-smart-home and can see heartbeats and reports coming in, so I guess Multicast is working. However, there doesn’t seem to be any response from the gateway to the “whois” command that is send at the beginning.

I created an issue and will try to implement some logging to address multicast issues in future:

https://github.com/Danielhiversen/PyXiaomiGateway/issues/26