arachnetech / homebridge-mqttthing

A plugin for Homebridge allowing the integration of many different accessory types using MQTT.
Apache License 2.0
462 stars 104 forks source link

Doorbell switchValues ? #550

Closed bakman2 closed 2 years ago

bakman2 commented 2 years ago

How do switchValues work with a doorbell ? I fail to understand the documentation.

mqtt topic received:

{
    "action": "single",
    "click": "single",
    "device":
    {
        "applicationVersion": 2,
        "dateCode": "20180525",
        "friendlyName": "rooms/hal/switch/deurbel",
        "hardwareVersion": 2,
        "ieeeAddr": "0x00158d0007cfb148",
        "manufacturerID": 4151,
        "manufacturerName": "LUMI",
        "model": "WXKG11LM",
        "networkAddress": 47775,
        "powerSource": "Battery",
        "softwareBuildID": "3000-0001",
        "stackVersion": 2,
        "type": "EndDevice",
        "zclVersion": 1
    },
    "linkquality": 72
}

Config:

    "accessories": [
        {
            "type": "doorbell",
            "name": "deurbel-hal",
            "url": "mqtt://10.0.0.6:1883",
            "logMqtt": true,
            "topics": {
                "getSwitch": "zigbee2mqtt/rooms/hal/switch/deurbel",
                "apply": "return ( JSON.parse(message).action =='single' ) ? 0 : null"
            },
            "accessory": "mqttthing",
            "switchValues": [
                "single",
                "double",
                "long_release"
            ]
        }
    ],

after press, homebridge response:

[3/31/2022, 1:00:06 PM] [deurbel-hal] Warning: switch received [{"action":"single","click":"single","device":{"applicationVersion":2,"dateCode":"20180525","friendlyName":"rooms/hal/switch/deurbel","hardwareVersion":2,"ieeeAddr":"0x00158d0007cfb148","manufacturerID":4151,"manufacturerName":"LUMI","model":"WXKG11LM","networkAddress":47775,"powerSource":"Battery","softwareBuildID":"3000-0001","stackVersion":2,"type":"EndDevice","zclVersion":1},"linkquality":138}] 
which is not in configured values {"single":0,"double":1,"long_release":2}

I also tried with:

"apply": "return JSON.parse(message).action"

Same response.

arachnetech commented 2 years ago

I've never managed to get Homekit to recognize the doorbell type - it always shows as unsupported accessory. If you get it working please let me know!

To answer your questions on switch values, the value received over MQTT (after decoding by any apply function) must exist in your switchValues array - so your second apply function looks right to me. However, you have the configuration syntax wrong: the apply function is defined within the topic.

Try:

        {
            "type": "doorbell",
            "name": "deurbel-hal",
            "url": "mqtt://10.0.0.6:1883",
            "logMqtt": true,
            "topics": {
                "getSwitch": {
                    "topic": "zigbee2mqtt/rooms/hal/switch/deurbel",
                    "apply": "return JSON.parse(message).action"
                }
            },
            "accessory": "mqttthing",
            "switchValues": [
                "single",
                "double",
                "long_release"
            ]
        }
bakman2 commented 2 years ago

Ah thanks, I overlooked that part. It works now;

[4/3/2022, 5:39:21 PM] [deurbel-hal] apply() function decoded message to [single]
[4/3/2022, 5:39:21 PM] [deurbel-hal] Received single - switch state is now 0

I've never managed to get Homekit to recognize the doorbell type - it always shows as unsupported accessory. If you get it working please let me know!

Yes they will show up as unsupported, as Apple seem to require certifications for it (i guess it usually involves cameras that will utilise their cloud for recordings), but the doorbell ring will work:

Screenshot 2022-04-03 at 17 41 17

arachnetech commented 2 years ago

Aha, thanks - from memory that's improved since I last tried them. (I bought a Ring years ago, so haven't needed my own doorbell integration!)