Forked from sbyx/wake-up-light-alarm-with-sunrise-effect.yaml
Last active
October 27, 2023 06:30
-
-
Save tom-erik-l/3191262c06936377fb136ae4c367297c to your computer and use it in GitHub Desktop.
Home Assistant Blueprint: Wake-up light alarm with sunrise effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: Wake-up light alarm with sunrise effect | |
description: 'A wake-up light alarm with a brightness and color temperature sunrise | |
effect. Note: Requires date_time_iso sensor in configuration, not manually executable!' | |
domain: automation | |
input: | |
light_entity: | |
name: Wake-up light entity | |
description: The light to control. Turning it off during the sunrise will keep | |
it off. Color temperature range is auto-detected. | |
selector: | |
entity: | |
domain: light | |
timestamp_sensor: | |
name: Alarm timestamp sensor | |
description: 'Sensor with timestamp of next alarm with device_class: timestamp | |
(set to ''none'' for manual alarm time)' | |
default: none | |
selector: | |
entity: | |
device_class: timestamp | |
manual_time: | |
name: Manual alarm time | |
description: Time to trigger alarm every day if timestamp sensor is not set. | |
Settings at or shortly after midnight will not work as expected! | |
default: '7:00:00' | |
selector: | |
time: {} | |
sunrise_duration: | |
name: Sunrise duration | |
description: The sunrise will start the configured number of minutes before | |
the timestamp. | |
default: 25 | |
selector: | |
number: | |
min: 5.0 | |
max: 60.0 | |
step: 5.0 | |
unit_of_measurement: min | |
mode: slider | |
end_brightness: | |
name: Maximum brightness | |
description: The brightness will be transitioned from 1 to the configured value. | |
default: 255 | |
selector: | |
number: | |
min: 5.0 | |
max: 255.0 | |
step: 5.0 | |
mode: slider | |
pre_sunrise_actions: | |
name: Pre-sunrise actions | |
description: Optional actions to run before sunrise starts. Wait-Actions may | |
be used to define additional alarm conditions. | |
default: [] | |
selector: | |
action: {} | |
post_sunrise_actions: | |
name: Post-sunrise actions | |
description: Optional actions to run after sunrise end. Wait-Actions may be | |
used to define additional alarm conditions. | |
default: [] | |
selector: | |
action: {} | |
source_url: https://gist.github.com/sbyx/96c43b13b90ae1c35b872313ba1d2d2d | |
variables: | |
light_entity: !input 'light_entity' | |
sensor: !input 'timestamp_sensor' | |
sunrise_duration: !input 'sunrise_duration' | |
end_brightness: !input 'end_brightness' | |
manual_time: !input 'manual_time' | |
seconds: '{{ float(sunrise_duration) * 60 }}' | |
start_mired: "{{ state_attr(light_entity, 'max_mireds') }}" | |
end_mired: "{{ state_attr(light_entity, 'min_mireds') }}" | |
tick_time: '{{ (float(seconds) / 255) * (255 / float(end_brightness)) }}' | |
trigger: | |
- platform: time_pattern | |
minutes: '*' | |
condition: [] | |
action: | |
# - service: system_log.write | |
# data_template: | |
# level: error | |
# logger: my_error | |
# message: "1" | |
# Ensure valid sensor configuration (timestamp_sensor either valid and parsable or == 'none') | |
- wait_template: "{{ sensor == 'none' or as_timestamp(states(sensor)) != None }}" | |
# - service: system_log.write | |
# data_template: | |
# level: error | |
# logger: my_error | |
# message: "2" | |
# 0 < Alarm time - Now < Sunrise transition | |
- wait_template: "{{ 0 < as_timestamp(states(sensor) if sensor != 'none' | |
else states('sensor.date') ~ ' ' ~ manual_time) | |
- as_timestamp(states('sensor.date_time_iso')) < float(seconds) }}" | |
# - service: system_log.write | |
# data_template: | |
# level: error | |
# logger: my_error | |
# message: "3" | |
# Execute pre-sunrise actions | |
- choose: [] | |
default: !input 'pre_sunrise_actions' | |
# - service: system_log.write | |
# data_template: | |
# level: error | |
# logger: my_error | |
# message: "4" | |
- condition: template | |
value_template: "{{ sensor == 'none' or as_timestamp(states(sensor)) != None }}" | |
# - service: system_log.write | |
# data_template: | |
# level: error | |
# logger: my_error | |
# message: "5" | |
# 0 < Alarm time - Now < Sunrise transition | |
- condition: template | |
value_template: "{{ 0 < as_timestamp(states(sensor) if sensor != 'none' | |
else states('sensor.date') ~ ' ' ~ manual_time) | |
- as_timestamp(states('sensor.date_time_iso')) < float(seconds) }}" | |
# - service: system_log.write | |
# data_template: | |
# level: error | |
# logger: my_error | |
# message: "6" | |
- choose: | |
- conditions: | |
- condition: template | |
value_template: "{{ state_attr(light_entity, 'min_mireds') != None }}" | |
sequence: | |
- service: light.turn_on | |
data: | |
brightness: 1 | |
color_temp: '{{start_mired}}' | |
entity_id: !input 'light_entity' | |
default: | |
- service: light.turn_on | |
data: | |
brightness: 1 | |
entity_id: !input 'light_entity' | |
- repeat: | |
while: | |
- condition: template | |
value_template: "{{ sensor == 'none' or as_timestamp(states(sensor)) != None }}" | |
- condition: template | |
value_template: "{{ 0 < as_timestamp(states(sensor) if sensor != 'none' | |
else states('sensor.date') ~ ' ' ~ manual_time) - as_timestamp(now()) < float(seconds) }}" | |
sequence: | |
- delay: '{{tick_time}}' | |
- choose: | |
- conditions: | |
- condition: state | |
entity_id: !input 'light_entity' | |
state: 'on' | |
- condition: template | |
value_template: "{{ sensor == 'none' or as_timestamp(states(sensor)) != None }}" | |
- condition: template | |
value_template: "{{ 0 < as_timestamp(states(sensor) if sensor != 'none' | |
else states('sensor.date') ~ ' ' ~ manual_time) - as_timestamp(now()) < float(seconds) }}" | |
sequence: | |
- choose: | |
- conditions: | |
- condition: template | |
value_template: "{{ state_attr(light_entity, 'min_mireds') != None }}" | |
sequence: | |
- service: light.turn_on | |
data: | |
brightness: "{{ (float(end_brightness) - (float(end_brightness) | |
* (as_timestamp(states(sensor) if sensor != 'none' | |
else states('sensor.date') ~ ' ' ~ manual_time) | |
- as_timestamp(now())) / float(seconds))) | int }}" | |
color_temp: "{{ (float(end_mired) + (float(start_mired) - float(end_mired)) | |
* ((as_timestamp(states(sensor) if sensor != 'none' | |
else states('sensor.date') ~ ' ' ~ manual_time) | |
- as_timestamp(now())) / float(seconds))) | int }}" | |
entity_id: !input 'light_entity' | |
default: | |
- service: light.turn_on | |
data: | |
brightness: "{{ (float(end_brightness) - (float(end_brightness) | |
* (as_timestamp(states(sensor) if sensor != 'none' | |
else states('sensor.date') ~ ' ' ~ manual_time) | |
- as_timestamp(now())) / float(seconds))) | int }}" | |
entity_id: !input 'light_entity' | |
- choose: [] | |
default: !input 'post_sunrise_actions' | |
mode: single | |
max_exceeded: silent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment