arachnetech / homebridge-mqttthing

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

Make switch for Siren On and Off #615

Closed lucaesse closed 1 year ago

lucaesse commented 1 year ago

Hi, I have this siren https://www.zigbee2mqtt.io/devices/TS0224.html#tuya-ts0224 and I need to expose it as a switch or two for on and off but I don’t know how to do it. Can somebody help me?

This should be ON: {"warning": {"mode": burglar, "level": low, "strobe_level": high, "strobe": true, "strobe_duty_cycle": 10, "duration": 3600}}

and this should be OFF: {"warning": {"mode": stop, "level": low, "strobe_level": high, "strobe": false, "strobe_duty_cycle": 10, "duration": 3600}}

both published on topic: zigbee2mqtt/Sirena/set

lucaesse commented 1 year ago

Solved by myself

remussamoila commented 1 year ago

Hi, Lucaesse Can you explain how you solved? My small advance was by creating two switches, one for Siren On and one for Siren Off, both with these parameters for SetOn. Unfortunately, the switches stays on until I can set by parameter.

The SirenOn switch> "setOn": { "topic": "zigbee2mqtt/Siren/set", "apply": "return JSON.stringify({\"warning\": { \"mode\": \"emergency\", \"level\": \"high\", \"strobe_level\": \"high\", \"strobe\": true, \"strobe_duty_cycle\": 10, \"duration\": 180 }})"

The SirenOff switch> "setOn": { "topic": "zigbee2mqtt/Siren/set", "apply": "return JSON.stringify({\"warning\": { \"mode\": \"stop\", \"strobe\": false}})"

I would like to see if I can use a single switch that can set the above mentioned on and off payloads, but I'm struggling to find how. Maybe adapting this toggle.js functionality: https://github.com/arachnetech/homebridge-mqttthing/issues/280 Thank you!

lucaesse commented 1 year ago

Hi, sorry for the long wait. I solved with this config:

    {
        "type": "switch",
        "name": "Sirena",
        "url": "mqtt://192.168.3.8:1883",
        "topics": {
            "setOn": "zigbee2mqtt/Sirena/set"
        },
        "onValue": "{\"warning\":{\"duration\":3600,\"level\":\"very_high\",\"mode\":\"burglar\",\"strobe\":false,\"strobe_duty_cycle\":1,\"strobe_level\":\"low\"}}",
        "offValue": "{\"warning\":{\"duration\":60,\"level\":\"low\",\"mode\":\"stop\",\"strobe\":false,\"strobe_duty_cycle\":1,\"strobe_level\":\"low\"}}",
        "history": false,
        "manufacturer": "Meian",
        "model": "TS0224",
        "serialNumber": "TUYA-TS0224",
        "accessory": "mqttthing"
    }

It's a single switch with ON/OFF on tap.