Guest User

Untitled

a guest
Dec 6th, 2023
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.22 KB | None | 0 0
  1. input_number:
  2. child_1_extra_screen_time:
  3. name: "Child 1 temps supplémentaire"
  4. min: -600
  5. max: 600
  6. step: 1
  7. mode: box
  8. unit_of_measurement: "min"
  9.  
  10. child_1_correction_screen_time:
  11. name: "Child 1 correction screen time"
  12. min: -1500
  13. max: 1500
  14. step: 1
  15. mode: box
  16. unit_of_measurement: "min"
  17.  
  18. child_2_extra_screen_time:
  19. name: "Child 2 temps supplémentaire"
  20. min: -600
  21. max: 600
  22. step: 1
  23. mode: box
  24. unit_of_measurement: "min"
  25.  
  26. child_2_correction_screen_time:
  27. name: "Child 2 correction screen time"
  28. min: -1500
  29. max: 1500
  30. step: 1
  31. mode: box
  32. unit_of_measurement: "min"
  33.  
  34. input_boolean:
  35. child_1_screen_time_active:
  36. name: "Child 1 is consuming screen time"
  37. child_2_screen_time_active:
  38. name: "Child 2 is consuming screen time"
  39.  
  40. homeassistant:
  41. customize:
  42. input_number.child_1_extra_screen_time:
  43. icon: "mdi:gift"
  44. input_number.child_2_extra_screen_time:
  45. icon: "mdi:gift"
  46.  
  47. sensor:
  48. - platform: history_stats
  49. name: Child 1 screen time this week
  50. entity_id: input_boolean.child_1_screen_time_active
  51. state: "on"
  52. type: time
  53. start: "{{ as_timestamp(now().replace(hour=0, minute=0, second=0)) - now().weekday() * 86400 }}"
  54. end: "{{ now() }}"
  55.  
  56. - platform: history_stats
  57. name: Child 1 screen time today
  58. entity_id: input_boolean.child_1_screen_time_active
  59. state: "on"
  60. type: time
  61. start: "{{ now().replace(hour=0, minute=0, second=0) }}"
  62. end: "{{ now() }}"
  63.  
  64. - platform: history_stats
  65. name: Child 2 screen time this week
  66. entity_id: input_boolean.child_2_screen_time_active
  67. state: "on"
  68. type: time
  69. start: "{{ as_timestamp(now().replace(hour=0, minute=0, second=0)) - now().weekday() * 86400 }}"
  70. end: "{{ now() }}"
  71.  
  72. - platform: history_stats
  73. name: Child 2 screen time today
  74. entity_id: input_boolean.child_2_screen_time_active
  75. state: "on"
  76. type: time
  77. start: "{{ now().replace(hour=0, minute=0, second=0) }}"
  78. end: "{{ now() }}"
  79.  
  80. template:
  81. - sensor:
  82. - unique_id: weekly_screen_time
  83. name: "Weekly screen time"
  84. state: "{{ 720 if is_state('binary_sensor.school_holiday', 'on') else 360 }}"
  85.  
  86. - unique_id: child_1_weekly_screen_time_threshold
  87. name: "Child 1 weekly screen time threshold"
  88. state: "{{ states('sensor.weekly_screen_time') | int(0) + states('input_number.child_1_extra_screen_time') | int(0) }}"
  89. availability: "{{ states('sensor.weekly_screen_time') | is_number() and states('input_number.child_1_extra_screen_time') | is_number() }}"
  90. unit_of_measurement: "min"
  91. - unique_id: child_1_corrected_screen_time_this_week
  92. name: "Child 1 corrected screen time this week"
  93. state: "{{ states('sensor.child_1_screen_time_this_week') | float(0) * 60 - states('input_number.child_1_correction_screen_time') | int(0) }}"
  94. availability: "{{ states('sensor.child_1_screen_time_this_week') | is_number() and states('input_number.child_1_correction_screen_time') | is_number() }}"
  95. unit_of_measurement: "min"
  96. - unique_id: child_1_weekly_screen_time_remaining
  97. name: "Child 1 weekly screen time remaining"
  98. state: "{{ states('sensor.child_1_weekly_screen_time_threshold') | int(0) - states('sensor.child_1_screen_time_this_week') | int(0) }}"
  99. availability: "{{ states('sensor.child_1_weekly_screen_time_threshold') | is_number() and states('sensor.child_1_screen_time_this_week') | is_number() }}"
  100. unit_of_measurement: "min"
  101.  
  102. - unique_id: child_2_weekly_screen_time_threshold
  103. name: "Child 2 weekly screen time threshold"
  104. state: "{{ states('sensor.weekly_screen_time') | int(0) + states('input_number.child_2_extra_screen_time') | int(0) }}"
  105. availability: "{{ states('sensor.weekly_screen_time') | is_number() and states('input_number.child_2_extra_screen_time') | is_number() }}"
  106. unit_of_measurement: "min"
  107. - unique_id: child_2_corrected_screen_time_this_week
  108. name: "Child 2 corrected screen time this week"
  109. state: "{{ states('sensor.child_2_screen_time_this_week') | float(0) * 60 - states('input_number.child_2_correction_screen_time') | int(0) }}"
  110. availability: "{{ states('sensor.child_2_screen_time_this_week') | is_number() and states('input_number.child_2_correction_screen_time') | is_number() }}"
  111. unit_of_measurement: "min"
  112. - unique_id: child_2_weekly_screen_time_remaining
  113. name: "Child 2 weekly screen time remaining"
  114. state: "{{ states('sensor.child_2_weekly_screen_time_threshold') | int(0) - states('sensor.child_2_screen_time_this_week') | int(0) }}"
  115. availability: "{{ states('sensor.child_2_weekly_screen_time_threshold') | is_number() and states('sensor.child_2_screen_time_this_week') | is_number() }}"
  116. unit_of_measurement: "min"
  117.  
  118. automation:
  119. - id: reset_extra_screen_time
  120. alias: "Reset extra screen time"
  121. mode: single
  122. max_exceeded: silent
  123. trigger:
  124. - platform: time
  125. at: "00:00:00"
  126. condition:
  127. condition: time
  128. weekday:
  129. - mon
  130. action:
  131. - service: input_number.set_value
  132. target:
  133. entity_id: input_number.child_1_extra_screen_time
  134. data:
  135. value: >-
  136. {% if states('input_number.child_1_extra_screen_time') | int(0) >= 0 %}
  137. {{ min(states('input_number.child_1_extra_screen_time') | int(0), states('sensor.child_1_weekly_screen_time_remaining') | int(0)) }}
  138. {% else %}
  139. {{ min(0, 0 + states('input_number.child_1_extra_screen_time') | int(0) + states('sensor.weekly_screen_time') | int(0)) }}
  140. {% endif %}
  141. - service: input_number.set_value
  142. target:
  143. entity_id: input_number.child_2_extra_screen_time
  144. data:
  145. value: >-
  146. {% if states('input_number.child_2_extra_screen_time') | int(0) >= 0 %}
  147. {{ min(states('input_number.child_2_extra_screen_time') | int(0), states('sensor.child_2_weekly_screen_time_remaining') | int(0)) }}
  148. {% else %}
  149. {{ min(0, 0 + states('input_number.child_2_extra_screen_time') | int(0) + states('sensor.weekly_screen_time') | int(0)) }}
  150. {% endif %}
  151.  
Advertisement
Add Comment
Please, Sign In to add comment