Adguard Home integration - any way to toggle client settings?

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?

So I changed it to add with all the additional parameters you have above, and had it add a test client (test.mydomain.me with an available static ip. That worked great. I then try to use update to change just the global services block setting and it gives me invalid name. Then I strip that last little bit off, change it from update to delete, and it does delete the client.

This done, I readded it and then tried simply updating the ip - invalid name again. Then I tried to do add again, just changing the blocked services to see if it would just change that, and I get a “Client already exists” error.

So your add/delete method works. Really confusing why they don’t have an easy way to just adjust an existing client without recreating it. In any case, thank you so much for helping me get here.

Got the update command to work! The key, it seems, is that the “name” field has to be in there twice - don’t ask me why. Here’s the commands I plan on using to toggle the blocked services on an existing client:

curl -X POST -H "content-Type:application/json" -s -u username:password adguard.domain.name/control/clients/update -d '{"name": "clientname","data":{"name":"clientname","ids": ["192.168.1.192"],"tags": ["device_pc"],"upstreams": [],"filtering_enabled": true,"parental_enabled": true,"safebrowsing_enabled": true,"safesearch_enabled": false,"use_global_blocked_services": true,"use_global_settings": false}}'

curl -X POST -H "content-Type:application/json" -s -u username:password adguard.domain.name/control/clients/update -d '{"name": "clientname","data":{"name":"clientname","ids": ["192.168.1.192"],"tags": ["device_pc"],"upstreams": [],"filtering_enabled": true,"parental_enabled": true,"safebrowsing_enabled": true,"safesearch_enabled": false,"use_global_blocked_services": false,"use_global_settings": false,"blocked_services": ["9gag","activision_blizzard","bilibili","clubhouse","discord","disneyplus","douban","electronic_arts","epic_games","facebook","gog","hulu","icloud_private_relay","instagram","iqiyi","kakaotalk","kik","lazada","leagueoflegends","line","linkedin","mail_ru","mastodon","mercado_libre","minecraft","netflix","nintendo","ok","onlyfans","origin","pinterest","playstation","qq","rakuten_viki","reddit","riot_games","roblox","rockstar_games","shopee","snapchat","steam","telegram","tiktok","tinder","twitch","twitter","ubisoft","valorant","viber","vimeo","vk","voot","wechat","weibo","whatsapp","xboxlive","zhihu"]}}'

My next step is to circle back this evening and see if can get that code into the automation to toggle properly in HA. So, so close!

2 Likes

Glad you got it working!

Guess I have the foundation, anyway. I tried updating the syntax an running the toggle again from HA and still getting nothing. Not sure why, because the helper should’ve set it up right but something’s amiss.

Well, I took the time to double and triple check what we discussed and the HA examples and I was confident all would work with the automation now, but it is not. It seems it might be something basic, but I see an error in the logs

Error: Cannot connect to host 192.168.100.1:81 ssl:default [[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1006)]

(Note: that port number is correct, as the router it runs on has something on 80 already.)

Seems there are a lot of unanswered questions when I search on this, and it works fine from the console so I’m not sure how to proceed at the moment.

Follow up research and trying to hit that URL in a browser leads me to believe an SSL_ERROR_RX_RECORD_TOO_LONG is in play here, too. Wondering if this is due to the very long payload string.

I think I have it! Used my internal proxy URL to redirect it and I think it is working. Exhausted from a long day and fighting a cold so I’m going to continue testing tomorrow and I’ll get an update out.

Okay, confirmed it is working. I am going to mark it as solved, and I’ll note the post with the curl update syntax to highlight that, but the real credit goes to @mhoogenbosch. Just to reiterate, the basic steps are:

  1. Added info for rest enable and disable commands to configuration.yaml
  2. Create input boolean using Helper->Toggle
  3. Create automation.
    Code needed for each can be derived from the posts in the thread. Cheers, all.
1 Like

What is the right ip address format for AGH installed as an addon in HA?
“username:password 192.168.1.123/control/clients/update” not working

Hello @BurntOC
I’m interesting to implement same solution to control my AGH restrictions.
Could you please details how to set it up ?
I’m beginer in HA, and don’t find how to setup.

Thanks in advance for whom who can help me :wink:

Hi,

What is the adguard domain name?
If we set the homeassistant IP then it is not ok, and I get error : Client error occurred when calling resource

Thanks,

It is the name of IP address of the adguard machine.