RESTful Switch

I have two HA locations, one local and the other over VPN. I would like to control and monitor all the entities from one instance of HA. It seems like to Master-Slave connection is not working or there is not a decent enough tutorial for me to make it run properly. I would like to use REST to control the entities in the remote instance and get their state.

Can someone help me get this working and reporting correctly?

For example I am trying to control a light so I imagine that I will need this…

  - platform: rest
    resource:
    body_on:
    body_off:
    is_on_template:

The entity_id is: light.linear_lb60z1_dimmable_led_light_bulb_level_3_0

I have had some success running commands from the examples below in terminal but just cant seem to put it all together.

Any help is appreciated!!

Here’s some info to help you determine the URLs for HASS service calls.

tl;dr: use HASS’ services dev tool and watch URLs in your browser’s dev tool (network)

Thanks @ih8gates I will check it out!

I can make it work through the dev tool but not as a component.

This is what I have now but I have tried several variations.

  - platform: rest
    resource: http://192.168.50.58:8123/api/services/light/
    name: Kitchen
    body_on: turn_on/ {"entity_id": "light.linear_lb60z1_dimmable_led_light_bulb_level_3_0"}
    body_off: turn_off/ {"entity_id": "light.linear_lb60z1_dimmable_led_light_bulb_level_3_0"}
    is_on_template:

This is the error I get.

17-01-20 11:05:17 ERROR (Thread-1) [homeassistant.util.yaml] mapping values are not allowed here

Thanks!

OK. I’m not really sure what you’re trying to achieve here. There’s no need to use the rest platform to turn on/off lights.

- service: light.turn_on
  entity_id: light.linear_lb60z1_dimmable_led_light_bulb_level_3_0

But this bulb should already have an on/off in the UI.

Thanks for staying with me on this…

The bulb is on a remote instance of HA. It is connected through VPN. I would like to add a component to the local instance of HA that controls and gets the state of the bulb connected to the remote instance.

I don’t use REST, so I’m reading the docs…Looks like you only want the JSON in body_on and body_off.

Ok Cool! Where do I use the JSON to identify the entity I want to control?

Does this look right or is the a ? after turn_on?

http://192.168.20.58:8123/api/services/light/turn_on {"entity_id":"light.linear_lb60z1_dimmable_led_light_bulb_level_3_0"}

This part is the JSON. The entity_id value is what you wanna control.

Yes sir this I understand.

I am having trouble putting this info in to the Restful switch component.

Maybe using a command line switch would be better?

@ih8gates

I got it working using the command line switch now I am working on getting the state from the bulb on the remote instance of HA. The state command below returns all attributes including the state. Is there a way to just get the state or extract the state using a value template?

  mckitchen:
    command_on: /usr/bin/curl -X POST http://192.168.50.58:8123/api/services/light/turn_on?{"entity_id":"light.linear_lb60z1_dimmable_led_light_bulb_level_3_0"}
    command_off: /usr/bin/curl -X POST http://192.168.50.58:8123/api/services/light/turn_off?{"entity_id":"light.linear_lb60z1_dimmable_led_light_bulb_level_3_0"}
    command_state: /usr/bin/curl -X GET http://192.168.50.58:8123/api/states/light.linear_lb60z1_dimmable_led_light_bulb_level_3_0

The command_state returns:

{"attributes": {"brightness": 255.0, "friendly_name": "Linear LB60Z-1 Dimmable LED Light Bulb Level", "node_id": 3, "supported_features": 19}, "entity_id": "light.linear_lb60z1_dimmable_led_light_bulb_level_3_0", "last_changed": "2017-01-21T14:36:49.806167+00:00", "last_updated": "2017-01-21T14:37:30.249645+00:00", "state": "on"}

As you can see the state is the last item.

Any suggestions?

Thank you!

#10 Minutes Later…

I think I got it!!

  mckitchen:
    command_on: /usr/bin/curl -X POST http://192.168.50.58:8123/api/services/light/turn_on?{"entity_id":"light.linear_lb60z1_dimmable_led_light_bulb_level_3_0"}
    command_off: /usr/bin/curl -X POST http://192.168.50.58:8123/api/services/light/turn_off?{"entity_id":"light.linear_lb60z1_dimmable_led_light_bulb_level_3_0"}
    command_state: /usr/bin/curl -X GET http://192.168.50.58:8123/api/states/light.linear_lb60z1_dimmable_led_light_bulb_level_3_0
    value_template: '{{ value_json.state == "on" }}'
1 Like