Conditional setOn/setOff
Opened this issue · 3 comments
Arnwald commented
Hi,
I have a device that is powered on or off with a smart relay closed for 1 second (in both cases).
Everything works well, but if I tell Siri to turn everything off and the device is already off, then it turns on... To correct this behavior, I would need to add a condition on the setOff function, so that it doesn't try to turn it off if its state is already off (I can get its state with a getOn). Is that possible ?
Here is my config:
{
"accessory": "HttpAdvancedAccessory",
"service": "Switch",
"name": "Ampli",
"forceRefreshDelay": 5,
"debug": false,
"urls": {
"getOn": {
"url": "http://172.22.22.59/rpc/Input.GetStatus?id=0",
"mappers": [
{
"type": "jpath",
"parameters": {
"jpath": "state",
"index": "0"
}
},
{
"type": "static",
"parameters": {
"mapping": {
"on": "true",
"off": "false"
}
}
}
]
},
"setOn": {
"url": "http://172.22.22.59/relay/0?turn=on"
},
"setOff": {
"url": "http://172.22.22.59/relay/0?turn=on"
}
}
}
Thank you!
staromeste commented
Hi,Maybe you can use the URL template (https://github.com/staromeste/homebridge-http-advanced-accessory#url-template) feature and replace the set off URL with something like this: “http://172.22.22.59/relay/0?turn=${state.getOn ? “On” : “Off”}”GuidoIl giorno 3 dic 2022, alle ore 13:44, Arnwald ***@***.***> ha scritto:
Hi,
I have a device that is powered on or off with a smart relay closed for 1 second (in both cases).
Everything works well, but if I tell Siri to turn everything off and the device is already off, then it turns on... To correct this behavior, I would need to add a condition on the setOff function, so that it doesn't try to turn it off if its state is already off (I can get its state with a getOn). Is that possible ?
Here is my config:
'''
{
"accessory": "HttpAdvancedAccessory",
"service": "Switch",
"name": "Ampli",
"forceRefreshDelay": 5,
"debug": false,
"urls": {
"getOn": {
"url": "http://172.22.22.59/rpc/Input.GetStatus?id=0",
"mappers": [
{
"type": "jpath",
"parameters": {
"jpath": "state",
"index": "0"
}
},
{
"type": "static",
"parameters": {
"mapping": {
"on": "true",
"off": "false"
}
}
}
]
},
"setOn": {
"url": "http://172.22.22.59/relay/0?turn=on"
},
"setOff": {
"url": "http://172.22.22.59/relay/0?turn=on"
}
}
}
'''
Thank you !
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
Arnwald commented
Thank you very much.
I managed to do it with a one-liner:
"setOn": {
"url": "http://172.22.22.59/relay/0?turn=${value==1?\"on\":state.getOn?\"on\":\"off\"}"
}
staromeste commented
Great!Have a nice weekend!GuidoIl giorno 3 dic 2022, alle ore 14:56, Arnwald ***@***.***> ha scritto:
Thank you very much.
I managed to do it with a one-liner:
"setOn": {
"url": "http://172.22.22.59/relay/0?turn=${value==1?\"on\":state.getOn?\"on\":\"off\"}"
}
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you commented.Message ID: ***@***.***>