Block youtube during certain times

i use Adguard and it works great to block sites like Youtube.

but as of now, i have to manually turn it on and off for my kids. So they cant watch youtube during school hours from 8am to 3pm. they can watch whatever after for 1hour.
is there a way to automate this process? if Adguard cant do it, what can? i know there are free software that can do this but i am hoping HA can

Use the built in services to adguard. Something like below (untested…don’t have adguard)

trigger:
  - platform: time
    at: "08:00:00"
  - platform: time
    at: "15:00:00"
action:
  - service: "adguard.{{ 'enable' if trigger.now.hour == 8 else 'disable'}}_url"
    data:
      url: "https://www.youtube.com"

Please tell me if you find a solution. I am looking for it for the same purpose. The most difficult will be to allow them for an hour.

hi gang - trying to do something similar - I’d like to block various services at per a schedule.

Also need to do this. Thinking I’ll just have Hass kill any stream going to the Nvidia shields.

I’m trying to figure out this at the moment.

What I know is that, at least, the AdGuard Home integration that Jim mentioned above is unfortunately not what we are looking for.

Reading the documentation of the integration, the enable_url and disable_url (and add_url & remove_url) actions are designed to manipulate filter subscription addresses
image
… which would be under the DNS blocklists section, if you want to do the same from GUI.

… so, not the actions / services where you can add & remove, say, www.youtube.com with any automation.

Well… unless you make or find a filter rule txt file specifically for blocking youtube and youtube only.

So, if anyone has any luck, please share.

I have made some progresses, though. Let me share the paths I have went through:

  • In AdGuard Home, there is this place where you can go and block services. Ideally I’m looking for a way to filp the youtube switch here based on automation.
    image
  • There is official REST API from GitHub, per the AdGuard documentation
  • And per the document, one can use /blocked_services/get and /blocked_services/update to update the blocked services. To see yours, try http://x.x.x.x:port/control/blocked_services/get on your AGH ip:port
  • So far I have managed to grab all the blocked services, and write the info into an attribute of a sensor.
sensors:
- platform: rest
  name: "Blocked Services per AdGuard Home"
  unique_id: "agh_blocked_services"
  authentication: basic
  username: !secret user
  password: !secret pwd
  resource: http://ip:port/control/blocked_services/get
  method: GET
  headers:
    User-Agent: Homeassistant REST
    Content-Type: application/json
  value_template: '1'   # dummy value because we are going to save the list into attribute instead - see next line - but the state of the sensor has to have something.
  json_attributes: 
    - ids
  scan_interval: 60
  verify_ssl: false

I suppose the gameplan / next steps are to use the attribute data of the sensor above, and add/remove youtube to the data, and update the data back to AdGuard Home, using /blocked_services/update.

So this is where I’m am… I just have not figured out how to proceed with the gameplan above. (Yup I’m coding newbie here.)

So another user 230 has figured this out! See #11 of this thread:

1 Like