staromeste/homebridge-http-advanced-accessory

Conditional setOn/setOff

Opened this issue · 3 comments

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!

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\"}"
        }