Managing your Child’s Computer Usage with Home Assistant

by Pete
Published: Updated: 9 minutes read

In today’s digital age, managing your child’s screen time has become a crucial aspect of parenting. Similar to Apple’s Screen Time feature, Home Assistant offers a powerful solution to help you efficiently control and monitor your child’s computer usage.

This guide provides a step-by-step walk through of creating a robust Home Assistant setup that empowers you to manage your child’s computer time effectively.

Requirements

Prior to initiation, kindly ensure the completion of the following tasks:

  • Install the RPC Shutdown Addon: To remotely control your child’s computer, you’ll need to install the RPC Shutdown addon on your Home Assistant instance.
  • Create an Admin Account: On the child’s Windows PC, create an admin account that Home Assistant will use to send shutdown commands. This account will ensure secure and authorized access.
  • Modify Registry Key:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]
"LocalAccountTokenFilterPolicy"=dword:00000001
  • Addon Configuration: Configure the RPC Shutdown addon to include your child’s computer. Use the provided aliases, addresses, credentials, delay, and message in the configuration. Example:
- alias: example.fqdn
  address: example.fqdn
  credentials: admin_username%password
  delay: 0
  message: >-
    Home Assistant is shutting down this PC. This cannot be aborted. Please save your work!

Setting Up the Automation

Next, let’s delve into setting up the Home Assistant automation to manage your child’s computer usage.

1
Let’s break down how it works

  1. Trigger: The automation is triggered every minute by the time_pattern trigger. This ensures that the automation runs frequently to monitor your child’s computer usage.
  2. Conditions and Actions: The automation begins with a series of conditional checks and corresponding actions.
    • Between Midnight and 5 AM: During this period, if the automation triggers, it resets the counter that keeps track of your child’s computer usage (counter.computer_name_counter) and turns off the input_boolean.desktop_a0o6jhr_homework, indicating that it’s not homework time.
    • Weekdays from 6:30 AM to Midnight (Mon-Thu): If the time falls within this range on weekdays, the automation checks if it’s homework time (input_boolean.computer_name_homework is turned on) and if the computer usage has exceeded 90 minutes. If both conditions are met, it sends a shutdown command to the designated computer (switch.pc190ha03_power). If not, and if the computer is in an “on” state, it increments the computer usage counter.
    • Weekends from 6:30 AM to Midnight (Sat-Sun): Similar to weekdays, this section handles weekends. It checks if it’s homework time and if the computer usage has exceeded 240 minutes.
    • Fridays from 6:30 AM to Midnight: On Fridays, the automation checks if it’s homework time and if the computer usage has exceeded 120 minutes.
  3. Mode: The automation operates in a single mode, which means it will only run once per trigger event.

2
Supporting Helper entities

These helper entities work in tandem with the automation’s conditions and actions to implement a comprehensive screen time management system.

  • counter.computer_name_counter: This counter effectively maintains a running record of the duration of your child’s computer usage.
  • input_boolean.computer_name_homework: Serving as a practical toggle.
  • switch.pc190ha03_power: Operating as a virtual lever, this switch entity symbolizes the specific computer you have in mind for control purposes.
  • binary_sensor.computer_name_pc: As a valuable binary sensor entity, this component reflects the current status of your child’s PC. Importantly, when the computer is powered on, the corresponding timer increments accordingly.

3
The Final Automation

alias: computer_name Usage
description: ""
trigger:
  - platform: time_pattern
    minutes: /1
condition: []
action:
  - if:
      - condition: time
        after: "00:00:00"
        before: "00:05:00"
    then:
      - service: counter.reset
        data: {}
        target:
          entity_id: counter.computer_name_counter
      - service: input_boolean.turn_off
        data: {}
        target:
          entity_id: input_boolean.computer_name_homework
    enabled: true
  - choose:
      - conditions:
          - condition: time
            after: "06:30:00"
            before: "23:59:59"
            weekday:
              - mon
              - tue
              - wed
              - thu
        sequence:
          - if:
              - condition: and
                conditions:
                  - condition: state
                    entity_id: input_boolean.computer_name_homework
                    state: "on"
                  - condition: numeric_state
                    entity_id: counter.computer_name_counter
                    above: 90
            then:
              - service: switch.turn_on
                data: {}
                target:
                  entity_id: switch.pc190ha03_power
            else:
              - if:
                  - condition: state
                    entity_id: input_boolean.computer_name_homework
                    state: "off"
                then:
                  - if:
                      - condition: state
                        entity_id: binary_sensor.computer_name
                        state: "on"
                    then:
                      - service: counter.increment
                        data: {}
                        target:
                          entity_id: counter.computer_name_counter
          - if:
              - condition: and
                conditions:
                  - condition: state
                    entity_id: input_boolean.computer_name_homework
                    state: "off"
                  - condition: numeric_state
                    entity_id: counter.computer_name_counter
                    above: 120
            then:
              - service: script.computer_name_shutdown
                data: {}
      - conditions:
          - condition: time
            weekday:
              - sun
              - sat
            after: "06:30:00"
            before: "23:59:59"
        sequence:
          - if:
              - condition: and
                conditions:
                  - condition: state
                    entity_id: input_boolean.computer_name_homework
                    state: "on"
                  - condition: numeric_state
                    entity_id: counter.computer_name_counter
                    above: 240
            then:
              - service: switch.turn_on
                data: {}
                target:
                  entity_id: switch.pc190ha03_power
            else:
              - if:
                  - condition: state
                    entity_id: input_boolean.computer_name_homework
                    state: "off"
                then:
                  - if:
                      - condition: state
                        entity_id: binary_sensor.computer_name
                        state: "on"
                    then:
                      - service: counter.increment
                        data: {}
                        target:
                          entity_id: counter.computer_name_counter
          - if:
              - condition: and
                conditions:
                  - condition: state
                    entity_id: input_boolean.computer_name_homework
                    state: "off"
                  - condition: numeric_state
                    entity_id: counter.computer_name_counter
                    above: 240
            then:
              - service: script.computer_name_shutdown
                data: {}
      - conditions:
          - condition: time
            weekday:
              - fri
            after: "06:30:00"
            before: "23:59:59"
        sequence:
          - if:
              - condition: and
                conditions:
                  - condition: state
                    entity_id: input_boolean.computer_name_homework
                    state: "on"
                  - condition: numeric_state
                    entity_id: counter.computer_name_counter
                    above: 120
            then:
              - service: switch.turn_on
                data: {}
                target:
                  entity_id: switch.pc190ha03_power
            else:
              - if:
                  - condition: state
                    entity_id: input_boolean.computer_name_homework
                    state: "off"
                then:
                  - if:
                      - condition: state
                        entity_id: binary_sensor.computer_name
                        state: "on"
                    then:
                      - service: counter.increment
                        data: {}
                        target:
                          entity_id: counter.computer_name_counter
          - if:
              - condition: and
                conditions:
                  - condition: state
                    entity_id: input_boolean.computer_name_homework
                    state: "off"
                  - condition: numeric_state
                    entity_id: counter.computer_name_counter
                    above: 120
            then:
              - service: script.computer_name_shutdown
                data: {}
mode: single

4
Designing the Lovelace Dashboard

lovelace_computer_time.png

To enhance your monitoring experience, consider designing a Lovelace dashboard within Home Assistant. Utilize Lovelace cards to display usage statistics, power status, and other relevant information. This dashboard provides a visual snapshot of your child’s computer activity.

type: vertical-stack
cards:
  - type: custom:mushroom-title-card
    title: Child's Computer Time
    subtitle: ''
  - type: markdown
    content: |-
      **Default Computer Time Allowances**
      Mon - Thurs: - 1.5 Hours / Night
      Fri: - 2 Hours / Night
      Weekends: - 4 Hours / Day
      Notes:
      Press the Homework button to allow more time or pause the counter.
      Counter will only increment when Child's computer is on.
  - square: false
    columns: 2
    type: grid
    cards:
      - type: tile
        entity: counter.computer_name_counter
        name: Computer Time Today
        vertical: true
      - type: tile
        entity: input_boolean.computer_name_homework
        name: Homework Time?
        vertical: true
  - type: tile
    entity: automation.computer_name_timer
    name: Child's Computer Time Automation

Conclusion

By adhering to the steps laid out in this comprehensive guide, you’ll adeptly set up an efficient screen time management solution through Home Assistant. The orchestrated interplay of automations, remote shutdown functionalities, and the interactive Lovelace dashboard will empower you to craft a secure and well-rounded digital ecosystem for your child.