Can home assistant change api if turning switch on vs off?

I am using wiolink sensors which provide a REST api.

How can I use the restful switch plugin to turn a switch on and off?

With curl

Turn on

https://us.wio.seeed.io/v1/node/GroveRelayD2/onoff/1?access_token=<redacted>

Turn off

https://us.wio.seeed.io/v1/node/GroveRelayD2/onoff/1?access_token=<redacted>

Get value

https://us.wio.seeed.io/v1/node/GroveRelayD2/onoff_status?access_token=<redacted>

Looking at the documentation examples ,there doesn’t appear to be a way to set a conditional url so that the switch is turned on with one url, and off with another. Can this be done?

This should do it. https://home-assistant.io/components/switch.rest/

You can use the method: GET function with a rest sensor.

I’m trying to use the rest switch, but how do I change the url depending if turning on or turning off?

Here is what I’ve got:

switch:
  - name: wiolink 2 D2
    platform: rest
    resource: https://us.wio.seeed.io/v1/node/GroveRelayD2/onoff/?access_token=<redacted> 
    body_on: 1
    body_off: 0

Yet the logs show that it can’t find the endpoint.

I expect home assistant to do a post to https://us.wio.seeed.io/v1/node/GroveRelayD2/onoff/1 or https://us.wio.seeed.io/v1/node/GroveRelayD2/onoff/0, but I find the value is absent.

16-10-18 05:14:51 homeassistant.components.switch.rest: Can’t turn on https://us.wio.seeed.io/v1/node/GroveRelayD2/onoff/?access_token=. Is resource/endpoint offline?

Sorry I overlooked it. If the curl works then the command line switch should. https://home-assistant.io/components/switch.command_line/

The following works, but feels hacky.

switch:
  platform: command_line
  switches:
    foobar:
      command_on: "/usr/bin/curl -X POST https://us.wio.seeed.io/v1/node/GroveRelayD2/onoff/1?access_token=xxxx"
      command_off: "/usr/bin/curl -X POST https://us.wio.seeed.io/v1/node/GroveRelayD2/onoff/0?access_token=xxxx"
      command_state: "/usr/bin/curl -X GET https://us.wio.seeed.io/v1/node/GroveRelayD2/onoff_status?access_token=xxxxx"
      friendly_name: WioLink 2 D2