This Blueprint gives the kids some control over the online time of their game consoles. They can use buttons to start and pause the online time. Parents can add more time if the kids made their shores. Internet access is controlled via the FritzBox.
Required entities
2 datetime (time) helpers for the default time and the additional time the parents can add per klick
3 buttons (play, pause and add)
1 timer
1 fritzbox internet_access switch
The Blueprint
blueprint:
name: Timer based internet access
description: Turn on and off internet access via FritzBox based on a timer
domain: automation
input:
timer:
name: Timer
selector:
entity:
filter:
domain: timer
default_time:
name: Default Time
selector:
entity:
filter:
domain: input_datetime
add_time:
name: Additional Time
selector:
entity:
filter:
domain: input_datetime
add_button:
name: add Button
selector:
entity:
filter:
domain: input_button
pause_button:
name: Pause Button
selector:
entity:
filter:
domain: input_button
play_button:
name: Play Button
selector:
entity:
filter:
domain: input_button
device:
name: FritzBox device
selector:
entity:
filter:
domain: switch
integration: fritz
mode: single
max_exceeded: silent
trigger:
- platform: state
id: add
entity_id: !input add_button
- platform: state
id: pause
entity_id: !input pause_button
- platform: state
id: play
entity_id: !input play_button
- platform: event
id: timer_finished
event_type: timer.finished
event_data:
entity_id: !input timer
- platform: time
id: midnight
at: "00:00:00"
variables:
input_timer: !input timer
input_default_time: !input default_time
input_add_time: !input add_time
action:
- choose:
- conditions:
- condition: trigger
id: add
sequence:
- service: switch.turn_on
target:
entity_id: !input device
- service: timer.start
target:
entity_id: !input timer
data:
duration: >
{% set s = states(input_timer) %}
{% set a = state_attr(input_add_time, 'timestamp') %}
{% set d = as_timestamp(strptime("1970-01-01 " + state_attr(input_timer, 'duration') + "-0000", '%Y-%m-%d %H:%M:%S%z', 0)) | int(0) %}
{% set f = 0 if state_attr(input_timer, 'finishes_at') == none else (state_attr(input_timer, 'finishes_at') | as_datetime - now()).total_seconds() | int(0) %}
{% set r = 0 if state_attr(input_timer, 'remaining') == none else strptime("1970-01-01 " + state_attr(input_timer, 'remaining') + "-0000", '%Y-%m-%d %H:%M:%S%z', 0) | as_timestamp | int(0) %}
{% if s == 'idle' and d <= 10 %} {{ a }}
{% elif s == 'idle' %} {{ a + d }}
{% elif s == 'paused' %} {{ r + a }}
{% elif s == 'active' %} {{ f + a }}
{% endif %}
- conditions:
- condition: and
conditions:
- condition: trigger
id: pause
sequence:
- service: switch.turn_off
target:
entity_id: !input device
- service: timer.pause
target:
entity_id: !input timer
- conditions:
- condition: and
conditions:
- condition: trigger
id: play
- condition: template
value_template: |
{% set d = state_attr(input_timer, 'duration') %}
{{ as_timestamp(strptime('1970-01-01 ' + d, '%Y-%m-%d %H:%M:%S', 0) + timedelta(hours=1)) > 1 }}
- condition: not
conditions:
- condition: state
entity_id: !input timer
state: active
sequence:
- service: switch.turn_on
target:
entity_id: !input device
- service: timer.start
target:
entity_id: !input timer
- conditions:
- condition: trigger
id: timer_finished
sequence:
- service: switch.turn_off
target:
entity_id: !input device
- conditions:
- condition: trigger
id: midnight
sequence:
- service: timer.start
target:
entity_id: !input timer
data:
duration: |
{{ states(input_default_time) | string }}
- service: timer.pause
target:
entity_id: !input timer
I don’t know anything about the experiabox. Does it and more important it’s hass integration have the ability to en-/disable internet access for individual devices?
Thank you. Of course I can. There is a trigger with the id midnight that triggers at midnight.
- platform: time
id: midnight
at: "00:00:00"
And further down there is a condition whose sequence is executed if midnight was triggered. It starts the timer with the default_time and pauses it right after.
I have the ssh command to turn the access to Internet ON/OFF on my router.
Could I use it with this blueprint?
I want my daughter to have ON/OFF switch on her HA app so she can use Internet anytime during the day, but only for 3 hours max per day.
If you can trigger the ssh command with home assistant you can use this. You must just change the device input and switch.turn_on/off service calls to whatever you need.
I expect it is not going to work like that, I want to make sure that I am on the right path. I was thinking to create a device separately, but I am not sure how to do it plus it would be convenient to implement everything into this blueprint directly if possible.
I didn’t use shell commands so I don’t know exactly, but as I understand the documentation you can create a command_line switch in your configuration.yaml
That should create a new switch in your home assistant. You should then be able to use that switch with this blueprint when you remove the integration: fritz filter.
I actually tried exactly that but there is no switch to be found after reboot, so I am confused in terms of what else need to be set to make the switch appear. Might open a new topic for it to get some help. Thank you though once I sort this out hopefully will get to make this blueprint working for my use case.