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:
domain: timer
default_time:
name: Default Time
selector:
entity:
domain: input_datetime
add_time:
name: Additional Time
selector:
entity:
domain: input_datetime
add_button:
name: add Button
selector:
entity:
domain: input_button
pause_button:
name: Pause Button
selector:
entity:
domain: input_button
play_button:
name: Play Button
selector:
entity:
domain: input_button
device:
name: FritzBox device
selector:
entity:
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: timer.start
target:
entity_id: !input timer
data:
duration: 1
- service: timer.cancel
target:
entity_id: !input timer
- 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