ebaauw / homebridge-hue

Homebridge plugin for Philips Hue
Apache License 2.0
901 stars 91 forks source link

Device Support Request: Tuya 2 Button Switch #1060

Closed julunde closed 2 years ago

julunde commented 2 years ago

Issue

Hi there,

Would it be possible to add support for a Tuya 2 button switch?

device

I've gotten it to work with Conbee2 but it is showing as an unsupported device in the home app. I made a similar request over on the Dresden Elektronik and this thread contains the information on the switch.

I'm primarily interested in single button press functionality so these are mapped to:

Single Press: Button 1 has the buttonevent value of 1002, Button 2 has the buttonevent value of 2002

But in the interest of completeness, the other button event values are as follows:

Double Press: Button 1 has the buttonevent value of 1004, Button 2 has the buttonevent value of 2004

Long Press: Button 1 has the buttonevent value of 1003, Button 2 has the buttonevent value of 2003

Thanks,

julunde

Log Messages

Hue Plugin Log

[16/12/2021, 20:39:01] [Hue] Phoscon-GW: /sensors/4: warning: ignoring unknown ZHASwitch sensor {"config":{"battery":null,"group":null,"on":true,"reachable":true},"ep":1,"etag":"1bfd4b4f5640d78e988d53cf84773807","lastannounced":null,"lastseen":"2021-12-16T20:14Z","manufacturername":"_TZ3000_i3rjdrwu","mode":1,"modelid":"TS0042","name":"Switch (2)","state":{"buttonevent":1002,"lastupdated":"2021-12-16T20:11:40.488"},"type":"ZHASwitch","uniqueid":"8c:f6:81:ff:fe:91:0b:7e-01-0006"}

[16/12/2021, 20:39:01] [Hue] Phoscon-GW: /sensors/5: warning: ignoring unknown ZHASwitch sensor {"config":{"battery":null,"group":null,"on":true,"reachable":true},"ep":2,"etag":"7a73b8f209294b3804ad1dee739f35aa","lastannounced":null,"lastseen":"2021-12-16T20:14Z","manufacturername":"_TZ3000_i3rjdrwu","mode":1,"modelid":"TS0042","name":"Switch (2)","state":{"buttonevent":2002,"lastupdated":"2021-12-16T20:14:11.247"},"type":"ZHASwitch","uniqueid":"8c:f6:81:ff:fe:91:0b:7e-02-0006"}

Phoscon API Event Log

                    {
    "21:10:47:660": {
        "e": "changed",
        "id": "6",
        "r": "sensors",
        "state": {
            "buttonevent": 1002,
            "lastupdated": "2021-12-16T21:10:47.656"
        },
        "t": "event",
        "uniqueid": "8c:f6:81:ff:fe:91:0b:7b-01-0006"
    },
    "21:10:50:652": {
        "e": "changed",
        "id": "7",
        "r": "sensors",
        "state": {
            "buttonevent": 2002,
            "lastupdated": "2021-12-16T21:10:50.648"
        },
        "t": "event",
        "uniqueid": "8c:f6:81:ff:fe:91:0b:7b-02-0006"
    },
    "21:10:53:15": {
        "e": "changed",
        "id": "6",
        "r": "sensors",
        "state": {
            "buttonevent": 1004,
            "lastupdated": "2021-12-16T21:10:53.011"
        },
        "t": "event",
        "uniqueid": "8c:f6:81:ff:fe:91:0b:7b-01-0006"
    },
    "21:10:56:9": {
        "e": "changed",
        "id": "7",
        "r": "sensors",
        "state": {
            "buttonevent": 2004,
            "lastupdated": "2021-12-16T21:10:56.006"
        },
        "t": "event",
        "uniqueid": "8c:f6:81:ff:fe:91:0b:7b-02-0006"
    },
    "21:11:03:47": {
        "e": "changed",
        "id": "6",
        "r": "sensors",
        "state": {
            "buttonevent": 1003,
            "lastupdated": "2021-12-16T21:11:03.042"
        },
        "t": "event",
        "uniqueid": "8c:f6:81:ff:fe:91:0b:7b-01-0006"
    },
    "21:11:08:284": {
        "attr": {
            "id": "7",
            "lastannounced": null,
            "lastseen": "2021-12-16T21:11Z",
            "manufacturername": "_TZ3000_i3rjdrwu",
            "modelid": "TS0042",
            "name": "TS0042 7",
            "swversion": null,
            "type": "ZHASwitch",
            "uniqueid": "8c:f6:81:ff:fe:91:0b:7b-02-0006"
        },
        "e": "changed",
        "id": "7",
        "r": "sensors",
        "t": "event",
        "uniqueid": "8c:f6:81:ff:fe:91:0b:7b-02-0006"
    },
    "21:11:08:286": {
        "e": "changed",
        "id": "7",
        "r": "sensors",
        "state": {
            "buttonevent": 2003,
            "lastupdated": "2021-12-16T21:11:08.281"
        },
        "t": "event",
        "uniqueid": "8c:f6:81:ff:fe:91:0b:7b-02-0006"
    },
    "21:11:08:380": {
        "attr": {
            "id": "6",
            "lastannounced": null,
            "lastseen": "2021-12-16T21:11Z",
            "manufacturername": "_TZ3000_i3rjdrwu",
            "modelid": "TS0042",
            "name": "Switch (3)",
            "swversion": null,
            "type": "ZHASwitch",
            "uniqueid": "8c:f6:81:ff:fe:91:0b:7b-01-0006"
        },
        "e": "changed",
        "id": "6",
        "r": "sensors",
        "t": "event",
        "uniqueid": "8c:f6:81:ff:fe:91:0b:7b-01-0006"
    }
}                      

Debug Files

ebaauw commented 2 years ago

Technically, yes. I don't think it's exposed correctly in deCONZ, though. Want to have that discussion first.

julunde commented 2 years ago

Ok awesome! I can validate that it has 2 endpoints on every switch (I have three).

[16/12/2021, 20:39:01] [Hue] Phoscon-GW: /sensors/2: warning: ignoring unknown ZHASwitch sensor {"config":{"battery":null,"group":null,"on":true,"reachable":true},"ep":2,"etag":"e7bd842818d00e7ee7515822b4c855f0","lastannounced":"2021-12-12T18:33:21Z","lastseen":"2021-12-16T20:37Z","manufacturername":"_TZ3000_i3rjdrwu","mode":1,"modelid":"TS0042","name":"Switch","state":{"buttonevent":2002,"lastupdated":"2021-12-16T20:38:22.124"},"type":"ZHASwitch","uniqueid":"8c:f6:81:ff:fe:91:0b:8b-02-0006"}
[16/12/2021, 20:39:01] [Hue] Phoscon-GW: /sensors/3: warning: ignoring unknown ZHASwitch sensor {"config":{"battery":null,"group":null,"on":true,"reachable":true},"ep":1,"etag":"ffdd7203ad7e059269efc794b0ac9790","lastannounced":"2021-12-12T18:33:21Z","lastseen":"2021-12-16T20:37Z","manufacturername":"_TZ3000_i3rjdrwu","mode":1,"modelid":"TS0042","name":"Switch","state":{"buttonevent":1004,"lastupdated":"2021-12-16T20:38:24.243"},"type":"ZHASwitch","uniqueid":"8c:f6:81:ff:fe:91:0b:8b-01-0006"}
[16/12/2021, 20:39:01] [Hue] Phoscon-GW: /sensors/4: warning: ignoring unknown ZHASwitch sensor {"config":{"battery":null,"group":null,"on":true,"reachable":true},"ep":1,"etag":"1bfd4b4f5640d78e988d53cf84773807","lastannounced":null,"lastseen":"2021-12-16T20:14Z","manufacturername":"_TZ3000_i3rjdrwu","mode":1,"modelid":"TS0042","name":"Switch (2)","state":{"buttonevent":1002,"lastupdated":"2021-12-16T20:11:40.488"},"type":"ZHASwitch","uniqueid":"8c:f6:81:ff:fe:91:0b:7e-01-0006"}
[16/12/2021, 20:39:01] [Hue] Phoscon-GW: /sensors/5: warning: ignoring unknown ZHASwitch sensor {"config":{"battery":null,"group":null,"on":true,"reachable":true},"ep":2,"etag":"7a73b8f209294b3804ad1dee739f35aa","lastannounced":null,"lastseen":"2021-12-16T20:14Z","manufacturername":"_TZ3000_i3rjdrwu","mode":1,"modelid":"TS0042","name":"Switch (2)","state":{"buttonevent":2002,"lastupdated":"2021-12-16T20:14:11.247"},"type":"ZHASwitch","uniqueid":"8c:f6:81:ff:fe:91:0b:7e-02-0006"}
[16/12/2021, 20:39:01] [Hue] Phoscon-GW: /sensors/6: warning: ignoring unknown ZHASwitch sensor {"config":{"battery":null,"group":null,"on":true,"reachable":true},"ep":1,"etag":"b68c9a2390851b1cd9f052397e983431","lastannounced":null,"lastseen":"2021-12-16T20:36Z","manufacturername":"_TZ3000_i3rjdrwu","mode":1,"modelid":"TS0042","name":"Switch (3)","state":{"buttonevent":1002,"lastupdated":"2021-12-16T20:36:42.077"},"type":"ZHASwitch","uniqueid":"8c:f6:81:ff:fe:91:0b:7b-01-0006"}
[16/12/2021, 20:39:01] [Hue] Phoscon-GW: /sensors/7: warning: ignoring unknown ZHASwitch sensor {"config":{"battery":null,"group":null,"on":true,"reachable":true},"ep":2,"etag":"0622b1b270260daaca34ca74881ced30","lastannounced":null,"lastseen":"2021-12-16T20:36Z","manufacturername":"_TZ3000_i3rjdrwu","mode":1,"modelid":"TS0042","name":"TS0042 7","state":{"buttonevent":2002,"lastupdated":"2021-12-16T20:36:49.988"},"type":"ZHASwitch","uniqueid":"8c:f6:81:ff:fe:91:0b:7b-02-0006"}
ebaauw commented 2 years ago

In v0.13.31.

julunde commented 2 years ago

Awesome. Just tested there, it works flawlessly. Thanks for the effort, it is greatly appreciated.

julunde commented 2 years ago

@ebaauw - Just for your info, I got 2 more switches and they didn't work as intended initially. It seems that DeConz/Phoscon creates an endpoint per switch only if you add-> delete-> re-add the switches without first deleting them in the device manager on the webapp. If you pair them first time, it will use a 01 endpoin for both buttons and differentiate buttons based on the event IDs (as expected).

They work now, but in order to get the Homebridge hue to recognize buttons I guess I had to incorrectly (for lack of a better word) discover the device.