Adguard - Rest Switches

I have the following switches defined as rest switches which are used to control blocked services within AdGuard. With a single switch it works as expected. I can toggle the service on and off. I recently added a second switch for the “Roblox” service and when doing so it will toggle off the “YouTube” service and vise versa. Even thought they are defined as different switches and interact with different service names interacting with one affects the other.

I would like to have both operate independent of each other to able to control the state of each service. I have tried adding the name in body off as well with no change.

- platform: rest
  method: POST
  name: Youtube
  resource: http://192.168.1.52:3000/control/blocked_services/set
  state_resource: http://192.168.1.52:3000/control/blocked_services/list
  body_on: '["youtube"]'
  body_off: '["youtube"]'
  is_on_template: '{{ value_json == ["youtube"] }}' 
  headers:
    User-Agent: Homeassistant REST
    Content-Type: application/json
  verify_ssl: false
  
- platform: rest
  method: POST
  name: Roblox
  resource: http://192.168.1.52:3000/control/blocked_services/set
  state_resource: http://192.168.1.52:3000/control/blocked_services/list
  body_on: '["roblox"]'
  body_off: '["roblox"]'
  is_on_template: '{{ value_json == ["roblox"] }}' 
  headers:
    User-Agent: Homeassistant REST
    Content-Type: application/json
  verify_ssl: false

You need more specific state_resource options for each.

Does it?

What strikes me is the is_on_template: {{ value_json == ["roblox"] }} which is extremely unlikely to be correct.
What is http://192.168.1.52:3000/control/blocked_services/list actually returning?

1 Like

Ah. Missed the value template. But yeah that is unlikely to be correct.

It appears to return the value of the last toggled switch.

When Roblox is turned on:

"roblox"

But this action will toogle Youtube off.

When Youtube switch is turned on:

"youtube"

But this action turns off Roblox.

Looking to have the ability for them to operate independant and not have one affect the other.

You might try

is_on_template: '{{ "youtube" in value }}' 

and same for roblox.

From the name of the services, I suspect you have to give an actual list to blocked_services/set though. So I suspect that if you “enable” youtube, it also re-enable roblox, unless you send “youtube, roblox”, or whatever the API wants as a list.

EDIT: Yep

So, should we first use

  http://x.x.x.x/control/blocked_services/get
  method: GET

to get a list of existing blocked services,

… and then append yourube to the list

… and the write the new list (with youtube) back to AdGuard using:

  resource: http://x.x.x.x/control/blocked_services/update
  method: PUT

… does that sound reasonable?