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

setOn different commands for On/Off #470

Closed PierreBier closed 3 years ago

PierreBier commented 3 years ago

Hi there, i'm using this plugin to control my hot tub. I have already configured a switch for controling the pump. I can activate the pump with this code:

"setOn": {
                    "topic": "dkspamqtt/command",
                    "apply": "return JSON.stringify({CMD:4,VALUE:1,XTIME:0,INTERVAL:0})"
                }

The problem is, that I'm not able to send the command to turn off the pump which must be

                    "topic": "dkspamqtt/command",
                    "apply": "return JSON.stringify({CMD:4,VALUE:0,XTIME:0,INTERVAL:0})"
                }

I tried to ad something like "setOff" but it doesn't work. How can I send to different commands for on and off?

arachnetech commented 3 years ago

The message variable is available within your apply code - so if you use "integerValue": true to give you on/off values of 1 and 0 then you should be able to use something like: "apply": "return JSON.stringify({CMD:4,VALUE:message,XTIME:0,INTERVAL:0})"

arachnetech commented 3 years ago

You might also want to have a look at the JSON Codec: https://github.com/arachnetech/homebridge-mqttthing/blob/42c7a5da71b2a6d80d49d2e70016dd03db387c24/docs/Codecs.md#json-codec-json

PierreBier commented 3 years ago

Thank you for your help. The code worked like this.