spuder
(Spuder)
October 18, 2016, 12:40am
1
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?
PtP
(Mike)
October 18, 2016, 4:52am
2
This should do it. https://home-assistant.io/components/switch.rest/
You can use the method: GET
function with a rest sensor.
spuder
(Spuder)
October 18, 2016, 5:06am
3
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?
PtP
(Mike)
October 18, 2016, 6:26am
4
Sorry I overlooked it. If the curl works then the command line switch should. https://home-assistant.io/components/switch.command_line/
spuder
(Spuder)
October 19, 2016, 2:04am
5
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