How do I make trigger URL API calls via Home Assistant?

I am fairly new to Home Assistant and I wish to be able to make URL API calls via either buttons on my Home Assistant home page OR trigger these URL API calls via an automation.

For example, if I wish to detach a Shelly relay, I may wish to call:

http://192.168.1.x/rpc/Switch.SetConfig?id=0&config={%22in_mode%22:%22detached%22}

And then if I wish to set it back to active, I may wish to call:

http://192.168.1.x/rpc/Switch.SetConfig?id=0&config={%22in_mode%22:%22follow%22}

I want to be able to trigger these via a toggle switch on my home screen or via an automation.

What is the best way to achieve that?

Rest command makes the url available to be scripted. Then you write a a scriptthat performs your get/put/post/delete

1 Like

if you want to follow this path, it is a valid one.

If you want an easier one, you can try Shelly integration. This integration will create switch entities automatically for you and will handle all commands too.

1 Like

Thanks for your reply. I am using the Shelly integration already for normal light function, but the integration module does not currently offer a way to change the switch mode - hence why I am looking at making a direct API call.

1 Like

Thanks. This ‘Restful Command’ looks perfect. I will take a look into that.

Solved it. For others reading this post in the future, I was able to simply edit my configuration.yaml file to define a new switch.

Remember to restart Home Assistant after adding this:

switch:
  - platform: rest
    name: "Shelly1Plus.Doorbell.Buzzer"
    resource: http://192.168.100/rpc
    method: post
    headers:
      Content-Type: application/json
    body_on: '{"id":1,"method":"Switch.SetConfig","params":{"id":0,"config":{"in_mode":"follow""initial_state":"match_input"}}}'
    body_off: '{"id":1,"method":"Switch.SetConfig","params":{"id":0,"config":{"in_mode":"detached","initial_state":"off"}}}'
    state_resource: http://192.168.1.100/rpc/Switch.GetConfig?id=0
    is_on_template: "{{ value_json['in_mode'] == 'follow' }}"