dresden-elektronik / deconz-rest-plugin

deCONZ REST-API plugin to control ZigBee devices
BSD 3-Clause "New" or "Revised" License
1.9k stars 502 forks source link

Xiaomi Aqara wall switch #543

Closed 1968-Larry closed 5 years ago

1968-Larry commented 6 years ago

I tried to get one dual wall switch to work but it seems not working. With Phoscon App I can see the switch connected as Vendor LUMI/Product Transmitter 2-gang. But when I look at Groups it doesn't show? I'm not sure what information I need to give you but I can donate a button. I think it's faster for you than try to explain all steps to get correct information.

mathos77 commented 6 years ago

@1968-Larry

Please see https://github.com/dresden-elektronik/deconz-rest-plugin/issues/356

@manup I suggest to close this issue.

ebaauw commented 6 years ago

This is not an in-wall switch, wired to the electricity, but a battery-powered switch that looks like a wall switch. Please keep this issue open.

1968-Larry commented 6 years ago

Moving my report here: I have upgraded to latest package available, removed the switches in pwa and database and tried to connect it back to the network. It's paired and I can see it in pwa/device/switches but I can't use it in groups. I tried to read /api/apikey/switches and it's missing. I got this in the database: "3549" "5" "lumi.sensor_86sw2 5" "ZHASwitch" "lumi.sensor_86sw2" "LUMI" "00:15:8d:00:01:e0:75:db-01-0006" "" "{""buttonevent"":null,""lastupdated"":null}" "{""battery"":null,""on"":true,""reachable"":true,""temperature"":null}" "{""d"":65535,""ep"":1,""in"":[0,6],""p"":260}" "normal" "1"

I could give you more information if you know what to look for.

ebaauw commented 6 years ago

That looks good to me. Does state.buttonevent change value when you press a button?

These switches use attribute reporting instead of commands to change associated lights or groups. They don’t work standalone, without a gateway. You need gateway rules to change the lights or group when state.buttonevent is updated. Consequently, config.group is missing, just like for my Xioami switches: lumi.sensor_switch.aq2, lumi.cube, and lumi.ctrl_ln2.aq1.

Don’t think PWA yet supports creating the needed rules.

1968-Larry commented 6 years ago

I'm not sure what to look at but I think it's always: {"buttonevent":null,"lastupdated":"none"} Could I add the rules in database?

ebaauw commented 6 years ago

I'm not sure what to look

Best use the REST API, doing a GET of /sensors/5. The database only updates periodically and when deCONZ exits.
Using ph from my homebridge-hue-utils, you'd simply do:

$ ph get /sensors/115
{
  "config": {
    "battery": 100,
    "on": true,
    "reachable": true,
    "temperature": 2300
  },
  "ep": 1,
  "etag": "ea5af57630320ec809e4f39b75b92e92",
  "manufacturername": "LUMI",
  "mode": 1,
  "modelid": "lumi.sensor_switch.aq2",
  "name": "Entrance Switch",
  "state": {
    "buttonevent": 1002,
    "lastupdated": "2018-04-22T05:07:30"
  },
  "swversion": "3000-0001",
  "type": "ZHASwitch",
  "uniqueid": "00:15:8d:00:01:a6:6f:3a-01-0006"
}

Could I add the rules in database?

Best create rules through the REST API. They'll be stored in the database, but the API provides some sanity checks.

1968-Larry commented 6 years ago

Nothing happens when I press the buttons: { "config": { "battery": 100, "on": true, "reachable": false, "temperature": 2600 }, "ep": 1, "etag": "996e9ed6567e3b88da0ad87ee3f4ebce", "manufacturername": "LUMI", "mode": 1, "modelid": "lumi.sensor_86sw2", "name": "lumi.sensor_86sw2 5", "state": { "buttonevent": null, "lastupdated": "none" }, "type": "ZHASwitch", "uniqueid": "00:15:8d:00:01:e0:75:db-01-0006" }

ebaauw commented 6 years ago

Can some-one please post the screenshots for the lumi.sensor_86sw1 and the lumi.sensor_86sw2 of:

And check which endpoints/clusters/attributes change when (single, double, triple, long) pressing the buttons?

And list what /sensors resource(s) is/are created in the REST API?

Thanks.

DB-Alex commented 6 years ago

@ebaauw I believe this information is in issue:

https://github.com/dresden-elektronik/deconz-rest-plugin/issues/356

ebaauw commented 6 years ago

No, those are the wired in-wall switches (lumi.ctrl_neutral and lumi.ctrl_ln), not the wireless switches that look like wall switches.

1968-Larry commented 6 years ago

I hope this is right.

image image image

ebaauw commented 6 years ago

Thanks, @1968-Larry

Could you please:

ebaauw commented 6 years ago

Reference: https://github.com/dresden-elektronik/deconz-rest-plugin/issues/165#issuecomment-348329845

Same (?) switch, but different clusters and device IDs?!

1968-Larry commented 6 years ago

@ebaauw will try to night, I can't reach the button from here :) If you send me your address I could send one to you.

ebaauw commented 6 years ago

If you send me your address I could send one to you.

If you could loan me one, that would be brilliant. Can I contact you by email, to send my address?

1968-Larry commented 6 years ago

I added a public email to my github account.

ebaauw commented 6 years ago

@1968-Larry I just received the switch, thank you!

It's a lumi.sensor_86sw2. Pairing was straightforward, just hold both buttons for a couple of seconds (until the LEDs start blinking) to reset the switch. Indeed the same endpoints and clusters above. Did the manual reading of the Basic attributes. Indeed, when pressing a button, none of the clusters show any values in the deCONZ GUI, so time for some serious ZigBee sniffing.

When pressing the left button, the switch sends an attribute report for endpoint 01, cluster 0x0006 (OnOff). For the right button, it's endpoint 02; for both buttons, endpoint 03. The report contains the 0x0000 (OnOff) attribute twice (!), first with value On, second with value Off. The deCONZ GUI is confused by this: it briefly shows the attributes greyed (as in not supported) and then shows them normal. But never value true for OnOff.

The switch doesn't seem to support anything but press/release. On double press, it just issues two reports.

The REST API created a ZHASwitch resource (as expected):

  {
    "config": {
      "battery": 100,
      "on": true,
      "reachable": true,
      "temperature": 2800
    },
    "ep": 1,
    "etag": "2deee4ed1558746be9161d692babab23",
    "manufacturername": "LUMI",
    "mode": 1,
    "modelid": "lumi.sensor_86sw2",
    "name": "lumi.sensor_86sw2 7",
    "state": {
      "buttonevent": 3002,
      "lastupdated": "2018-05-11T14:09:21"
    },
    "swversion": "3000-0001",
    "type": "ZHASwitch",
    "uniqueid": "00:15:8d:00:01:e0:75:d6-01-0006"
  }

As you can see, I'm receiving buttonevents (?!). I did some cleanup of the code before receiving the sensor, but nothing (as far as I'm aware) to change the discovery. Need to do some more testing. Anyways buttonevent 1002 for the left button, 2002 for the right, and 3002 for both. One event per press/release.

I'm also receiving Xiaomi magic reports, as you can see from the config values, and confirmed in the deCONZ log:

May 11 15:55:05 pi1 deCONZ[15882]: 15:55:02:234 APS-DATA.indication srcAddr: 0x00158d0001e075d6, dstAddrMode: 2, profile: 0x0104, cluster: 0x0000, lqi: 255, rssi: -40
May 11 15:55:05 pi1 deCONZ[15882]: 15:55:02:234 ZCL attribute report 0x00158D0001E075D6 for cluster 0x0000, ep 0x01 
May 11 15:55:05 pi1 deCONZ[15882]: 15:55:02:234         payload: 01ff421f0121db0b03281a0421a8010521130006240100000000082105140a211d95
May 11 15:55:05 pi1 deCONZ[15882]: 15:55:02:234 0x00158D0001E075D6 extract Xiaomi special 
May 11 15:55:05 pi1 deCONZ[15882]: 15:55:02:234         01 battery 3035 (0x0BDB)
May 11 15:55:05 pi1 deCONZ[15882]: 15:55:02:234         03 temperature 26 °C
May 11 15:55:05 pi1 deCONZ[15882]: 15:55:02:234         04 unknown 424 (0x01A8)
May 11 15:55:05 pi1 deCONZ[15882]: 15:55:02:234         05 unknown 19 (0x0013)
May 11 15:55:05 pi1 deCONZ[15882]: 15:55:02:234         06 unknown 4294967296 (0x0000000100000000)
May 11 15:55:05 pi1 deCONZ[15882]: 15:55:02:234         08 unknown 5125 (0x1405)/
ebaauw commented 6 years ago

Hm. Re-installed v0.05.25. Deleted sensor resource from database, reset sensor, deleted node from deCONZ GUI and paired the sensor again. This time, it only shows Basic and OnOff clusters on endpoint 01, and OnOff on endpoint 03. When pressing the left button, endpoint 02 appears, also with only OnOff cluster. Device ID is now 0xffff for all endpoints.

Again, after pressing a button (to wake the switch) and manually reading the Basic cluster attributes, the ZHASwitch sensor resource is created, and, again, I'm getting buttonevents.

ebaauw commented 6 years ago

Take 3. This time, I'm getting some light resources (?!). Probably because of the 0xffff device types deCONZ confuses it for a lumi.ctrl_neutral.

{
  "3": {
    "etag": "53f2002e30c1c7aac7f6d58432c6cd49",
    "hascolor": false,
    "manufacturername": "Unknown",
    "modelid": null,
    "name": "Light 3",
    "state": {
      "alert": "none",
      "on": false,
      "reachable": true
    },
    "swversion": null,
    "type": "Smart plug",
    "uniqueid": "00:15:8d:00:01:e0:75:d6-03"
  },
  "4": {
    "etag": "53f2002e30c1c7aac7f6d58432c6cd49",
    "hascolor": false,
    "manufacturername": "Unknown",
    "modelid": null,
    "name": "Light 4",
    "state": {
      "alert": "none",
      "on": false,
      "reachable": true
    },
    "swversion": null,
    "type": "Smart plug",
    "uniqueid": "00:15:8d:00:01:e0:75:d6-02"
  }
}

No matter what I try, the Basic attributes won't be read. Somehow, deCONZ got the Model Identifier already, and created the sensor resource (note: no swversion this time):

{
  "config": {
    "battery": 100,
    "on": true,
    "reachable": true,
    "temperature": 2900
  },
  "ep": 1,
  "etag": "f8f7e6fa2091cb647bde1845aeca3089",
  "manufacturername": "LUMI",
  "mode": 1,
  "modelid": "lumi.sensor_86sw2",
  "name": "lumi.sensor_86sw2 7",
  "state": {
    "buttonevent": 2002,
    "lastupdated": "2018-05-11T15:01:50"
  },
  "type": "ZHASwitch",
  "uniqueid": "00:15:8d:00:01:e0:75:d6-01-0006"
}

Again, I'm receiving buttonevents and Xiaomi magic reports.

ebaauw commented 6 years ago

Take 4. Reset the switch, removed the node, shutdown deCONZ, reset the RaspBee, power-cycled the only other device (on my test network), removed the light and sensor resources from the database, and once again paired the switch. This time is comes back with the full endpoints and clusters, but the OnOff clusters only appear on the corresponding button action. Device IDs on endpoints 02 and 03 are 0x5f02 and 0x5f03, so no lights this time. Again the sensor resource is created and I do get buttonevents.

@manup, I don't know how the node's endpoints and clusters can differ, but it would seem that the light discovery and the sensor discovery interfere with each other. I think the current implementation of light discovery for battery-powered end devices is cursed (mea culpa) and we better create the light resources from addSensorNode(), when we know the Model Id. We could simply whitelist the endpoints and as added benefit, update the manufacturername and modelid the same way we do for sensor resources.

lubbertkramer commented 6 years ago

Here also problems with the single/double which are added with only a battery sensor but visible under switch @ deconz. I am a Homey switcher to HASS but at Homey there is also a Xiaomi Zigbee app which supports the wirelss single/double switch maybe there can be found some more intel on how to do it? -> https://github.com/TedTolboom/com.xiaomi-mi-zigbee

In the entitiy yaml i now only see a sensor and no switch like i should expect: sensor.lumisensor_86sw2_9_battery_level: name: platform: deconz unique_id: 00:15:8d:00:01:71:2d:3e-01-0006

sensor.lumisensor_86sw1_2_battery_level: name: platform: deconz unique_id: 00:15:8d:00:01:3f:f7:ce-01-0006

I use the models WXKG03LM (Single) and the WXKG02LM (Double)

Log information 16:34:51:649 GW firmware version: 0x261f0500 16:34:51:649 GW firmware version is up to date: 0x261f0500 16:35:32:325 no button map for: lumi.sensor_86sw2 cl: 0x0006 cmd: 0x0A pl[0]: 000 capture

saurabh984 commented 6 years ago

Hi Erik,

Let me know if you need any help debugging this. WXKG02LM & WXKG03LM both work for me using deCONZ v2.05.27

It took several attempts to get them to join, report correct attributes, device ids and be reported by the REST API. I found that resetting them first by pressing the button for >5 seconds after removing and reinserting the battery had better results.

After doing the reset cycle I added them again by opening the network and pressing the button for 5 seconds.

WXKG02LM hasn't had any config reports yet so getting battery info etc as null. It was reporting when I paired it the first time.

Another strange observation - A brand new unpaired switch seems to work the very first time (after pressing the buttons to get the ZHASwitch Resource created). If any attempt to re-pair or reset then these are an absolute nightmare!

Hope it helps!

fillwe commented 6 years ago

Hey guys i just bought both a WXKG02LM & WXKG03LM. After 4 hours i still havent been able to add any of them to Deconz. I have tried your method with restoring saurabh984, replacing the battery and moving it really close to the Conbee, 50 cm but with no luck :( Any time i hold in the button, it will stay unlit for about 7 seconds, then both leds just starts flashing 6 times, then nothing, have waited for it to pair but with no result. Any ideas?:( Running on Hass.io with version 2.05.35

zilluss commented 6 years ago

@fillwe Have you been able to connect the switch? I'm on the latest version and can't connect it either. I'm currently considering switching to a CC2531/Zigbee2MQTT based system but I'm not sure if I'm simply doing something wrong while trying to connect the switch.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.