Yes, you’re right the switching on function does work if I only interact with it in HA and I start with the light off.
If the light is on, which is what I had because I was sitting in the room at night, the restful switch says it’s off and hitting the switch doesn’t make the switch stay, and doesn’t make the light change.
If I start with the light off, and hit the restful switch, the light turns on, the switch in HA moves to on briefly, then back to off. At this point, the restul switch is unable to turn the light off.
When I mentioned I had these working not as restful switches, what I mean is that I’ve built a rest_command service entry in my configuration.yaml. This uses a different function of the API, which I’d prefer not to use (the alpha000 path) because I assume at some point it’ll stop being functional in preference for the api/v1 path. It’s also not doing a real POST command, which I’d prefer.
#test turning on lights
rest_command:
light_set:
url: http://ip:port/alpha000/basic_set?node={{ node }}&value={{ value }}
method: GET
Then built sensors:
# Sensors
sensor:
- name: living_room_left_status
platform: rest
resource: http://ip:port/alpha000/dump_node?node=14
method: GET
value_template: '{{ value_json.result.switch_binary.value }}'
force_update: true
And then this is my switch entry:
# Switches
switch:
- platform: template
switches:
living_room_left:
friendly_name: "Living Room - Left"
value_template: "{{ is_state('sensor.living_room_left_status', 'True') }}"
turn_on:
service: rest_command.light_set
data:
node: 14
value: 100
turn_off:
service: rest_command.light_set
data:
node: 14
value: 0
I’m fairly new to HA and am certainly learning on the move. I got this to work and was happy, but it feels overly complicated, which is what I was hoping the restful switch would solve. I’ll look into the scan_interval variable. Is there not a way to get HA to read the returned body when calling an API?