WebThingsIO / zigbee-adapter

Zigbee adapter add-on for WebThings Gateway
Mozilla Public License 2.0
46 stars 29 forks source link

workaround to enable Scenes on TRADFRI 5 button remote #229

Closed chas-iot closed 3 years ago

chas-iot commented 4 years ago

an inline comment on this change is too long. I left it that way as I am uncertain of the preferred way to comment this kind of work-around. Please feel free to edit the PR or suggest how I should change the comment. As far as I can tell, the latest remote from IKEA is either abusing the spec or, more likely, has a bug where '0005' ( = GENSCENES ) is missing from the output clusters. As this is the first time I've looked into this area, I may well be missing something significant.

chas-iot commented 4 years ago

resolves https://github.com/mozilla-iot/zigbee-adapter/issues/199

davehylands commented 4 years ago

In order to make this generic, you'll probably have to detect the specific Ikea device (in the classifier) and set a flag that then gets processed. I haven't played with scenes at all, assuming that the gateway would be used to provide this functionality.

chas-iot commented 4 years ago

@davehylands both the earlier model and the new E1810 model both share node.modelId === 'TRADFRI remote control' in zb-classifier.js and the patch is inside a check for this. Is there some other layer that I should search to see if the more specific model is exposed?

davehylands commented 4 years ago

I think we store all of the relevant fields (that might be used for identificiation) in the zb-XXXXX.json file (there is an entry for each device). This can be found in the .mozilla-iot/config or data directories IIRC.

chas-iot commented 4 years ago

Here's the details of the two version E1810 devices. I removed the properties in the inline text and attached the complete file in case of need. There is a possibility that the deviceId could be useful. In the original issue, the author attached details of the two versions and the older model has a different deviceId, see https://github.com/mozilla-iot/zigbee-adapter/issues/199

  "nodes": {
    "842e14fffe4fa87d": {
      "addr64": "842e14fffe4fa87d",
      "addr16": "1a4d",
      "activeEndpoints": {
        "1": {
          "profileId": "0104",
          "deviceId": "0820",
          "deviceVersion": 1,
          "inputClusters": [
            "0000",
            "0001",
            "0003",
            "0020",
            "1000",
            "fc7c"
          ],
          "outputClusters": [
            "0003",
            "0004",
            "0006",
            "0008",
            "0019",
            "1000"
          ],
          "classifierAttributesPopulated": true
        }
      },
// properties removed
      "name": "zb-842e14fffe4fa87d-button",
      "@type": [
        "PushButton"
      ],
      "defaultName": "zb-842e14fffe4fa87d-undefined",
      "extendedTimeout": true,
      "activeEndpointsPopulated": true,
      "nodeInfoEndpointsPopulated": true,
      "modelId": "TRADFRI remote control",
      "powerSource": 3,
      "checkinInterval": 80,
      "longPollInterval": 1160,
      "shortPollInterval": 4,
      "fastPollTimeout": 40,
      "pollCtrlBindingNeeded": false,
      "rxOnWhenIdle": 0
    },

    "842e14fffe17ce3b": {
      "addr64": "842e14fffe17ce3b",
      "addr16": "338c",
      "activeEndpoints": {
        "1": {
          "profileId": "0104",
          "deviceId": "0820",
          "deviceVersion": 1,
          "inputClusters": [
            "0000",
            "0001",
            "0003",
            "0020",
            "1000",
            "fc7c"
          ],
          "outputClusters": [
            "0003",
            "0004",
            "0006",
            "0008",
            "0019",
            "1000"
          ],
          "classifierAttributesPopulated": true
        }
      },
// properties removed
      "name": "zb-842e14fffe17ce3b-button",
      "@type": [
        "PushButton"
      ],
      "defaultName": "zb-842e14fffe17ce3b-undefined",
      "extendedTimeout": true,
      "activeEndpointsPopulated": true,
      "nodeInfoEndpointsPopulated": true,
      "modelId": "TRADFRI remote control",
      "powerSource": 3,
      "checkinInterval": 80,
      "longPollInterval": 1160,
      "shortPollInterval": 4,
      "fastPollTimeout": 40,
      "pollCtrlBindingNeeded": false
    }
  }

zb-00212effff05def2.txt

chas-iot commented 4 years ago

I created a more targeted workaround using the deviceId and verified that it works with my two buttons (both are E1810 / 0820). @mrstegeman are you comfortable where the code just overrides the missing output cluster? @davehylands is this approach better? Answering an earlier question, the scene is just a number in the range 0-15

mrstegeman commented 4 years ago

This seems much more reasonable to me.

davehylands commented 4 years ago

FYI: DeviceID of 0820 corresponds to a Non-Color remote: https://github.com/mozilla-iot/zigbee-adapter/blob/bfccebc2dccf1b00f6e120c1a6ed9ea6261cb546/zb-constants.js#L340

chas-iot commented 4 years ago

FYI: DeviceID of 0820 corresponds to a Non-Color remote:

I’m inexperienced in this area. Is there any action that I can or should take in reaction to this FYI?

davehylands commented 4 years ago

I guess I'd expect the older remote to also have the same device id, so adding a check for the deviceId on top of the check for the modelId shouldn't really be necessary.

chas-iot commented 4 years ago

The older version, according to the logs in #199, has a deviceId of 0x0830 https://github.com/mozilla-iot/zigbee-adapter/blob/bfccebc2dccf1b00f6e120c1a6ed9ea6261cb546/zb-constants.js#L341 It's really quite weird - I suspect that someone made a mess in a hurry, rather than anything deliberate.

Another more complex approach might to create the property but hidden / in the background, and only show it when one of the scene buttons is first clicked. However, this might make rules in the gateway quite difficult to create and maintain, and I'm not even certain that I know how to do it.

davehylands commented 4 years ago

The fact that old controller was of deviceId 0830 is consistent with having the SCENE cluster, and the new controller having a deviceId of 0820 is consistent with NOT having the SCENE cluster.

I suspect that the new controller reports what used to be the "scene" buttons slightly differently that the old controller, and that's probably where the change should be rather than trying to simulate a scene cluster (this is just off the top of my head - I haven't played with (nor do I have) the newer remote).

The way that scenes work is that the remote uses them the control devices directly. Which is why we don't bother using them in the gateway. We just have the device report button presses to the gateway and then have the gateway control the devices.

It would be good to get a packet trace (i.e. enable the frameDetail debug in the confuguration) and press each of the buttons.

chas-iot commented 4 years ago

@davehylands please see https://github.com/mozilla-iot/zigbee-adapter/issues/199#issuecomment-678377732 and the following comment where I posted traces with different debugging options. What I saw was that, despite output cluster 5 not present in the endpoint at initialisation, an update on that cluster was received on a button-click.

chas-iot commented 4 years ago

What can I do to help get this completed?

chas-iot commented 3 years ago

@mrstegeman @davehylands Is there anything that I can do to help push this forward?

mrstegeman commented 3 years ago

@chas-iot Can you confirm that this works properly with both versions of the remote? That's the only concern I had.

chas-iot commented 3 years ago

@chas-iot Can you confirm that this works properly with both versions of the remote? That's the only concern I had.

@mrstegeman A qualified yes.

My yes is qualified in that I do not have an older version of the button to test with. However, the code goes out of the way to avoid changing anything unless it detects the new version of the button.

mrstegeman commented 3 years ago

I'll go ahead and merge. We can back it out and rethink things if someone reports a breakage.

chas-iot commented 3 years ago

I'll go ahead and merge. We can back it out and rethink things if someone reports a breakage.

Great, thank-you