I enabled my multicast and am still having the same issue as well as spotty performance from the button.
Spotty performance could indicate a range/signal strength issue.
The presses register in the Mi Home app, but are not always making it to HA.
Got a multicast enabled router and got problems (startet other, already referenced Thread) with error message “{“error”:“Invalid key”}”
A fresh install and switching to a wired connection seems to have fixed my problems.
I tried the wired connection, I’ve also moved from virtualbox vm to pi3 with fresh installation. I’m still facing the same issue, “{“error”:“Invalid key”}”
Same issue for me.
After sniffing with ngrep, it seems that the key value is not the same (don’t know if it’s normal or not).
for example:
my config:
xiaomi_aqara:
gateways:
- host: 192.168.1.22
mac: 34ce00906b44
key: 1z2z3z4e5r7t8t9g
discovery_retry: 10
Ngrep result:
U 192.168.1.21:58712 -> 192.168.1.22:9898
{“cmd”: “write”, “sid”: “34ce00906b44”, “data”: {“rgb”: 3036676095, “key”: “500c501be3cac0351efbbf11e7e28943”}}
U 192.168.1.22:9898 -> 192.168.1.21:58712
{“cmd”:“write_ack”,“sid”:“34ce00906b44”,“data”:"{“error”:“Invalid key”}"}
Sid seems to be the good value whereas the key is not.
The key from the config is encrypted first:
https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/PyXiaomiGateway/init.py#L317
HA should receive a token from the gateway: https://github.com/Danielhiversen/PyXiaomiGateway/blob/master/PyXiaomiGateway/init.py#L170
If that is missing the encrypted key will be invalid.
Do you see any packages with token
?
No token in my traces.
Then you have the reason for the invalid key.
So you have to find what stops the packages to get from the gateway to HA.
Turn off the firewall and ensure your router supports multicast
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.
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
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
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?