Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- input_number:
- child_1_extra_screen_time:
- name: "Child 1 temps supplémentaire"
- min: -600
- max: 600
- step: 1
- mode: box
- unit_of_measurement: "min"
- child_1_correction_screen_time:
- name: "Child 1 correction screen time"
- min: -1500
- max: 1500
- step: 1
- mode: box
- unit_of_measurement: "min"
- child_2_extra_screen_time:
- name: "Child 2 temps supplémentaire"
- min: -600
- max: 600
- step: 1
- mode: box
- unit_of_measurement: "min"
- child_2_correction_screen_time:
- name: "Child 2 correction screen time"
- min: -1500
- max: 1500
- step: 1
- mode: box
- unit_of_measurement: "min"
- input_boolean:
- child_1_screen_time_active:
- name: "Child 1 is consuming screen time"
- child_2_screen_time_active:
- name: "Child 2 is consuming screen time"
- homeassistant:
- customize:
- input_number.child_1_extra_screen_time:
- icon: "mdi:gift"
- input_number.child_2_extra_screen_time:
- icon: "mdi:gift"
- sensor:
- - platform: history_stats
- name: Child 1 screen time this week
- entity_id: input_boolean.child_1_screen_time_active
- state: "on"
- type: time
- start: "{{ as_timestamp(now().replace(hour=0, minute=0, second=0)) - now().weekday() * 86400 }}"
- end: "{{ now() }}"
- - platform: history_stats
- name: Child 1 screen time today
- entity_id: input_boolean.child_1_screen_time_active
- state: "on"
- type: time
- start: "{{ now().replace(hour=0, minute=0, second=0) }}"
- end: "{{ now() }}"
- - platform: history_stats
- name: Child 2 screen time this week
- entity_id: input_boolean.child_2_screen_time_active
- state: "on"
- type: time
- start: "{{ as_timestamp(now().replace(hour=0, minute=0, second=0)) - now().weekday() * 86400 }}"
- end: "{{ now() }}"
- - platform: history_stats
- name: Child 2 screen time today
- entity_id: input_boolean.child_2_screen_time_active
- state: "on"
- type: time
- start: "{{ now().replace(hour=0, minute=0, second=0) }}"
- end: "{{ now() }}"
- template:
- - sensor:
- - unique_id: weekly_screen_time
- name: "Weekly screen time"
- state: "{{ 720 if is_state('binary_sensor.school_holiday', 'on') else 360 }}"
- - unique_id: child_1_weekly_screen_time_threshold
- name: "Child 1 weekly screen time threshold"
- state: "{{ states('sensor.weekly_screen_time') | int(0) + states('input_number.child_1_extra_screen_time') | int(0) }}"
- availability: "{{ states('sensor.weekly_screen_time') | is_number() and states('input_number.child_1_extra_screen_time') | is_number() }}"
- unit_of_measurement: "min"
- - unique_id: child_1_corrected_screen_time_this_week
- name: "Child 1 corrected screen time this week"
- state: "{{ states('sensor.child_1_screen_time_this_week') | float(0) * 60 - states('input_number.child_1_correction_screen_time') | int(0) }}"
- availability: "{{ states('sensor.child_1_screen_time_this_week') | is_number() and states('input_number.child_1_correction_screen_time') | is_number() }}"
- unit_of_measurement: "min"
- - unique_id: child_1_weekly_screen_time_remaining
- name: "Child 1 weekly screen time remaining"
- state: "{{ states('sensor.child_1_weekly_screen_time_threshold') | int(0) - states('sensor.child_1_screen_time_this_week') | int(0) }}"
- availability: "{{ states('sensor.child_1_weekly_screen_time_threshold') | is_number() and states('sensor.child_1_screen_time_this_week') | is_number() }}"
- unit_of_measurement: "min"
- - unique_id: child_2_weekly_screen_time_threshold
- name: "Child 2 weekly screen time threshold"
- state: "{{ states('sensor.weekly_screen_time') | int(0) + states('input_number.child_2_extra_screen_time') | int(0) }}"
- availability: "{{ states('sensor.weekly_screen_time') | is_number() and states('input_number.child_2_extra_screen_time') | is_number() }}"
- unit_of_measurement: "min"
- - unique_id: child_2_corrected_screen_time_this_week
- name: "Child 2 corrected screen time this week"
- state: "{{ states('sensor.child_2_screen_time_this_week') | float(0) * 60 - states('input_number.child_2_correction_screen_time') | int(0) }}"
- availability: "{{ states('sensor.child_2_screen_time_this_week') | is_number() and states('input_number.child_2_correction_screen_time') | is_number() }}"
- unit_of_measurement: "min"
- - unique_id: child_2_weekly_screen_time_remaining
- name: "Child 2 weekly screen time remaining"
- state: "{{ states('sensor.child_2_weekly_screen_time_threshold') | int(0) - states('sensor.child_2_screen_time_this_week') | int(0) }}"
- availability: "{{ states('sensor.child_2_weekly_screen_time_threshold') | is_number() and states('sensor.child_2_screen_time_this_week') | is_number() }}"
- unit_of_measurement: "min"
- automation:
- - id: reset_extra_screen_time
- alias: "Reset extra screen time"
- mode: single
- max_exceeded: silent
- trigger:
- - platform: time
- at: "00:00:00"
- condition:
- condition: time
- weekday:
- - mon
- action:
- - service: input_number.set_value
- target:
- entity_id: input_number.child_1_extra_screen_time
- data:
- value: >-
- {% if states('input_number.child_1_extra_screen_time') | int(0) >= 0 %}
- {{ min(states('input_number.child_1_extra_screen_time') | int(0), states('sensor.child_1_weekly_screen_time_remaining') | int(0)) }}
- {% else %}
- {{ min(0, 0 + states('input_number.child_1_extra_screen_time') | int(0) + states('sensor.weekly_screen_time') | int(0)) }}
- {% endif %}
- - service: input_number.set_value
- target:
- entity_id: input_number.child_2_extra_screen_time
- data:
- value: >-
- {% if states('input_number.child_2_extra_screen_time') | int(0) >= 0 %}
- {{ min(states('input_number.child_2_extra_screen_time') | int(0), states('sensor.child_2_weekly_screen_time_remaining') | int(0)) }}
- {% else %}
- {{ min(0, 0 + states('input_number.child_2_extra_screen_time') | int(0) + states('sensor.weekly_screen_time') | int(0)) }}
- {% endif %}
Advertisement
Add Comment
Please, Sign In to add comment