-
Notifications
You must be signed in to change notification settings - Fork 201
/
automations.yaml
executable file
·717 lines (645 loc) · 19.2 KB
/
automations.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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
##############################################
################### Toilet ###################
##############################################
# Motion sensor on door for initial light, Distance sensor pointed at the toilet to keep lights on.
# This basically makes sure the lights dont stay on for 5 minutes, they turn off if no one is there.
#Detects first motion at toilet door
- alias: 'Toilet On Motion'
# hide_entity: true
trigger:
- entity_id: binary_sensor.toilet_motion
platform: state
to: 'on'
action:
service: scene.turn_on
data:
entity_id: scene.toilet_on
transition: 0.5
#Keeps lights on when distance sensor sees someone on the toilet
- alias: 'Toilet On Occupied'
# hide_entity: true
trigger:
- entity_id: binary_sensor.toilet_in_use
platform: state
to: 'on'
for:
hours: 0
minutes: 0
seconds: 7
action:
service: scene.turn_on
target:
entity_id: scene.toilet_on
#Keeps lights on when distance sensor sees and motion is triggered
- alias: 'Toilet On Occupied with Motion'
# hide_entity: true
trigger:
- entity_id: binary_sensor.toilet_in_use
platform: state
to: 'on'
condition:
condition: state
entity_id: binary_sensor.toilet_motion
state: 'on'
action:
service: scene.turn_on
target:
entity_id: scene.toilet_on
#If no motion or proximity, turn off toilet lights
- alias: 'Toilet Off'
# hide_entity: true
trigger:
- entity_id: binary_sensor.toilet_motion
platform: state
to: 'off'
condition:
condition: state
entity_id: binary_sensor.toilet_in_use
state: 'off'
action:
service: scene.turn_on
target:
entity_id: scene.toilet_off
#Keep turning off toilet lights every 5 seconds
#if light has been turned on for more than 3 mins
- alias: 'Toilet Off Distance'
# hide_entity: true
trigger:
platform: time_pattern
seconds: "/5"
condition:
- condition: state
entity_id: light.toilet_1
state: 'on'
for:
hours: 0
minutes: 0
seconds: 130
- condition: state
entity_id: binary_sensor.toilet_in_use
state: 'off'
for:
hours: 0
minutes: 0
seconds: 12
action:
service: scene.turn_on
target:
entity_id: scene.toilet_off
#Make sure if someone is sitting on the toilet,
#The lights remain on
- alias: 'Toilet On Distance'
# hide_entity: true
trigger:
platform: time_pattern
seconds: "/1"
condition:
- condition: state
entity_id: binary_sensor.toilet_in_use
state: 'on'
action:
service: scene.turn_on
target:
entity_id: scene.toilet_on
##############################################
#################### Roof ####################
##############################################
# Two motion sensors detect if someone is moving upstairs or downstairs, counts people on roof.
# A vibration sensor detects the angle of the roof door and turns lights on and off.
- alias: Person goes upstairs
# hide_entity: true
trigger:
- platform: state
entity_id: binary_sensor.roof_motion
to: 'on'
condition:
- condition: state
entity_id: binary_sensor.stairs_detector_motion
state: 'on'
action:
service: counter.increment
entity_id: counter.people_on_roof
- alias: Person goes downstairs
trigger:
- platform: state
entity_id: binary_sensor.stairs_detector_motion
to: 'on'
condition:
- condition: state
entity_id: binary_sensor.roof_motion
state: 'on'
- condition: numeric_state
entity_id: counter.people_on_roof
above: 0
action:
service: counter.decrement
entity_id: counter.people_on_roof
- alias: Turn on Roof
# hide_entity: true
trigger:
platform: state
entity_id: binary_sensor.roof_door_open
to: "on"
condition:
condition: state
entity_id: sun.sun
state: 'below_horizon'
action:
service: homeassistant.turn_on
entity_id:
- light.roof_plants
- light.roof_garden
- light.roof
- light.roof_lights
- alias: Turn Off Roof
# hide_entity: true
trigger:
platform: state
entity_id: binary_sensor.roof_door_open
to: "off"
action:
service: homeassistant.turn_off
entity_id:
- light.roof_plants
- light.roof_garden
- light.roof
- light.roof_lights
- alias: "Roof Off Morning"
# hide_entity: true
trigger:
- platform: time
at: '04:00:00'
action:
- service: homeassistant.turn_off
data:
entity_id:
- light.roof_plants
- light.roof_garden
- light.roof
- light.roof_lights
## Set nighttime value for Health Graphs
- alias: 'Set Nighttime input'
# hide_entity: true
trigger:
platform: sun
event: sunset
offset: "-00:45:00"
action:
entity_id: input_number.nighttime
service: input_number.set_value
data:
value: 20
- alias: 'Set Daytime input'
# hide_entity: true
trigger:
platform: sun
event: sunrise
offset: "-00:45:00"
action:
entity_id: input_number.nighttime
service: input_number.set_value
data:
value: 0
## Set custom theme on startup
- alias: 'System - Set Custom Theme at Startup'
# hide_entity: true
initial_state: 'true'
trigger:
platform: homeassistant
event: start
action:
service: frontend.set_theme
data:
name: slate
## Browser-mod Switch views when something happens
- alias: Change to Media Screen
# hide_entity: true
trigger:
- platform: state
entity_id: media_player.plex_projector
to: 'playing'
- platform: state
entity_id: media_player.spotify
to: 'playing'
- platform: state
entity_id: media_player.chrome_surround_speakers
to: 'playing'
action:
service: script.turn_on
entity_id: script.navigate_to_media
##############################################
################# IR Blaster #################
##############################################
#### Homekit make toggle a button:
#### This controls my IR blaster to send volume commands, so I can just keep tapping the button like it was an actual remote in Homekit.
- alias: Sound Up
# hide_entity: true
trigger:
- platform: state
entity_id: switch.speakers_up
to: 'on'
action:
service: switch.turn_off
entity_id: switch.speakers_up
- alias: Sound Down
# hide_entity: true
trigger:
- platform: state
entity_id: switch.speakers_down
to: 'on'
action:
service: switch.turn_off
entity_id: switch.speakers_down
- alias: Projector Off
trigger:
platform: state
entity_id: device_tracker.projector
to: 'not_home'
for:
minutes: 3
action:
- service: switch.turn_off
entity_id: switch.projector_audio
- service: script_turn_on
entity_id: script.navigate_to_lights
- alias: Projector On
# hide_entity: true
trigger:
- platform: state
entity_id: device_tracker.projector
to: 'home'
action:
- service: switch.turn_on
entity_id: switch.projector_audio
- service: script_turn_on
entity_id: script.navigate_to_media
##############################################
################## Diabetes ##################
##############################################
# Fun fact, im a type 1 diabetic. My house knows my sugar level (connected CgM)
# If a low sugar is detected, the tablet displays a warning and turns lights red
# Light colors also warn me if there is an issue with my insulin pump
# - id: '1234567890123'
# alias: overnight_low_kitchen_lights
# description: Turn on the lights in the kitchen if my blood sugar drops low overnight
# trigger:
# - below: '65'
# entity_id: sensor.blood_glucose
# platform: numeric_state
# condition: time
# after: '22:00:00'
# before: '06:00:00'
# action:
# - service: light.turn_on
# data:
# entity_id: light.kitchen
#### Sugar levels low ####
- alias: Issue with CGM!
# hide_entity: true
trigger:
- platform: state
entity_id: sensor.luke_cgm_direction
to: 'NOT'
action:
- service: scene.create
data:
scene_id: snapshot_cabinet
snapshot_entities:
- light.cabinet
- service: light.turn_on
data:
brightness: 150
rgb_color: [0, 30, 200]
entity_id:
- light.cabinet
- alias: No issue with cgm
# hide_entity: true
trigger:
- platform: state
entity_id: sensor.luke_cgm_direction
from: 'NOT'
condition:
condition: numeric_state
entity_id: sensor.luke_cgm_sgv_mmol
above: '4'
action:
- service: scene.turn_on
entity_id: scene.snapshot_cabinet
- service: browser_mod.close_popup
- alias: Low Blood Sugar!
# hide_entity: true
trigger:
- platform: numeric_state
entity_id: sensor.luke_cgm_sgv_mmol
below: '4'
condition:
condition: template
value_template: "{{ states.sensor.luke_cgm_direction.state != 'NOT' }}"
action:
- service: scene.create
data:
scene_id: snapshot_cabinet
snapshot_entities:
- light.cabinet
- service: light.turn_on
data:
brightness: 150
rgb_color: [255, 0, 0]
entity_id:
- light.cabinet
- service: browser_mod.popup
data:
title: Low Blood Sugar!
card:
type: 'custom:mini-graph-card'
color_thresholds:
- color: '#FF004C'
value: 3
- color: '#03B4FF'
value: 5
- color: '#03B4FF'
value: 8
- color: '#B51BE4'
value: 9
line_width: 2
points_per_hour: 6
hours_to_show: 25
height: 130
update_interval: 30
entities:
- entity: sensor.buienradar_ground_temperature
- entity: binary_sensor.night
color: rgba(255,255,255,.25)
y_axis: secondary
smoothing: false
aggregate_func: min
show_state: false
show_line: false
show_points: false
- entity: input_number.range_high
color: rgba(255,255,255,.1)
smoothing: false
line_width: 1
aggregate_func: max
show_state: false
show_line: true
show_points: false
- entity: input_number.range_low
color: rgba(255,255,255,.1)
smoothing: false
line_width: 1
aggregate_func: max
show_state: false
show_line: true
show_points: false
state_map:
- value: "off"
label: "Day"
- value: "on"
label: "Night"
icon: 'mdi:water-outline'
align_state: right
align_icon: right
name_adaptive_color: true
icon_adaptive_color: true
show:
icon: true
legend: false
name: false
fill: false
points: hover
deviceID:
- e3bcb892-264fae95
- 0290dd82-2a03ce63
- tablet
- alias: Normal Blood Sugar
# hide_entity: true
trigger:
- platform: numeric_state
entity_id: sensor.luke_cgm_sgv_mmol
above: '4'
action:
- service: scene.turn_on
entity_id: scene.snapshot_cabinet
- service: browser_mod.close_popup
##############################################
############### Watching movies ##############
##############################################
#### Automate lights when watching movies, pause on toilet break ####
- alias: Plex Playing
# hide_entity: true
trigger:
- platform: state
entity_id: media_player.plex_projector
to: 'playing'
condition:
- condition: state
entity_id: sun.sun
state: 'below_horizon'
action:
service: script.turn_on
entity_id: script.plex_moviestarted
- alias: Plex Paused
# hide_entity: true
trigger:
- platform: state
entity_id: media_player.plex_projector
to: 'paused'
condition:
- condition: state
entity_id: light.toilet_1
state: 'on'
action:
- service: browser_mod.popup
data:
title: Movie Paused
style:
width: 400px
card:
type: 'custom:button-card'
icon: mdi:play-circle
tap_action:
action: call-service
service: script.turn_on
service_data:
entity_id: script.plex_continuemovie
label: Continue Playing
show_label: true
size: 45%
styles:
card:
- height: 400px
deviceID:
- e3bcb892-264fae95
- 0290dd82-2a03ce63
- tablet
- alias: Plex Playing Break
# hide_entity: true
trigger:
- platform: state
entity_id: light.toilet_1
to: 'on'
condition:
- condition: state
entity_id: media_player.plex_projector
state: 'playing'
action:
- service: media_player.media_pause
entity_id: media_player.plex_projector
- alias: Plex Playing Break Study
# hide_entity: true
trigger:
- platform: state
entity_id: light.study
to: 'on'
condition:
- condition: state
entity_id: media_player.plex_projector
state: 'playing'
action:
service: media_player.media_pause
entity_id: media_player.plex_projector
- alias: Plex Playing Continue
# hide_entity: true
trigger:
- platform: state
entity_id: light.toilet_1
to: 'unavailable'
condition:
- condition: state
entity_id: media_player.plex_projector
state: 'paused'
- condition: state
entity_id: light.study
state: 'off'
action:
service: media_player.media_play
entity_id: media_player.plex_projector
- alias: Plex Playing Continue Study
# hide_entity: true
trigger:
- platform: state
entity_id: light.study
to: 'off'
condition:
- condition: state
entity_id: light.toilet_1
state: 'off'
- condition: state
entity_id: media_player.plex_projector
state: 'paused'
action:
service: media_player.media_play
entity_id: media_player.plex_projector
- alias: Plex Stopped
# hide_entity: true
trigger:
- platform: state
entity_id: media_player.plex_projector
to: '0'
condition:
- condition: state
entity_id: sun.sun
state: 'below_horizon'
action:
service: script.turn_on
entity_id: script.slowly_turn_on_livingroom
##############################################
############ Xiomi Robot UI status ###########
##############################################
#### Updating status of Room Cleaning input ####
- alias: Vacuum Returning
# hide_entity: true
trigger:
- platform: state
entity_id: sensor.vacuum_status
to: 'Returning home'
action:
- service: input_text.set_value
data_template:
entity_id: input_text.room_cleaning
value: "goinghome"
- alias: Vacuum Idle
# hide_entity: true
trigger:
- platform: state
entity_id: sensor.vacuum_status
to: 'Idle'
action:
service: input_text.set_value
data_template:
entity_id: input_text.room_cleaning
value: "paused"
- alias: Vacuum Charging
# hide_entity: true
trigger:
- platform: state
entity_id: sensor.vacuum_status
to: 'Charging'
action:
- service: input_text.set_value
data_template:
entity_id: input_text.room_cleaning
value: "charging"
##############################################
############ UI Sounds for tablet ############
##############################################
- alias: ui_sound_on
# hide_entity: true
trigger:
- platform: state
entity_id:
['light.door', 'light.stairs_2', 'light.bed', 'light.bedroom_roof', 'light.toilet_2', 'light.toilet_1', 'light.cabinet',
'light.table', 'light.couch', 'light.kitchen_4', 'light.kitchen_3', 'light.kitchen_2', 'light.kitchen_1', 'light.roof_plants',
'light.roof_garden', 'switch.speakers_up', 'switch.speakers_down', 'switch.speakers', 'switch.projector_audio',
'light.balcony','light.study']
from: 'off'
to: 'on'
action:
- service: media_player.play_media
data:
entity_id: media_player.tablet
media_content_id: /local/ui/sound/on.m4a
media_content_type: music
- alias: ui_sound_off
# hide_entity: true
trigger:
- platform: state
entity_id:
['light.door', 'light.stairs_2', 'light.bed', 'light.bedroom_roof', 'light.toilet_2', 'light.toilet_1', 'light.cabinet',
'light.table', 'light.couch', 'light.kitchen_4', 'light.kitchen_3', 'light.kitchen_2', 'light.kitchen_1', 'light.roof_plants',
'light.roof_garden', 'switch.speakers_up', 'switch.speakers_down', 'switch.speakers', 'switch.projector_audio',
'light.balcony','light.study']
from: 'on'
to: 'off'
action:
- service: media_player.play_media
data:
entity_id: media_player.tablet
media_content_id: /local/ui/sound/off.m4a
media_content_type: music
- alias: ui_sound_popup
# hide_entity: true
trigger:
platform: event
event_type: call_service
event_data:
domain: browser_mod
service: popup
action:
- service: media_player.play_media
data:
entity_id: media_player.tablet
media_content_id: /local/ui/sound/popup.m4a
media_content_type: music
- alias: ui_sound_view
# hide_entity: true
trigger:
platform: state
entity_id: sensor.tablet_view
action:
- service: media_player.play_media
data:
entity_id: media_player.tablet
media_content_id: /local/ui/sound/popup.m4a
media_content_type: music