Adguard Home integration - any way to toggle client settings?

I use AGH on my firewall and it is working great. I use it for, amongst other things, shutting down gaming and such when my kids have study time, but I always have to go into the client settings and toggle the “use global blocked services” on and off. Is there any way to trigger that with the existing integration or a fork?

Can one of these switches do it? AdGuard Home - Home Assistant

Yes, afraid not. This is a per-client setting, but probablythe most commonly used one.

Only method I came across was doing this by a curl command.

That’s a good thought. I’ll look into that - thanks.

found a solution? I have created restcommands for this:

add_ipad_milan:
  url: https://username:[email protected]/control/clients/add
  method: POST
  payload: '{"name": "ipad","ids": ["192.168.0.178"],"tags": ["user_child"],"upstreams": [],"filtering_enabled": true,"parental_enabled": false,"safebrowsing_enabled": false,"safesearch_enabled": false,"use_global_blocked_services": false,"use_global_settings": false,"blocked_services": ["9gag","amazon","dailymotion","discord","disneyplus","ebay","epic_games","facebook","hulu","imgur","instagram","mail_ru","netflix","ok","origin","pinterest","qq","reddit","snapchat","steam","telegram","tiktok","tinder","twitch","twitter","viber","vimeo","vk","wechat","weibo","whatsapp","youtube","roblox","onlyfans","fifa"]}'
  content_type: "application/json"

and, to remove:

remove_laptop_milan:
  url: https://username:[email protected]/control/clients/delete
  method: POST
  payload: '{ "name": "ipad" }'
  content_type: "application/json"  

Ensure the name is exactly the same, it is case sensitive.

2 Likes

Thanks so much! I think I have the gist of what’s going on here and this looks really promising. I will look into ways to tie that into a switch toggle action. I’m swamped with work this week so it may be next week before I really get to try it, unfortunately.

Thanks again - I’ll be back with an update one way or another.

So it looks like if I use something like this it will work:

disable_laptop_block:
  url: https://username:[email protected]/control/clients/update
  method: POST
  payload: '{ "name": "laptop","ids": ["192.168.1.10"],"use_global_blocked_services": false}'
  content_type: "application/json"  

I guess I could set another one with global blocked services set to true. IF, that is the case, can you recommend a way to create a toggle switch or alternatively two switches (one for each action) so I can add it to a switch card on my dashboard?

That’s why I don’t use an ‘update’ but add and delete. I have a switch with a turn on action connected to ADD and a turn-off action to delete. This is done by the automations, obviously. And with a different automation, I turn on and off the switch scheduled.

@mhoogenbosch I’m sorry to be so dense, but I spent about an hour trying to figure out the steps here and I just can’t. I think it’s because I’ve used automations via the wizard and blueprints with existing devices.

Is there any chance you can help me understand the steps a bit? For example, do I create a specific switch type and just paste the tailored code in, then add that switch to an automation that is triggered when I flip the dashboard toggle switch?

Any specifics you can provide would be very much appreciated.

I have created a input_boolean called input_boolean.milanadguard. Created this by utilizing the helpers section at devices and servcies. After that I created a really simple automation:

alias: System - Adguard Milan
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.milanadguard
    to: "on"
    id: aan
  - platform: state
    entity_id:
      - input_boolean.milanadguard
    to: "off"
    id: uit
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id:
              - aan
        sequence:
          - service: rest_command.add_adguard_milan
            data: {}
      - conditions:
          - condition: trigger
            id:
              - uit
        sequence:
          - service: rest_command.remove_adguard_milan
            data: {}
mode: single

This automation ensures the on and off state of the input boolean triggers the rest commands. The rest commands are above mentioned.

And this input boolean I’ve added to my dashboard so my wife can also trigger this.

Hopefully I just have to ask you for your patience only one more time. I have set it up like this:

  1. Created an input boolean using the helper
  2. Created a rest_command for each action, so enable_tommy_blocks and disable_tommy_blocks based on your response from 2 days ago. (Only real difference there is I am trying to use update first vs add/delete because the clients are already defined and to keep history and such)
  3. Used automation based on your message from today, but updated entity_id and rest services to match mine (e.g. rest_command.enable_tommy_blocks)
  4. Added the toggle for the input_booean entity to my dashboard.

When I trigger it I get a message that it “calls an unknown service: rest_command.enable_tommy_blocks”

Seems like I am SO, close. I did a quick reload of Home Assistant yamls to see if it just didn’t pick it up. I’m not seeing any errors noted in the yaml. Any ideas why it would seem so perfect and have it trip up?

UPDATE - Decided to do a full restart and I’m not getting the error any more - AWESOME! That said, when I click the toggle I’m not seeing a change in the Adguard client, so I guess I may have to do the add and delete thing after all instead of just update. A bummer, because all I really need it to do is toogle use_global_blocked_services" to true or false - everything else is set up perfectly.

UPDATE 2 - I thought it might be because I have adguard on the firewall vs on the Home Assistant box, but the URL in the rest_command reflects the right path and pasting that URL in a browser gives me a response that only method POST is allowed, so it shoudl be listening to the command. Just isn’t toggling. Again, may just be that update or something doesn’t work.

1 Like

So most things seem fine. When you execute the rest command, do you get any messages in your logs?

You could try and use a curl command from the cli of home assistant to see if that gives an error.

Haven’t given up, but I swapped my laptop this weekend and I had to reload a lot. Anyway, I don’t see any entries in the Logbook. When I use developer tools to run either the enable or disable service, it doesn’t show a change in Adguard and I still don’t see anything in the logbook. I’m going to Google curl syntax to try this from CLI. I had it before the reload and tried it and I can’t remember there being any real error, but I have to look it up again.

 curl -X POST -H "content-Type:application/json" -s -u user:pass adguard.domain.name/control/clients/add -d '{"name": "milan","ids": ["192.168.23.81"],"tags": ["user_child"],"upstreams": [],"filtering_enabled": true,"parental_enabled": false,"safebrowsing_enabled": false,"safesearch_enabled": false,"use_global_blocked_services": false,"use_global_settings": false,"blocked_services": ["9gag","amazon","dailymotion","discord","disneyplus","ebay","epic_games","facebook","hulu","imgur","instagram","mail_ru","netflix","ok","origin","pinterest","qq","reddit","snapchat","steam","telegram","tiktok","tinder","twitch","twitter","viber","vimeo","vk","wechat","weibo","whatsapp","youtube","roblox","onlyfans","fifa"]}'

Is the curl command.

Thanks. I’m getting a 301 Moved Permanently error on this. Looking into that now.

I guess the URL you are using is wrong, maybe try on IP.

Yup, just my thought. No longer getting the 301 error, but now after hitting enter in my ssh window it just sits there hanging. Getting warmer…checking firewall logged for blocked traffic now.

Okay, that was at least part of it. I allowed port 80 and now it seems to be passing the reponses. I’m getting an “invalid name” error, but at least it seems it might just be a syntax thing for me now - though it is odd because that’s the exact name shown in the gui…

What if you first use the add command and then change it to update?