/
light.yaml
executable file
·379 lines (350 loc) · 10.7 KB
/
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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
---
#-
# _ _ _ _
# | (_) __ _| |__ | |_
# | | |/ _` | '_ \| __|
# | | | (_| | | | | |_
# |_|_|\__, |_| |_|\__|
# |___/
#
#- from github.com/basnijholt/home-assistant-config
# __ __ _ _ _ _ _
# | \/ | __ _ _ __ _ _ __ _| | | (_) __ _| |__ | |_ ___
# | |\/| |/ _` | '_ \| | | |/ _` | | | | |/ _` | '_ \| __/ __|
# | | | | (_| | | | | |_| | (_| | | | | | (_| | | | | |_\__ \
# |_| |_|\__,_|_| |_|\__,_|\__,_|_| |_|_|\__, |_| |_|\__|___/
# |___/
# Moved to control_switches.yaml!
# _ _ _ _ _ _ _ _
# / \ _ _| |_ ___ _ __ ___ __ _| |_(_) ___ | (_) __ _| |__ | |_ ___
# / _ \| | | | __/ _ \| '_ ` _ \ / _` | __| |/ __| | | |/ _` | '_ \| __/ __|
# / ___ \ |_| | || (_) | | | | | | (_| | |_| | (__ | | | (_| | | | | |_\__ \
# /_/ \_\__,_|\__\___/|_| |_| |_|\__,_|\__|_|\___| |_|_|\__, |_| |_|\__|___/
# |___/
# _ _ _
# | | (_)_ _(_)_ __ __ _ _ __ ___ ___ _ __ ___
# | | | \ \ / / | '_ \ / _` | | '__/ _ \ / _ \| '_ ` _ \
# | |___| |\ V /| | | | | (_| | | | | (_) | (_) | | | | | |
# |_____|_| \_/ |_|_| |_|\__, | |_| \___/ \___/|_| |_| |_|
# |___/
- alias: "Light: turn on living room"
trigger:
platform: state
entity_id: binary_sensor.activity_in_living_room
to: "on"
action:
service: light.turn_on
entity_id: light.living_room_lights
- alias: "Light: turn off living room"
trigger:
platform: state
entity_id: binary_sensor.activity_in_living_room
to: "off"
action:
service: light.turn_off
entity_id: light.living_room_lights
# _ ___ _ _
# | |/ (_) |_ ___| |__ ___ _ __
# | ' /| | __/ __| '_ \ / _ \ '_ \
# | . \| | || (__| | | | __/ | | |
# |_|\_\_|\__\___|_| |_|\___|_| |_|
- alias: "Light: toggle kitchen ceiling"
trigger:
platform: state
entity_id: binary_sensor.activity_in_kitchen
action:
service: light.turn_{{ trigger.to_state.state }}
data:
entity_id: light.ceiling_kitchen
transition: 1
- alias: "Light: turn on kitchen counter if sleep mode is off"
trigger:
platform: state
entity_id: binary_sensor.activity_in_kitchen
to: "on"
condition:
condition: state
entity_id: input_select.sleep_mode
state:
- "off"
- "half"
action:
service: light.turn_on
entity_id: light.kitchen_counter
- alias: "Light: turn off kitchen counter"
trigger:
platform: state
entity_id: binary_sensor.activity_in_kitchen
to: "off"
action:
service: light.turn_off
entity_id: light.kitchen_counter
# ____ _ _
# | __ ) __ _| |_| |__ _ __ ___ ___ _ __ ___
# | _ \ / _` | __| '_ \| '__/ _ \ / _ \| '_ ` _ \
# | |_) | (_| | |_| | | | | | (_) | (_) | | | | | |
# |____/ \__,_|\__|_| |_|_| \___/ \___/|_| |_| |_|
#
- alias: "Light: toggle bathroom"
trigger:
platform: state
entity_id: binary_sensor.activity_in_bathroom
condition: "{{ not is_state('light.ceiling_bathroom', trigger.to_state.state) }}"
action:
service: light.turn_{{ trigger.to_state.state }}
data:
entity_id: light.ceiling_bathroom
transition: 1
# _____ _ _ _
# |_ _|__ (_) | ___| |_
# | |/ _ \| | |/ _ \ __|
# | | (_) | | | __/ |_
# |_|\___/|_|_|\___|\__|
- alias: "Light: toggle toilet"
trigger:
platform: state
entity_id: binary_sensor.activity_in_toilet
action:
service: light.turn_{{ trigger.to_state.state }}
data:
entity_id: light.toilet
transition: 1
# _ _ _ _ _ _ _
# | | | | __ _| | | __ _ _ __ __| | ___| |_ __ _(_)_ __ ___
# | |_| |/ _` | | | / _` | '_ \ / _` | / __| __/ _` | | '__/ __|
# | _ | (_| | | | | (_| | | | | (_| | \__ \ || (_| | | | \__ \
# |_| |_|\__,_|_|_| \__,_|_| |_|\__,_| |___/\__\__,_|_|_| |___/
- alias: "Light: turn on hall"
mode: parallel
trigger:
- platform: state
entity_id: binary_sensor.activity_in_hall
from: "off"
to: "on"
- platform: state
entity_id: binary_sensor.openclose_front_door
from: "off"
to: "on"
variables:
off_lights: >
{% set hall_lights = ["light.hall_2"]
if is_state('input_select.sleep_mode', 'total')
else ["light.hall_1", "light.hall_2", "light.hall_3"] %}
{{ expand(state_attr("light.stairs_lights", "entity_id") + hall_lights)
| selectattr("state", "eq", "off")
| map(attribute="entity_id")
| list }}
condition: "{{ (off_lights | length) > 0 }}"
action:
alias: Turn on lights that are off
repeat:
count: "{{ off_lights | length }}"
sequence:
service: script.turn_on_lights
data:
entity_id: "{{ off_lights[repeat.index - 1] }}"
- alias: "Light: turn off hall"
trigger:
platform: state
entity_id: binary_sensor.activity_in_hall
from: "on"
to: "off"
action:
service: light.turn_off
data:
entity_id:
- light.stairs_lights
- light.hall_lights
transition: 1
# ____ _
# | __ ) ___ __| |_ __ ___ ___ _ __ ___
# | _ \ / _ \/ _` | '__/ _ \ / _ \| '_ ` _ \
# | |_) | __/ (_| | | | (_) | (_) | | | | | |
# |____/ \___|\__,_|_| \___/ \___/|_| |_| |_|
- alias: "Light: automatically turn on the bedroom"
trigger:
platform: state
entity_id: binary_sensor.activity_in_bedroom
to: "on"
variables:
off_lights: >
{{ expand(state_attr("light.bedroom_lights", "entity_id"))
| selectattr("state", "eq", "off")
| map(attribute="entity_id")
| list }}
condition:
- "{{ (off_lights | length) > 0 }}"
- condition: state
entity_id: input_select.sleep_mode
state: "off"
- condition: state
entity_id: input_boolean.automatic_bedroom_lights
state: "on"
action:
- alias: Turn on lights that are off
repeat:
count: "{{ off_lights | length }}"
sequence:
service: script.turn_on_lights
data:
entity_id: "{{ off_lights[repeat.index - 1] }}"
- service: input_boolean.turn_on
entity_id: input_boolean.bedroom_lights_automatically_turned_on
- alias: "Light: automatically turn off the bedroom"
initial_state: "on"
trigger:
platform: state
entity_id: binary_sensor.activity_in_bedroom
to: "off"
for: "00:08:00"
condition:
- condition: state
entity_id: input_boolean.bedroom_lights_automatically_turned_on
state: "on"
- condition: state
entity_id: light.bedroom_lights
state: "on"
- condition: state
entity_id: input_boolean.automatic_bedroom_lights
state: "on"
action:
service: light.turn_off
entity_id: light.bedroom_lights
data:
transition: 10
- alias: "Light: turn off bedroom lights auto switch"
mode: parallel
trigger:
- platform: state
entity_id: light.bedroom_lights
to: "off"
- platform: event
event_type: deconz_event
event_data:
id: dimmer_switch_bedroom
- platform: event
event_type: deconz_event
event_data:
id: smart_switch_bedroom_bas
- platform: event
event_type: deconz_event
event_data:
id: smart_switch_bedroom_marcella
condition:
condition: state
entity_id: input_boolean.bedroom_lights_automatically_turned_on
state: "on"
action:
service: input_boolean.turn_off
entity_id: input_boolean.bedroom_lights_automatically_turned_on
- alias: "Light: turn on automatic_bedroom_lights switch"
trigger:
platform: time
at: "12:00"
action:
entity_id: input_boolean.automatic_bedroom_lights
service: input_boolean.turn_on
- alias: "Light: turn off bedroom after 2 hours of inactivity"
trigger:
platform: state
entity_id: binary_sensor.activity_in_bedroom
from: "on"
to: "off"
for: "02:00:00"
condition: "{{ is_state('light.bedroom_lights', 'on') }}"
action:
service: light.turn_off
data:
entity_id: light.bedroom_lights
# _____ _ _ _
# | ____|_ _| |_ _ __ __ _ ___| |__ ___ ___| | _____
# | _| \ \/ / __| '__/ _` | / __| '_ \ / _ \/ __| |/ / __|
# | |___ > <| |_| | | (_| | | (__| | | | __/ (__| <\__ \
# |_____/_/\_\\__|_| \__,_| \___|_| |_|\___|\___|_|\_\___/
- alias: "Light: turn off toilet (extra check)"
description: In case the other automation failed
trigger:
platform: time_pattern
minutes: "/10"
condition:
- condition: state
entity_id: binary_sensor.activity_in_toilet
state: "off"
- condition: state
entity_id: light.toilet
state: "on"
action:
service: light.turn_off
entity_id: light.toilet
- alias: "Light: turn off bathroom (extra check)"
description: In case the other automation failed
trigger:
platform: time_pattern
minutes: "/10"
condition:
- condition: state
entity_id: binary_sensor.activity_in_bathroom
state: "off"
- condition: state
entity_id: light.ceiling_bathroom
state: "on"
action:
service: light.turn_off
entity_id: light.ceiling_bathroom
- alias: "Light: turn off kitchen (extra check)"
description: In case the other automation failed
trigger:
platform: time_pattern
minutes: "/10"
condition:
- condition: state
entity_id: binary_sensor.activity_in_kitchen
state: "off"
- condition: state
entity_id: light.kitchen_lights
state: "on"
action:
service: light.turn_off
entity_id: light.kitchen_lights
- alias: "Light: turn off hall (extra check)"
description: In case the other automation failed
trigger:
platform: time_pattern
minutes: "/10"
condition:
- condition: state
entity_id: binary_sensor.activity_in_hall
state: "off"
- condition: or
conditions:
- condition: state
entity_id: light.stairs_lights
state: "on"
- condition: state
entity_id: light.hall_lights
state: "on"
action:
service: light.turn_off
entity_id:
- light.hall_lights
- light.stairs_lights
- alias: "Light: turn off bedroom (extra check)"
description: In case the other automation failed
trigger:
platform: time_pattern
minutes: "/30"
condition:
- condition: state
entity_id: binary_sensor.activity_in_bedroom
state: "off"
- condition: state
entity_id: input_boolean.automatic_bedroom_lights
state: "on"
- condition: state
entity_id: input_boolean.bedroom_lights_automatically_turned_on
state: "on"
action:
- service: light.turn_off
entity_id: light.bedroom_lights
- service: light.turn_off
entity_id: input_boolean.bedroom_lights_automatically_turned_on