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

Fixed: How to make Siren Alarm to chose Alarm melody and Turn it on Off #585

Open rionshin opened 1 year ago

rionshin commented 1 year ago

Hello all, I am trying to make Alarm switch for https://www.zigbee2mqtt.io/devices/NAS-AB02B0.html#neo-nas-ab02b0 MQQT is exposing following data : { "alarm": false, "battery_low": false, "humidity": 46, "humidity_alarm": true, "humidity_max": 100, "humidity_min": 10, "linkquality": 63, "melody": 9, "power_type": "usb", "temperature": 27, "temperature_alarm": false, "temperature_max": 60, "temperature_min": 0, "volume": "low" }

And I need switch which is sending True/False to "alarm" I tried multiple options but whatever i am doing it is always sending TRUE and don't want to send False on switch off.

That is my configuration :

{ "type": "switch", "name": "Siren", "url": "mqtt://192.168.1.44:1883", "mqttPubOptions": { "retain": true }, "topics": { "getOn": { "topic": "zigbee2mqtt/Siren", "apply": "return JSON.parse(message).alarm ? true : false;" }, "setOn": { "topic": "zigbee2mqtt/Siren/set", "apply": "return JSON.stringify({alarm: (JSON.parse(message).alarm ? false : true )});" }
},

I need to replace (JSON.parse(message).alarm ? false : true ) with the Status of the Switch True/False and not rely on MQQT Message, as for some reason on switch off it doesn't do anything.

Your help will be really appreciated.

rionshin commented 1 year ago

With a little bit of reading it's working now. { "type": "switch", "name": "Siren", "url": "mqtt://192.168.1.44:1883", "mqttPubOptions": { "retain": true }, "topics": { "getOn": { "topic": "zigbee2mqtt/Siren", "apply": "return JSON.parse(message).alarm ? true : false;" }, "setOn": { "topic": "zigbee2mqtt/Siren/set", "apply": "return JSON.stringify({alarm:message});" }, "getOnline": { "topic": "zigbee2mqtt/Siren", "apply": "return JSON.parse(message).battery_low ? false : true;" } },

You can publish in working configurations it as Switch for Zigbee Alarm Sirens, there is 2 sirens with Zigbee both working with this setup now.

rionshin commented 1 year ago

I came with solution to use thermostat which gives option to select the melody as the Siren has 18 different melodies and to turn it on off . This is the code:

{ "accessory": "mqttthing", "type": "thermostat", "name": "Siren Melody", "url": "mqtt://192.168.1.44:1883", "topics": { "getCurrentTemperature": { "topic": "zigbee2mqtt/Siren", "apply": "return JSON.parse(message).temperature" }, "getTargetTemperature": { "topic": "zigbee2mqtt/Siren", "apply": "return JSON.parse(message).melody" }, "getTargetHeatingCoolingState": { "topic": "zigbee2mqtt/Siren", "apply": "return JSON.parse(message).alarm ? 'HEAT' : 'OFF'" }, "getCurrentRelativeHumidity": { "topic": "zigbee2mqtt/Siren", "apply": "return JSON.parse(message).humidity" }, "setTargetHeatingCoolingState": { "topic": "zigbee2mqtt/Siren/set", "apply": "return JSON.stringify({alarm: message == 'OFF' ? false : true })" }, "setTargetTemperature": { "topic": "zigbee2mqtt/Siren/set", "apply": "return JSON.stringify({melody: message })" } }, "temperatureDisplayUnitsValues": "CELSIUS", "minTemperature": 1, "maxTemperature": 50, "restrictHeatingCoolingState": [ 0, 1 ], "heatingCoolingStateValues": [ "OFF", "HEAT" ] }