Skip to content

Instantly share code, notes, and snippets.

@simonwh
Last active August 25, 2022 17:59
Show Gist options
  • Save simonwh/03ad1ef6caa5c3457432b794c4f63bcf to your computer and use it in GitHub Desktop.
Save simonwh/03ad1ef6caa5c3457432b794c4f63bcf to your computer and use it in GitHub Desktop.
blueprint:
name: Wake-up light and music alarm with sunrise effect and increasing volume (RGB version)
description: 'A wake-up light and music alarm with a brightness and color temperature sunrise effect and increasing volume.
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
speaker_entity:
name: Wake-up speaker entity
description: The speaker to control. Turning it off during the wake-up will keep
it off.
selector:
entity:
domain: media_player
media:
name: Media to play on wakeup
description: Media to play
default: []
selector:
media: {}
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: {}
check_entity:
name: Additional entity to check before wake-up is triggered
description: If set, checks if entity is 'on' or 'home' before triggering. Use
e.g. a (workday) sensor, device_tracker or person entity.
default: none
selector:
entity: {}
wakeup_duration:
name: Wake-up duration
description: The wake-up 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
start_brightness:
name: Minimum brightness in percentage
description: The brightness to start with. Some lights ignore very low values
and may turn on with full brightness instead!
default: 1
selector:
number:
min: 1.0
max: 100.0
step: 1.0
mode: slider
end_brightness:
name: Maximum brightness in percentage
description: The brightness will be transitioned from the minimum to the configured
value.
default: 100
selector:
number:
min: 5.0
max: 100.0
step: 1.0
mode: slider
hue:
name: Color to use
description: The color for RGB light
value.
default: 60
selector:
number:
min: 0
max: 360
step: 1.0
mode: slider
sat:
name: Color Saturation
description: The saturation will be transitioned from the maximum to the configured
value.
default: 100
selector:
number:
min: 0
max: 100
step: 1.0
mode: slider
start_volume:
name: Minimum volume
description: The volume to start with
default: 1
selector:
number:
min: 1.0
max: 100.0
step: 1.0
mode: slider
end_volume:
name: Maximum volume
description: The volume will be transitioned from the minimum to the configured
value.
default: 20
selector:
number:
min: 5.0
max: 100.0
step: 1.0
mode: slider
pre_wakeup_actions:
name: Pre-wakeup actions
description: Optional actions to run before wake-up starts.
default: []
selector:
action: {}
post_wakeup_actions:
name: Post-wakeup actions
description: Optional actions to run after wake-up ends (around the alarm time).
default: []
selector:
action: {}
variables:
light_entity: !input 'light_entity'
speaker_entity: !input 'speaker_entity'
sensor: !input 'timestamp_sensor'
wakeup_duration: !input 'wakeup_duration'
start_brightness: !input 'start_brightness'
end_brightness: !input 'end_brightness'
range_brightness: '{{float(end_brightness) - float(start_brightness)}}'
hue: !input 'hue'
sat: !input 'sat'
start_volume: !input 'start_volume'
end_volume: !input 'end_volume'
range_volume: '{{float(end_volume) - float(start_volume)}}'
manual_time: !input 'manual_time'
seconds: '{{float(wakeup_duration) * 60}}'
tick_time: '{{float(seconds) / float(range_brightness)}}'
check_entity: !input 'check_entity'
trigger:
- platform: time_pattern
minutes: '*'
action:
- wait_template: '{{sensor == ''none'' or as_timestamp(states(sensor)) != None}}'
- wait_template: '{{0 < as_timestamp(states(sensor) if sensor != ''none'' else (states(''sensor.date'') ~ '' '' ~ manual_time) | as_datetime() | as_local())
- as_timestamp(now()) <= float(seconds) and states(check_entity) in [''unknown'', ''on'', ''home'']}}'
- choose: []
default: !input 'pre_wakeup_actions'
- 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_datetime() | as_local())
- as_timestamp(now()) <= float(seconds) and states(check_entity) in [''unknown'', ''on'', ''home'']}}'
- choose:
- conditions:
- '{{state_attr(light_entity, ''brightness'') != None}}'
sequence:
- service: light.turn_on
data:
brightness: '{{start_brightness}}'
hs_color:
- '{{ hue | int}}'
- '{{ 100 | int}}'
entity_id: !input 'light_entity'
default:
- service: light.turn_on
data:
brightness: '{{start_brightness}}'
entity_id: !input 'light_entity'
- service: media_player.volume_set
data:
volume_level: '{{float(start_volume / 100)}}'
entity_id: !input 'speaker_entity'
- service: media_player.play_media
target:
entity_id: !input 'speaker_entity'
data:
!input 'media'
- repeat:
while:
- '{{sensor == ''none'' or as_timestamp(states(sensor)) != None}}'
- '{{0 < as_timestamp(states(sensor) if sensor != ''none'' else (states(''sensor.date'') ~ '' '' ~ manual_time) | as_datetime() | as_local())
- as_timestamp(now()) <= float(seconds)}}'
sequence:
- delay: '{{tick_time}}'
- choose:
- conditions:
- '{{0 < state_attr(light_entity, ''brightness'') | int(0) < float(end_brightness) / 100 * 255 | int(0)}}'
sequence:
- choose:
- conditions:
- '{{state_attr(light_entity, ''brightness'') != None}}'
sequence:
- service: light.turn_on
data:
brightness: '{{float(end_brightness) - ([0, float(range_brightness) * (as_timestamp(states(sensor) if sensor != ''none'' else (states(''sensor.date'') ~ '' '' ~ manual_time) | as_datetime() | as_local())
- as_timestamp(now())) / seconds, float(end_brightness)]|sort)[1] | round(0)}}'
hs_color:
- '{{hue | int}}'
- '{{((float(100) - (float(100) - sat)) + ((float(100) - sat) *
(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) - ([0, float(range_brightness) * (as_timestamp(states(sensor) if sensor != ''none'' else (states(''sensor.date'') ~ '' '' ~ manual_time) | as_datetime() | as_local())
- as_timestamp(now())) / seconds, float(end_brightness)]|sort)[1] | round(0)}}'
entity_id: !input 'light_entity'
- choose:
- conditions:
- '{{0 < state_attr(speaker_entity, ''volume_level'') * 100 | round(0) < float(end_volume) - ([0, float(range_volume) * (as_timestamp(states(sensor) if sensor != ''none'' else (states(''sensor.date'') ~ '' '' ~ manual_time) | as_datetime() | as_local())
- as_timestamp(now())) / seconds, float(end_volume)]|sort)[1] | round(0) <= float(end_volume)}}'
sequence:
- service: media_player.volume_set
data:
volume_level: '{{(float(end_volume) - ([0, float(range_volume) * (as_timestamp(states(sensor) if sensor != ''none'' else (states(''sensor.date'') ~ '' '' ~ manual_time) | as_datetime() | as_local())
- as_timestamp(now())) / seconds, float(end_volume)]|sort)[1]) / 100 | round(2)}}'
entity_id: !input 'speaker_entity'
- choose: []
default: !input 'post_wakeup_actions'
mode: single
max_exceeded: silent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment