Shelly io url as a REST switch

This question is related to Home Assistant AND Shelly REST commands.

I need the status of the enabled io-url-actions of my Shelly as a Switch entity in Home Assistant
I already have it enabled for the ‘real’ switch of a Shelly like this:

switch:
  - platform: rest
    name: “Shelly REST Switch”
    scan_interval: 10
    resource: http://192.168.1.2/relay/0
    body_on: "turn=on"
    body_off: "turn=off"
    is_on_template: '{{ value_json.ison == true }}'
    headers:
      content_type: application/x-www-form-urlencoded

I want to create a switch entity in Home Assistant so I can enable and disable local action urls
How can I get this done?

The resource for the action url is:
http://192.168.1.2/settings/actions

Part of the REST response is:

{
"actions":
{
"out_on_url": [{
"index": 0,
"urls": ["http://ip.she.lly.two/relay/0?turn=on"],
"enabled": true
}],
"out_off_url": [{
"index": 0,
"urls": ["http://ip.she.lly.two/relay/0?turn=off"],
"enabled": true
}]
}
}

The common HTTP API command would be:
To switch OFF:

http://192.168.1.2/settings/actions?index=0&name=out_on_url&enabled=false

To switch ON:

http://192.168.1.2/settings/actions?index=0&name=out_on_url&enabled=true

I’ve got the status of the switch working, unfortunately body_on and body_off not working yet…
No idea how to get to that part…

- platform: rest
  name: "URL switch"
  scan_interval: 10
  resource: http://192.168.1.2/settings/actions
  body_on: "enabled=true"
  body_off: "enabled=false"
  is_on_template: '{{ value_json.actions["out_on_url"][0]["enabled"] == true }}'
  headers:
    content_type: application/x-www-form-urlencoded

Hi @filmgarage , were you able to accomplish this at any point?
You have another post about something similar, also with no replies:

And I’m also trying to do something similar, I made a new post on the Shelly forum:

I investigated further and this is achievable in HA - it’s just a matter of getting the coding right.
This will create a “virtual switch” for button_type=toggle/detached
If this parameter is changed outside of HA, it will still show the correct setting with a 10-15 second delay.

switch:
  - platform: rest
    name: "Roller Shutter Buttons"
    resource: http:// shelly-ip /settings/roller/0
    body_on: "btn_type=toggle"
    body_off: "btn_type=detached"
    is_on_template: '{{ value_json.button_type == "toggle" }}'
    headers:
      Content-Type: application/x-www-form-urlencoded
    username: (username of the device)
    password: (password of the device)

Here’s the code for a case much like yours:

switch:
  - name: "URL action"
    platform: rest
    resource: http:// shelly-ip /settings/actions
    body_on: "name=shortpush_url&index=0&enabled=true"
    body_off: "name=shortpush_url&index=0&enabled=false"
    is_on_template: '{{ value_json.actions["shortpush_url"][0]["enabled"] == true }}'
    headers:
      Content-Type: application/x-www-form-urlencoded
    username: (username of the device)
    password: (password of the device)
1 Like

I was struggling with this over a year ago…
So cool you found the solution!

Would you know how to set the actual short push_url itself as well?
It would be great if I could change the action url from within HA…

I would love to turn this into a blueprint and use it as a service.

Thanks a lot for your insight. I will definitely start fiddling with this again!

Sorry I didn’t get a notification.
I think this might get you there:
https://shelly-api-docs.shelly.cloud/gen1/#settings-actions