-
Notifications
You must be signed in to change notification settings - Fork 0
/
wake_and_sleep_light.yaml
119 lines (114 loc) · 3.63 KB
/
wake_and_sleep_light.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
blueprint:
name: Wake and sleep light
description: |
If a light is turned on in a very dim state, do one of two actions:
a) raise its brightness in steps up to maximum brightness in a given time frame, or
b) set it to its minimum brightness.
Turning the light to its maximum brightness or off will stop the actions.
source_url: https://gist.github.com/akloeckner/6f5d3299b5661ef1830171db1957b1a0
domain: automation
input:
light_entity:
name: Light entity
description: The light to control
selector:
entity:
domain: light
wake_time_start:
name: Start of the wake-up time frame
description: The beginning of the time frame, where the automation should behave as a wake-up light
default: '07:00:00'
selector:
time: {}
wake_time_end:
name: End of the wake-up time frame
description: The end of the time frame, where the automation should behave as a wake-up light
default: '10:00:00'
selector:
time: {}
trigger_brightness:
name: Trigger brightness
description: The brightness below which this automation will trigger
default: 50
selector:
number:
min: 1.0
max: 255.0
step: 1.0
mode: slider
sleep_brightness:
name: Sleep brightness
description: The brightness so set when used as a sleep light
default: 25
selector:
number:
min: 1.0
max: 255.0
step: 1.0
mode: slider
max_brightness:
name: Maximum brightness
description: The ultimate brightness to turn the wake-up light to
default: 255
selector:
number:
min: 1.0
max: 255.0
step: 1.0
mode: slider
wake_duration:
name: Wake-up duration
description: The timespan in which to reach full brightness in minutes
default: 5
selector:
number:
min: 1.0
max: 30.0
step: 1.0
mode: slider
mode: single
max_exceeded: silent
variables:
light_entity: !input 'light_entity'
trigger_brightness: !input 'trigger_brightness'
max_brightness: !input 'max_brightness'
wake_duration: !input 'wake_duration'
step: 5
trigger:
- platform: state
entity_id: !input 'light_entity'
from: 'off'
to: 'on'
for: 5
condition:
- condition: template
value_template: "{{ is_state(light_entity, 'on') and state_attr(light_entity, 'brightness') < float(trigger_brightness) }}"
action:
- alias: "Set up runtime variables"
variables:
start_brightness: "{{ state_attr(light_entity, 'brightness') }}"
start_time: "{{ as_timestamp(now()) }}"
wake_gradient: "{{ (max_brightness-start_brightness) / float(wake_duration) / 60 }}"
wake_tick: "{{ float(step) / wake_gradient }}"
- alias: "Turn up brightness in the morning, else set minimum brightness"
choose:
conditions:
- condition: time
after: !input 'wake_time_start'
before: !input 'wake_time_end'
sequence:
- repeat:
while:
- "{{ is_state(light_entity, 'on') and state_attr(light_entity, 'brightness') < float(max_brightness) }}"
sequence:
- service: light.turn_on
entity_id: !input 'light_entity'
data_template:
#brightness: "{{ (state_attr(light_entity, 'brightness')+float(step)) | min(float(max_brightness)) }}"
brightness: "{{ start_brightness + (as_timestamp(now())-start_time) * wake_gradient }}"
- delay: "{{ wake_tick }}"
default:
- service: light.turn_on
entity_id: !input 'light_entity'
data:
brightness: !input 'sleep_brightness'