1
Automation-Examples
sq4ind edited this page 2025-09-28 12:49:11 +00:00

🤖 Automation Examples

Transform your network management with smart automations. These examples show how to create intelligent rules that adapt to your family's needs.

👨‍👩‍👧‍👦 Parental Control Automations

Bedtime Internet Restrictions

Automatically restrict entertainment services for kids at bedtime.

automation:
  - id: kids_bedtime_restrictions
    alias: "Kids Bedtime - Block Entertainment"
    description: "Block entertainment services for kids' devices at bedtime"
    trigger:
      - platform: time
        at: "20:00:00"
    condition:
      - condition: time
        weekday: ['sun', 'mon', 'tue', 'wed', 'thu']  # School nights
    action:
      - service: adguard_hub.block_services
        data:
          client_name: "Kids iPad"
          services: 
            - "youtube"
            - "netflix"
            - "disney_plus"
            - "gaming"
            - "social"
      - service: notify.mobile_app_parents_phone
        data:
          title: "🌙 Bedtime Rules Active"
          message: "Entertainment blocked on kids' devices"

  - id: kids_morning_unblock_educational
    alias: "Kids Morning - Allow Educational Content"
    description: "Unblock educational content during school hours"
    trigger:
      - platform: time
        at: "07:00:00"
    condition:
      - condition: time
        weekday: ['mon', 'tue', 'wed', 'thu', 'fri']  # School days
    action:
      - service: adguard_hub.unblock_services
        data:
          client_name: "Kids iPad"
          services: ["educational"]
      - service: adguard_hub.block_services
        data:
          client_name: "Kids iPad"
          services: ["gaming", "social"]  # Keep these blocked during school

Weekend vs Weekday Rules

Different internet policies for school days and weekends.

automation:
  - id: weekend_relaxed_rules
    alias: "Weekend - Relaxed Rules for Kids"
    description: "Allow more entertainment on weekends"
    trigger:
      - platform: time
        at: "09:00:00"
    condition:
      - condition: time
        weekday: ['sat', 'sun']
    action:
      - service: adguard_hub.update_client
        data:
          name: "Kids iPad"
          blocked_services: ["adult", "gambling"]  # Only block harmful content
      - service: persistent_notification.create
        data:
          title: "🎮 Weekend Mode"
          message: "Relaxed internet rules now active for kids"

  - id: school_night_strict_rules
    alias: "School Night - Strict Rules"
    description: "Apply strict rules on school nights"
    trigger:
      - platform: time
        at: "18:00:00"  # After school
    condition:
      - condition: time
        weekday: ['sun', 'mon', 'tue', 'wed', 'thu']
    action:
      - service: adguard_hub.block_services
        data:
          client_name: "Kids iPad"
          services: ["social", "gaming"]
          schedule:
            enabled: true
            time_zone: "Local"
            sun: { start: "18:00", end: "19:00" }  # 1 hour on Sunday
            mon: { start: "19:00", end: "20:00" }  # 1 hour after homework
            tue: { start: "19:00", end: "20:00" }
            wed: { start: "19:00", end: "20:00" }
            thu: { start: "19:00", end: "20:00" }

Homework Time Restrictions

Block distractions during study hours.

automation:
  - id: homework_time_focus
    alias: "Homework Time - Enable Focus Mode"
    description: "Block distractions during homework hours"
    trigger:
      - platform: time
        at: "16:00:00"  # After school
    condition:
      - condition: time
        weekday: ['mon', 'tue', 'wed', 'thu', 'fri']
      - condition: state
        entity_id: input_boolean.school_holiday
        state: 'off'
    action:
      - service: adguard_hub.block_services
        data:
          client_name: "Kids Laptop"
          services: ["social", "entertainment", "gaming"]
      - service: tts.google_translate_say
        data:
          entity_id: media_player.kids_room_speaker
          message: "Homework time! Internet restrictions are now active."

  - id: homework_time_end
    alias: "Homework Time - End Focus Mode"
    description: "Allow limited entertainment after homework"
    trigger:
      - platform: time
        at: "18:00:00"
    condition:
      - condition: time
        weekday: ['mon', 'tue', 'wed', 'thu', 'fri']
    action:
      - service: adguard_hub.unblock_services
        data:
          client_name: "Kids Laptop"
          services: ["entertainment"]  # Allow some entertainment
      - service: tts.google_translate_say
        data:
          entity_id: media_player.kids_room_speaker
          message: "Good job on homework! You can now watch videos."

💼 Work Productivity Automations

Work Hours Focus Mode

Eliminate distractions during work hours.

automation:
  - id: work_hours_focus_mode
    alias: "Work Hours - Enable Focus Mode"
    description: "Block distracting services during work hours"
    trigger:
      - platform: time
        at: "09:00:00"
    condition:
      - condition: time
        weekday: ['mon', 'tue', 'wed', 'thu', 'fri']
      - condition: state
        entity_id: person.work_user
        state: 'home'
    action:
      - service: adguard_hub.block_services
        data:
          client_name: "Work Laptop"
          services:
            - "social"
            - "entertainment"
            - "gaming"
            - "shopping"
          schedule:
            enabled: true
            time_zone: "Local"
            mon: { start: "09:00", end: "17:00" }
            tue: { start: "09:00", end: "17:00" }
            wed: { start: "09:00", end: "17:00" }
            thu: { start: "09:00", end: "17:00" }
            fri: { start: "09:00", end: "17:00" }
      - service: notify.mobile_app_work_phone
        data:
          title: "💼 Work Mode Active"
          message: "Focus mode enabled - distractions blocked"

  - id: lunch_break_temporary_unblock
    alias: "Lunch Break - Temporary Social Access"
    description: "Allow social media during lunch break"
    trigger:
      - platform: time
        at: "12:00:00"
    condition:
      - condition: time
        weekday: ['mon', 'tue', 'wed', 'thu', 'fri']
      - condition: state
        entity_id: person.work_user
        state: 'home'
    action:
      - service: adguard_hub.emergency_unblock
        data:
          duration: 3600  # 1 hour
          clients: ["Work Laptop"]
      - service: notify.mobile_app_work_phone
        data:
          title: "🍽️ Lunch Break"
          message: "Enjoy your lunch! Full access for 1 hour."

  - id: meeting_mode_bandwidth_priority
    alias: "Meeting Mode - Prioritize Bandwidth"
    description: "Block bandwidth-heavy services during meetings"
    trigger:
      - platform: state
        entity_id: calendar.work_meetings
        to: 'on'
    action:
      - service: adguard_hub.bulk_update_clients
        data:
          client_pattern: "*"  # All clients
          settings:
            blocked_services: ["netflix", "youtube", "gaming", "torrents"]
      - delay: 
          seconds: 30
      - service: notify.family_group
        data:
          title: "📹 Meeting in Progress"
          message: "Bandwidth-heavy services temporarily blocked"

Deep Work Sessions

Integrate with focus time trackers or calendars.

automation:
  - id: deep_work_session_start
    alias: "Deep Work - Maximum Focus"
    description: "Block all distractions during deep work sessions"
    trigger:
      - platform: state
        entity_id: input_boolean.deep_work_mode
        to: 'on'
    action:
      - service: adguard_hub.block_services
        data:
          client_name: "Work Laptop"
          services: ["social", "entertainment", "news", "shopping"]
      - service: light.turn_on
        data:
          entity_id: light.office_desk_lamp
          color_name: "red"
          brightness: 100
      - service: media_player.play_media
        data:
          entity_id: media_player.office_speaker
          media_content_id: "https://example.com/focus-sounds.mp3"
          media_content_type: "music"

  - id: deep_work_session_end
    alias: "Deep Work - Session Complete"
    description: "Restore normal access after deep work"
    trigger:
      - platform: state
        entity_id: input_boolean.deep_work_mode
        to: 'off'
    action:
      - service: adguard_hub.unblock_services
        data:
          client_name: "Work Laptop"
          services: ["news"]  # Allow news but keep social blocked
      - service: light.turn_on
        data:
          entity_id: light.office_desk_lamp
          color_name: "green"
          brightness: 80
      - service: notify.mobile_app_work_phone
        data:
          title: "✅ Deep Work Complete"
          message: "Great job! Take a well-deserved break."

🏠 Presence-Based Automations

Away Mode Security

Strict filtering when nobody is home.

automation:
  - id: away_mode_strict_filtering
    alias: "Away Mode - Enable Strict Filtering"
    description: "Enable strict filtering when nobody is home"
    trigger:
      - platform: state
        entity_id: group.family
        to: 'not_home'
        for: '00:30:00'  # 30 minutes after everyone leaves
    action:
      - service: adguard_hub.bulk_update_clients
        data:
          client_pattern: "*"
          settings:
            parental_enabled: true
            safebrowsing_enabled: true
            safesearch_enabled: true
            blocked_services: ["social", "entertainment", "gaming"]
      - service: notify.family_group
        data:
          title: "🔒 Away Mode Active"
          message: "Strict filtering enabled for all devices"
      - service: light.turn_on
        data:
          entity_id: light.front_porch
          brightness: 255

  - id: home_mode_restore_normal
    alias: "Home Mode - Restore Normal Filtering"
    description: "Restore normal filtering when someone comes home"
    trigger:
      - platform: state
        entity_id: group.family
        to: 'home'
    action:
      - service: adguard_hub.bulk_update_clients
        data:
          client_pattern: "*"
          settings:
            parental_enabled: false
            safebrowsing_enabled: true
            safesearch_enabled: false
      - service: notify.mobile_app_parents_phone
        data:
          title: "🏠 Welcome Home"
          message: "Normal internet access restored"

Guest Arrival/Departure

Automatic guest network management.

automation:
  - id: guest_arrived_welcome
    alias: "Guest Arrived - Open Access"
    description: "Remove restrictions when guests arrive"
    trigger:
      - platform: state
        entity_id: device_tracker.guest_phone
        to: 'home'
    action:
      - service: adguard_hub.update_client
        data:
          name: "Guest Network"
          use_global_settings: false
          blocked_services: []  # Unblock all services
      - service: tts.google_translate_say
        data:
          entity_id: media_player.living_room_speaker
          message: "Welcome! Guest network access has been opened."
      - service: persistent_notification.create
        data:
          title: "🏠 Guest Access"
          message: "Guest network restrictions removed"
          notification_id: "guest_access"

  - id: guest_departed_restrictions
    alias: "Guest Left - Enable Restrictions"
    description: "Re-enable restrictions after guest leaves"
    trigger:
      - platform: state
        entity_id: device_tracker.guest_phone
        to: 'away'
        for: '01:00:00'  # 1 hour after leaving
    action:
      - service: adguard_hub.update_client
        data:
          name: "Guest Network"
          blocked_services: ["adult", "gambling", "torrents"]
          parental_enabled: true
      - service: persistent_notification.dismiss
        data:
          notification_id: "guest_access"

📺 Smart TV & Entertainment Automations

Movie Night Mode

Special rules for family entertainment time.

automation:
  - id: movie_night_unblock_streaming
    alias: "Movie Night - Unblock Streaming"
    description: "Unblock streaming services for family movie night"
    trigger:
      - platform: state
        entity_id: input_boolean.movie_night_mode
        to: 'on'
    action:
      - service: adguard_hub.unblock_services
        data:
          client_name: "Living Room TV"
          services: ["netflix", "disney_plus", "amazon_video", "youtube"]
      - service: adguard_hub.bulk_update_clients
        data:
          client_pattern: "Kids*"
          settings:
            blocked_services: ["social"]  # Block social but allow streaming
      - service: light.turn_on
        data:
          entity_id: light.living_room
          brightness: 30
          color_name: "purple"
      - service: notify.family_group
        data:
          title: "🍿 Movie Night!"
          message: "Streaming services unlocked, lights dimmed. Enjoy!"

  - id: movie_night_end_restrictions
    alias: "Movie Night End - Restore Blocks"
    description: "Re-enable blocks after movie night"
    trigger:
      - platform: state
        entity_id: input_boolean.movie_night_mode
        to: 'off'
    action:
      - service: adguard_hub.block_services
        data:
          client_name: "Living Room TV"
          services: ["netflix", "disney_plus", "amazon_video"]
      - service: adguard_hub.bulk_update_clients
        data:
          client_pattern: "Kids*"
          settings:
            blocked_services: ["social", "entertainment"]  # Restore normal blocks
      - service: light.turn_on
        data:
          entity_id: light.living_room
          brightness: 100
          color_name: "white"

Gaming Time Limits

Control gaming device access based on time and behavior.

automation:
  - id: gaming_console_time_limits
    alias: "Gaming Console - Time-Based Access"
    description: "Allow gaming only during specific hours"
    trigger:
      - platform: time
        at: "15:00:00"  # 3 PM - after school
    condition:
      - condition: time
        weekday: ['sat', 'sun']  # Weekends only
      - condition: state
        entity_id: input_boolean.chores_completed
        state: 'on'  # Only if chores are done
    action:
      - service: adguard_hub.unblock_services
        data:
          client_name: "PlayStation 5"
          services: ["gaming", "playstation", "steam"]
      - service: timer.start
        data:
          entity_id: timer.gaming_session
          duration: "02:00:00"  # 2 hours
      - service: notify.mobile_app_kids_phone
        data:
          title: "🎮 Gaming Time!"
          message: "You have 2 hours of gaming time. Have fun!"

  - id: gaming_time_warning
    alias: "Gaming Time - 15 Minute Warning"
    description: "Warn when gaming time is almost up"
    trigger:
      - platform: event
        event_type: timer.finished
        event_data:
          entity_id: timer.gaming_warning
    action:
      - service: tts.google_translate_say
        data:
          entity_id: media_player.kids_room_speaker
          message: "Gaming time ends in 15 minutes. Start wrapping up!"
      - service: timer.start
        data:
          entity_id: timer.gaming_final_warning
          duration: "00:15:00"

  - id: gaming_console_bedtime_block
    alias: "Gaming Console - Bedtime Block"
    description: "Block gaming at bedtime"
    trigger:
      - platform: time
        at: "21:00:00"  # 9 PM bedtime
    action:
      - service: adguard_hub.block_services
        data:
          client_name: "PlayStation 5"
          services: ["gaming", "playstation", "steam"]
      - service: notify.mobile_app_kids_phone
        data:
          title: "🌙 Bedtime"
          message: "Gaming is now blocked. Time for bed!"

🚨 Emergency & Safety Automations

Emergency Unblock Button

Quick access for urgent situations.

automation:
  - id: emergency_unblock_button
    alias: "Emergency Unblock Button"
    description: "Emergency unblock when button is pressed"
    trigger:
      - platform: state
        entity_id: input_button.emergency_unblock
    action:
      - service: adguard_hub.emergency_unblock
        data:
          duration: 600  # 10 minutes
          clients: ["all"]
      - service: notify.family_group
        data:
          title: "🚨 EMERGENCY ACCESS"
          message: "All internet restrictions temporarily disabled for 10 minutes"
          data:
            priority: high
            color: red
      - service: light.turn_on
        data:
          entity_id: light.emergency_indicator
          color_name: "red"
          brightness: 255
          effect: "flash"

  - id: emergency_unblock_auto_restore
    alias: "Emergency Unblock - Auto Restore"
    description: "Automatically restore protection after emergency unblock"
    trigger:
      - platform: state
        entity_id: switch.adguard_protection
        to: 'off'
        for: '00:10:00'  # 10 minutes
    condition:
      - condition: state
        entity_id: input_boolean.manual_protection_disable
        state: 'off'
    action:
      - service: switch.turn_on
        entity_id: switch.adguard_protection
      - service: notify.family_group
        data:
          title: "🛡️ Protection Restored"
          message: "Internet filtering has been automatically restored"
      - service: light.turn_off
        entity_id: light.emergency_indicator

Health Emergency Override

Override all restrictions for health emergencies.

automation:
  - id: health_emergency_override
    alias: "Health Emergency - Full Override"
    description: "Remove all restrictions during health emergencies"
    trigger:
      - platform: state
        entity_id: input_boolean.health_emergency
        to: 'on'
    action:
      - service: adguard_hub.emergency_unblock
        data:
          duration: 3600  # 1 hour
          clients: ["all"]
      - service: adguard_hub.bulk_update_clients
        data:
          client_pattern: "*"
          settings:
            blocked_services: []
            parental_enabled: false
            safebrowsing_enabled: false
      - service: notify.emergency_contacts
        data:
          title: "🆘 HEALTH EMERGENCY MODE"
          message: "All internet restrictions removed. Emergency protocols active."
          data:
            priority: critical
            ttl: 0

📅 Schedule-Based Automations

Weekly Schedule Management

Different rules for different days of the week.

automation:
  - id: weekly_schedule_sunday_family_time
    alias: "Sunday - Family Time Rules"
    description: "Special rules for Sunday family time"
    trigger:
      - platform: time
        at: "10:00:00"
    condition:
      - condition: time
        weekday: ['sun']
    action:
      - service: adguard_hub.bulk_update_clients
        data:
          client_pattern: "*"
          settings:
            blocked_services: ["adult", "gambling"]  # Minimal blocks
      - service: persistent_notification.create
        data:
          title: "👨‍👩‍👧‍👦 Family Day"
          message: "Relaxed internet rules for family time"

  - id: school_preparation_sunday_evening
    alias: "Sunday Evening - School Prep Mode"
    description: "Prepare for school week on Sunday evening"
    trigger:
      - platform: time
        at: "18:00:00"
    condition:
      - condition: time
        weekday: ['sun']
    action:
      - service: adguard_hub.bulk_update_clients
        data:
          client_pattern: "Kids*"
          settings:
            blocked_services: ["social", "entertainment", "gaming"]
      - service: notify.family_group
        data:
          title: "📚 School Week Prep"
          message: "School-night rules now active. Time to prepare for the week!"

🔔 Notification Integration

Smart Notifications

Get informed about rule changes and network activity.

automation:
  - id: notify_service_blocked
    alias: "Notify - Service Blocked"
    description: "Send notification when services are blocked"
    trigger:
      - platform: state
        entity_id: 
          - switch.adguard_client_kids_ipad_service_youtube
          - switch.adguard_client_kids_ipad_service_gaming
        to: 'on'  # Service is blocked
    action:
      - service: notify.mobile_app_parents_phone
        data:
          title: "🛡️ Service Blocked"
          message: "{{ trigger.to_state.attributes.friendly_name }} is now active"
          data:
            actions:
              - action: "UNBLOCK_TEMPORARILY"
                title: "Unblock for 1 hour"
              - action: "VIEW_DASHBOARD"
                title: "Open Dashboard"

  - id: notify_emergency_unblock_used
    alias: "Notify - Emergency Unblock Used"
    description: "Alert when emergency unblock is activated"
    trigger:
      - platform: state
        entity_id: switch.adguard_protection
        to: 'off'
    condition:
      - condition: template
        value_template: "{{ trigger.from_state.state == 'on' }}"
    action:
      - service: notify.family_group
        data:
          title: "⚠️ AdGuard Protection Disabled"
          message: "AdGuard protection has been temporarily disabled"
          data:
            priority: high
            persistent: true
            actions:
              - action: "ENABLE_PROTECTION"
                title: "Re-enable Now"

Next: Explore Service Reference for complete service documentation or check out Troubleshooting if you need help!