I have a script that gradually changes the light over a period of time.
I have it set up that when I manually change the lights, it sends an actionable notification after 10 minutes to ask if I want to continue the light change from the current settings.
If I select “Yes”, it will continue immediately, if not, it should keep the lights at the current settings and then ask again in 10 minutes.
Also, if I select “Yes” then change the lights again after a while, it should ask again after 10 minutes.
Now I need help configuring this in my script. Is there an easier way where I don’t have to repeat the same actions (send notification → if “Yes” → continue, etc.)?
This is my script:
mode: single
variables:
start_time: "08:00:00"
end_time: "8:20:00"
steps_per_minute: 5
start_kelvin: 2200
end_kelvin: 4500
start_bright: 20
end_bright: 85
manual_override: input_boolean.manual_override
duration: >
{% set start = strptime(start_time, '%H:%M:%S') %} {% set end =
strptime(end_time, '%H:%M:%S') %} {% if start > end %}
{% set end = end + timedelta(days=1) %}
{% endif %} {{ (end - start).total_seconds() / 60 }}
intervals: "{{ duration * steps_per_minute | int }}"
step_kelvin: "{{ ((end_kelvin - start_kelvin) / intervals) }}"
step_bright: "{{ ((end_bright - start_bright) / intervals) }}"
sequence:
- condition: zone
entity_id: person.elise
zone: zone.home
- variables:
step_kelvin: |
{% if start_kelvin < end_kelvin %}
{{ (end_kelvin - start_kelvin) / intervals }}
{% else %}
{{ (start_kelvin - end_kelvin) / intervals * -1 }}
{% endif %}
step_bright: |
{% if start_bright < end_bright %}
{{ (end_bright - start_bright) / intervals }}
{% else %}
{{ (start_bright - end_bright) / intervals * -1 }}
{% endif %}
- target:
entity_id:
- light.keuken
- light.woonkamer
data:
brightness_pct: "{{ start_bright }}"
color_temp_kelvin: "{{ start_kelvin }}"
action: light.turn_on
- delay:
seconds: 2
- repeat:
until:
- condition: or
conditions:
- condition: state
entity_id: input_boolean.manual_override
state: "on"
- condition: template
value_template: "{{ repeat.index == intervals | int }}"
sequence:
- target:
entity_id:
- light.keuken
- light.woonkamer
data:
brightness_pct: "{{ (start_bright + (step_bright * repeat.index)) | int }}"
color_temp_kelvin: "{{ (start_kelvin + (step_kelvin * repeat.index)) | int }}"
action: light.turn_on
- delay:
seconds: 2
- choose:
- conditions:
- condition: state
entity_id: input_boolean.manual_override
state: "on"
sequence:
- delay:
hours: 0
minutes: 0
seconds: 10
- action: notify.mobile_app_pixel_8
metadata: {}
data:
title: Continue lights?
data:
actions:
- action: CONTINUE_LIGHTS
title: "Yes"
- action: NO_ACTION
title: "No"
message: Continue?
- wait_for_trigger:
- trigger: event
event_type: mobile_app_notification_action
event_data:
action: CONTINUE_LIGHTS
- if:
- condition: template
value_template: >-
{{ wait.trigger and wait.trigger.event.data.action ==
'CONTINUE_LIGHTS' }}
then:
- variables:
current_kelvin: "{{ state_attr('light.keuken', 'color_temp_kelvin') }}"
current_bright: >-
{{ state_attr('light.keuken', 'brightness') * 100 /
255 }}
duration_until: >
{% set now_time = now().replace(tzinfo=None) %} {% set
end = strptime(end_time,
'%H:%M:%S').replace(year=now_time.year,
month=now_time.month, day=now_time.day) %} {% if
now_time > end %} {% set end = end + timedelta(days=1)
%} {% endif %} {{ ((end - now_time).total_seconds() /
60) | int }}
new_intervals: "{{ duration_until * steps_per_minute }}"
new_step_kelvin: |
{% if current_kelvin < end_kelvin %}
{{ (end_kelvin - current_kelvin) / new_intervals }}
{% else %}
{{ (current_kelvin - end_kelvin) / new_intervals * -1 }}
{% endif %}
new_step_bright: |
{% if current_bright < end_bright %}
{{ (end_bright - current_bright) / new_intervals }}
{% else %}
{{ (current_bright - end_bright) / new_intervals * -1 }}
{% endif %}
- repeat:
sequence:
- action: light.turn_on
metadata: {}
data:
brightness_pct: >-
{{ (current_bright + (new_step_bright *
repeat.index)) }}
color_temp_kelvin: >-
{{ (current_kelvin + (new_step_kelvin *
repeat.index)) }}
target:
entity_id: light.keuken
until:
- condition: or
conditions:
- condition: state
entity_id: input_boolean.manual_override
state: "on"
- condition: template
value_template: "\"{{ repeat.index == intervals }}\""
else:
- delay:
hours: 0
minutes: 0
seconds: 10
- action: notify.mobile_app_pixel_8
metadata: {}
data:
title: Continue lights?
data:
actions:
- action: CONTINUE_LIGHTS
title: "Yes"
- action: NO_ACTION
title: "No"
message: Continue?
alias: 08:00 (Duplicate)
description: ""