-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsunAlarm.yaml
145 lines (140 loc) · 4.75 KB
/
sunAlarm.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
blueprint:
name: "Wake-up light alarm with realistic sunrise effect. Version: 1.5.12"
description: >
A wake-up light alarm with a realistic brightness and color temperature sunrise effect.
domain: automation
homeassistant:
min_version: "2023.1.0"
input:
light_entity:
name: Wake-up light entity
description: The light to control. Color temperature range is auto-detected.
selector:
entity:
domain: light
sunrise_duration:
name: Sunrise duration
description: The sunrise will start this many minutes before the timestamp.
default: 30
selector:
number:
min: 10
max: 60
step: 5
unit_of_measurement: min
mode: slider
end_brightness:
name: Ending brightness
description: The final brightness level of the light at the end of the sunrise effect.
default: 100
selector:
number:
min: 10
max: 100
step: 1
mode: slider
unit_of_measurement: "%"
keep_on_duration:
name: Keep light on duration
description: How long to keep the light on after the sunrise effect is complete.
default: 60
selector:
number:
min: 5
max: 120
step: 5
unit_of_measurement: min
mode: slider
variables:
light_entity: !input light_entity
sunrise_duration: !input sunrise_duration
start_brightness: 1
end_brightness: !input end_brightness
update_interval: 10 # Update every 10 seconds
total_updates: "{{ ((sunrise_duration | int) * 60 / update_interval) | int }}"
color_steps: [
[139, 0, 0], # Deep dark red
[205, 16, 0], # Dark red
[255, 69, 0], # Red-orange
[255, 130, 0], # Deep orange
[255, 180, 50], # Golden yellow
[255, 223, 150], # Very warm white/golden
]
keep_on_duration: !input keep_on_duration
trigger:
- trigger: event
event_type: sunrise_alarm_start
action:
# Set initial state
- action: light.turn_on
target:
entity_id: !input light_entity
data:
brightness: "{{ start_brightness * 2.55 | round(0) }}"
rgb_color: "{{ color_steps[0] }}"
transition: "{{ update_interval }}"
- delay:
seconds: "{{ update_interval }}"
- repeat:
count: "{{ total_updates }}"
sequence:
- condition: state
entity_id: !input light_entity
state: "on"
- variables:
progress: "{{ repeat.index / total_updates }}"
current_brightness: >
{{ ((progress ** 2) * (end_brightness - start_brightness) + start_brightness) * 2.55 | round(0) }}
color_progress: "{{ progress * (color_steps | length - 1) }}"
color_index: "{{ color_progress | int }}"
- action: light.turn_on
target:
entity_id: !input light_entity
data:
brightness: "{{ current_brightness }}"
rgb_color: >
{% set start = color_steps[color_index] %}
{% set end = color_steps[color_index + 1] %}
{% set fraction = color_progress - color_index %}
{{ [
(start[0] + (end[0] - start[0]) * fraction) | round,
(start[1] + (end[1] - start[1]) * fraction) | round,
(start[2] + (end[2] - start[2]) * fraction) | round
] }}
transition: "{{ update_interval }}"
- delay:
seconds: "{{ update_interval }}"
- if:
- condition: or
conditions:
- condition: state
entity_id: !input light_entity
state: "off"
- condition: template
value_template: "{{ repeat.index == total_updates - 1 }}"
then:
- choose:
- conditions:
- condition: state
entity_id: !input light_entity
state: "off"
sequence:
- stop: "Light turned off, aborting sunrise"
- conditions:
- condition: template
value_template: "{{ repeat.index == total_updates - 1 }}"
sequence:
- if:
condition: template
value_template: "{{ keep_on_duration > 0 }}"
then:
- delay:
minutes: "{{ keep_on_duration }}"
- action: light.turn_off
target:
entity_id: !input light_entity
data:
transition: 30
- stop: "Sunrise complete"
mode: single
max_exceeded: silent