Danielhiversen / PyXiaomiGateway

PyXiaomiGateway
MIT License
152 stars 55 forks source link

Add support for WXKG06LM (remote.b186acn02) #186

Closed fabricepipart closed 4 years ago

fabricepipart commented 4 years ago

Even with the latest version of Home Assistant (0.115.3) which uses PyXiaomiGateway version 0.13.2, the support of Aqara D1 Wireless Remote Switch (Single Rocker) (WXKG06LM) (lumi.remote.b186acn02) still does not work. On startup you get:

Logger: xiaomi_gateway
Source: /usr/local/lib/python3.8/site-packages/xiaomi_gateway/__init__.py:309 
First occurred: 14:21:51 (3 occurrences) 
Last logged: 14:21:51

Unsupported device found! Please create an issue at https://github.com/Danielhiversen/PyXiaomiGateway/issues and provide the following data: {'cmd': 'read_ack', 'model': 'remote.b186acn02', 'sid': '158d0005441db0', 'short_id': 1075, 'data': '{"voltage":3115}'}
Unsupported device found! Please create an issue at https://github.com/Danielhiversen/PyXiaomiGateway/issues and provide the following data: {'cmd': 'read_ack', 'model': 'remote.b186acn02', 'sid': '158d00054418a2', 'short_id': 16642, 'data': '{"voltage":3115}'}
Unsupported device found! Please create an issue at https://github.com/Danielhiversen/PyXiaomiGateway/issues and provide the following data: {'cmd': 'read_ack', 'model': 'remote.b186acn02', 'sid': '158d0005220048', 'short_id': 4530, 'data': '{"voltage":3145}'}

I think this model has just been forgotten when those two commits were made: https://github.com/Danielhiversen/PyXiaomiGateway/commit/88699a2ea3f06f258ed644f7acb9836df5e24249 and https://github.com/Danielhiversen/PyXiaomiGateway/commit/f0742e12747d44ba353ba740bf796fadcbbae420

On the other side, it seems to be correctly referenced on HA side: https://github.com/home-assistant/core/commit/3fc5f9deb82e855d69aa7001df96c5820a62554c

Fixes #185

fabricepipart commented 4 years ago

This is my first contribution I just took inspiration from previous contributions. I do not even know how to validate locally on my HA installation that it fixes the issue. Any indication would be helpful

syssi commented 4 years ago

Could you try to capture some network traffic to make sure the device provides event data if you press the button?

fabricepipart commented 4 years ago

If you have any instruction to do so, I can do all the tests you need. The Home Assistant log that I joined does not show the event that is triggered?

What do you mean exactly by event? The payload of the xiaomi_aqara.click event that HA receives? Or you want me to sniff my network? ie the network communication between the Gateway and HA? I am not used to do that kind of thing but just indicate what kind of command line you would use and I'll find a way (I am on Mac and not shy to use the Terminal).

Is there any way for me to modify my local installation in order to test the modification?

syssi commented 4 years ago

You could install ngrep on your HA host and capture the incoming udp traffic of the gateway by

# 192.168.132.3 is the ip address of the xiaomi aqara gateway
ngrep -l -q udp and host 192.168.132.3

The output should look like this:

U 192.168.132.2:54560 -> 192.168.132.3:9898
  {"data": {"mid": 10001, "vol": 1, "key": "7f8d38bf2f1367ecbe0f3a0c67eb8936"}, "cmd": "write", "sid": "34ce0088db0b"}                                                           

U 192.168.132.3:9898 -> 192.168.132.2:54560
  {"cmd":"write_ack","sid":"34ce0088db0b","data":"{\"error\":\"Invalid key\"}"}                                                                                                  

U 192.168.132.2:54560 -> 192.168.132.3:9898
  {"cmd" : "get_id_list"}                                                                                                                                                        

U 192.168.132.3:9898 -> 192.168.132.2:54560
  {"cmd":"get_id_list_ack","sid":"34ce0088db0b","token":"Imt6Sb7zCBInddjX","data":"[...]"}                                                                                                                                                            

U 192.168.132.2:54560 -> 192.168.132.3:9898
  {"data": {"mid": 10001, "vol": 1, "key": "b89fc354c108ef90849ddebee2268a81"}, "cmd": "write", "sid": "34ce0088db0b"}                                                           

U 192.168.132.3:9898 -> 192.168.132.2:54560
  {"cmd":"write_ack","model":"gateway","sid":"34ce0088db0b","short_id":0,"data":"{\"rgb\":1694498815,\"illumination\":1292,\"proto_version\":\"1.0.9\"}"}                        

Push the button of your remote.b186acn02 to generate some events. Please provide all packets which contain the string "remote.b186acn02".

fabricepipart commented 4 years ago

I'll try to do that tomorrow. Thanks for the hints showing me how to do that 👍

fabricepipart commented 4 years ago

I struggled but I got it. For the record, here is how I did it:

And I got:

U 192.168.1.36:4321 -> 224.0.0.50:9898 #3
  {"cmd":"report","model":"remote.b186acn02","sid":"thebuttonsid","short_id":1075,"data":"{\"channel_0\":\"click\"}"}