-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathautomations.yaml
5326 lines (5212 loc) · 147 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
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
- id: '1588556714529'
alias: Maintenance at midnight
description: Runs every night at midnight.
trigger:
- platform: time
at: 00:00:00
condition: []
action:
- data:
message: Daily maintenance begins.
type: warning
duration: 300
service: script.notify_web
continue_on_error: true
- service: homeassistant.turn_off
continue_on_error: true
target:
entity_id:
- input_boolean.guest_mode
- input_boolean.leave_unlocked
data: {}
- data: {}
service: script.holiday_sensors_update
continue_on_error: true
- data:
keep_days: 10
repack: true
service: recorder.purge
- service: switch.turn_off
continue_on_error: true
data: {}
target:
entity_id: switch.docker_unifi
- delay:
hours: 0
minutes: 0
seconds: 15
milliseconds: 0
- service: switch.turn_on
continue_on_error: true
data: {}
target:
entity_id: switch.docker_unifi
- service: button.press
continue_on_error: true
data: {}
target:
entity_id:
- button.omg01_restart_gateway
- button.omg02_restart_gateway
- button.kitchen_cabinet_lights_restart
- button.irrigation_controller_restart
- button.workbench_presence_restart_device
- button.dishwasher_status_restart
alias: Restart ESPHome + WLED devices.
- service: script.notify_web
continue_on_error: true
data:
type: success
message: Daily maintenance complete.
mode: single
- id: '1618159056314'
alias: Startup
description: Actions to run at startup.
trigger:
- platform: homeassistant
event: start
condition: []
action:
- service: script.notify_web
data:
message: Startup automation begins.
type: warning
duration: 120
- service: automation.turn_on
data: {}
target:
entity_id:
- automation.z2m_remote_nerene_bedside
- automation.z2m_remote_brian_bedside
alias: Force bedside remotes to remain enabled.
- service: frontend.set_theme
data:
name: Mushroom Shadow
- delay:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
- service: script.inovelli_led_set_defaults
data:
entity_id: light.family_room
color: Teal
- service: logger.set_default_level
data:
level: warning
- service: watchman.report
data: {}
- service: script.notify_web
data:
message: Startup automation complete.
type: success
duration: 60
- service: logbook.log
data:
message: ' complete'
entity_id: automation.startup
name: Startup automation
- delay:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
- service: template.reload
data: {}
alias: Reload template sensors.
- service: automation.turn_off
data: {}
target:
entity_id: automation.startup
mode: single
initial_state: true
- id: '1620056955070'
alias: 'Scheduled tasks: hourly'
description: Tasks to run every hour.
trigger:
- platform: time_pattern
hours: /1
condition: []
action:
- service: script.refresh_update_sensors
mode: single
- id: '1620532169172'
alias: Keep startup automation off
description: The startup automation will turn back on after an automation reload.
So turn it right back off when it changes from "unavailable" to "on".
trigger:
- platform: event
event_type: automation_reloaded
condition:
- condition: template
value_template: '{%- set uptime_minutes = (now()|as_timestamp - states("sensor.last_restart")|as_timestamp)|round(0,default=0)
/ 60 %}
{{ uptime_minutes > 5 }}'
alias: Continue if it has been more than 5 minutes since the last restart.
action:
- service: automation.turn_off
target:
entity_id: automation.startup
data: {}
mode: single
- id: '1624556633877'
alias: Safety alert garage door obstruction detected
description: Alert when the garage door is unable to close due an obstruction.
trigger:
- platform: state
entity_id:
- cover.garage_door
attribute: obstruction-detected
to: 'true'
for:
hours: 0
minutes: 1
seconds: 0
from: 'false'
condition: []
action:
- service: script.notify_speech
data:
media_player: media_player.google_welcome
message: The garage door cannot close due to an obstruction. Please help the
garage door close safely.
- service: script.notify_mobile
data:
title: Garage door obstructed
url: /lovelace/outdoor
message: The garage door cannot close due to an obstruction. Please help the
garage door close safely.
critical: true
mode: single
- id: '1638465871838'
alias: Maintenance before sunrise
description: 'Runs every day 2 hours before sunrise.
1. Reset adaptive lighting switches.
2. Update watchman report.
3. Ensure bedroom do not disturb is enabled.
4. Disable "Keep outdoor lights off" toggle.'
trigger:
- platform: sun
event: sunrise
offset: '-2:00:00'
condition: []
action:
- service: watchman.report
continue_on_error: true
data: {}
alias: Update watchman report.
- if:
- condition: state
entity_id: switch.google_bedroom_do_not_disturb
state: 'off'
then:
- service: switch.turn_on
continue_on_error: true
data: {}
target:
entity_id: switch.google_bedroom_do_not_disturb
alias: Restore bedroom do not disturb.
- service: input_boolean.turn_off
data: {}
target:
entity_id: input_boolean.keep_outdoor_lights_off
- service: script.toggle_entity
continue_on_error: true
data:
entity_id: switch.adaptive_lighting_family_room
alias: Adaptive lighting restore automated control.
mode: single
- id: '1638910619111'
alias: 'Maintenace: after sunrise'
description: Turn the entry and porch lights off after sunrise.
trigger:
- platform: sun
event: sunrise
offset: +00:15:00
action:
- service: switch.turn_off
continue_on_error: true
target:
entity_id: switch.adaptive_lighting_home_entry
alias: Turn off adaptive lighting control temporarily.
data: {}
- service: light.turn_off
continue_on_error: true
data:
transition: 10
target:
entity_id:
- light.home_entry
- light.path_lights
- light.porch
- service: select.select_option
data:
option: Auto
target:
entity_id: select.driveway_flood_mode
- service: light.turn_off
continue_on_error: true
data: {}
target:
entity_id: light.driveway_flood_accent
- service: switch.turn_on
continue_on_error: true
target:
entity_id: switch.adaptive_lighting_home_entry
alias: Turn adaptive lighting control back on.
data: {}
- id: '1640128623256'
alias: 'Maintenance: lights before sunset'
description: ''
trigger:
- platform: sun
event: sunset
offset: -00:30:00
action:
- service: light.turn_on
continue_on_error: true
data:
transition: 10
target:
entity_id:
- light.porch
- light.path_lights
- service: script.say
data:
media_player: media_player.google_kitchen
message: '{{ [
''It is about to get dark outside. I will turn on the lights now.'',
''It is almost sunset. Time to turn on the lights.'',
''I will switch on the outdoor lights.'',
''Time to turn on the front lights.''
]|random }}
'
- if:
- condition: state
entity_id: binary_sensor.work_day
state: 'on'
then:
- service: light.turn_on
data: {}
target:
entity_id:
- light.family_room
- light.family_room_table_lamp
enabled: false
- service: script.cast
data:
dashboard_path: dashboard-cast
view_path: night
displays:
- 47e1a1a35bb2d1e827ccdeb761f5721b
- 7d6b52507e25e7eeba10914e56052d1c
enabled: false
mode: single
- id: '1640887750655'
alias: Wet laundry Family room LED indicator
description: The light will chase blue when the laundry wet alert is active.
use_blueprint:
path: brianhanifin/inovelli_led_notify.yaml
input:
trigger_entity_id: alert.wet_laundry
on_trigger_state: 'on'
off_trigger_state: idle
inovelli_entity_id: light.family_room
color: Blue
effect: Chase
duration: Indefinitely
- id: '1642400705340'
alias: 'Remote: Brian bedside'
description: ''
use_blueprint:
path: mozartbanging/zigbee2mqtt-aqara-opple-wxcjkg13lm-3-band-switch-all-custom-buttons.yaml
input:
switch: sensor.remote_brian_bedside_action
button_1_single:
- service: light.toggle
data:
transition: 0
target:
entity_id: light.bedroom
button_2_single:
- service: light.toggle
data:
transition: 0
target:
entity_id: light.bedroom_east
button_1_double:
- service: light.toggle
data:
transition: 0
target:
entity_id: light.bedroom_table_lamp
button_2_double:
- service: light.toggle
data: {}
target:
entity_id: light.bedroom_table_lamp
button_3_single:
- service: fan.toggle
data: {}
target:
entity_id: fan.bedroom
alias: Toggle fan on/off.
button_4_single:
- service: switch.toggle
target:
device_id: 4fb4fa5e3d2742488c93b02c34bbd7e8
data: {}
button_6_single:
- service: climate.turn_off
target:
entity_id: climate.bedroom_thermostat
data: {}
button_5_single:
- choose:
- conditions:
- condition: state
entity_id: climate.bedroom_thermostat
state: cool
sequence:
- service: climate.set_hvac_mode
target:
entity_id: climate.bedroom_thermostat
data:
hvac_mode: fan_only
default:
- service: climate.set_hvac_mode
target:
entity_id: climate.bedroom_thermostat
data:
hvac_mode: cool
alias: Toggle between cool + fan.
- id: '1642402019243'
alias: 'Remote: Nerene bedside'
description: ''
use_blueprint:
path: mozartbanging/zigbee2mqtt-aqara-opple-wxcjkg13lm-3-band-switch-all-custom-buttons.yaml
input:
switch: sensor.remote_nerene_bedside_action
button_1_single:
- service: light.toggle
data:
transition: 0
target:
entity_id: light.bedroom
button_2_single:
- service: light.toggle
data:
transition: 0
target:
entity_id: light.bedroom_east
button_1_double:
- service: light.toggle
data:
transition: 0
target:
entity_id: light.bedroom_table_lamp
button_2_double:
- service: light.toggle
data:
transition: 0
target:
entity_id: light.bedroom_table_lamp
button_3_single:
- service: fan.toggle
data: {}
target:
entity_id: fan.bedroom
alias: Toggle fan on/off.
button_4_single:
- service: switch.toggle
target:
device_id: 4fb4fa5e3d2742488c93b02c34bbd7e8
data: {}
button_6_single:
- service: climate.turn_off
target:
entity_id: climate.bedroom_thermostat
data: {}
button_5_single:
- choose:
- conditions:
- condition: state
entity_id: climate.bedroom_thermostat
state: cool
sequence:
- service: climate.set_hvac_mode
target:
entity_id: climate.bedroom_thermostat
data:
hvac_mode: fan_only
default:
- service: climate.set_hvac_mode
target:
entity_id: climate.bedroom_thermostat
data:
hvac_mode: cool
alias: Toggle between cool + fan.
- id: '1642448378521'
alias: 'Remote: printer toggle'
description: ''
use_blueprint:
path: freakshock/zigbee2mqtt-xiaomi-mijia-round-wireless-remote-switch-wxkg01lm-actions.yaml
input:
button_sensor: sensor.printer_button_action
remote_button_single_press:
- service: switch.toggle
data: {}
target:
entity_id: switch.printer
- id: '1642908642407'
alias: Doorbell pushed
description: ''
trigger:
- platform: state
entity_id:
- sensor.doorbell_action
to: bell1
condition: []
action:
- service: script.notify_audio
data:
audio_file: media-source://media_source/local/audio/jetsons-doorbell.mp3
speakers:
- media_player.google_family_room
volume: 75
alias: Play the doorbell sound in the Family room.
- parallel:
- service: script.notify_mobile
data:
who: brian
title: Doorbell
message: Someone pushed the doorbell.
camera: camera.front_door
- service: script.notify_web
data:
message: Someone pressed the doorbell!
duration: 60
enabled: false
- service: script.notify_mobile
data:
who: blackpc
title: Doorbell
message: Someone pushed the doorbell.
camera: camera.front_door
- delay:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
alias: Cooldown before allow another ring.
mode: single
- id: '1643829963937'
alias: HACS install event - update sensors
description: ''
trigger:
- platform: event
event_type: hacs/repository
event_data:
action: install
condition: []
action:
- delay:
hours: 0
minutes: 0
seconds: 30
milliseconds: 0
- service: homeassistant.update_entity
data: {}
target:
entity_id: sensor.updates
mode: single
- id: '1643862026593'
alias: External IP changed
description: ''
trigger:
- platform: state
entity_id: sensor.external_ip
condition: []
action:
- service: script.notify_mobile
data:
who: brian
title: IP changed
message: 'From: {{trigger.from_state.state}}
To: {{trigger.to_state.state}}'
- if:
- condition: template
value_template: '{{ trigger.to_state.state=="unavailable"}}'
then:
- service: switch.turn_off
data: {}
target:
entity_id: switch.docker_unifi
- delay:
hours: 0
minutes: 0
seconds: 15
milliseconds: 0
- service: switch.turn_on
data: {}
target:
entity_id: switch.docker_unifi
else: []
mode: single
- id: '1644783738380'
alias: Google next timer actions
description: ''
trigger:
- platform: state
entity_id: sensor.google_next_timer
attribute: end_time
id: update_end_time
- platform: event
event_type: timer.started
event_data:
entity_id: timer.google_next_timer
id: timer_started
enabled: true
- platform: event
event_type: timer.finished
event_data:
entity_id: timer.google_next_timer
id: timer_finished
- platform: event
event_type:
- timer.cancelled
- timer.paused
event_data:
entity_id: timer.google_next_timer
id: timer_cancelled
- platform: state
entity_id: input_button.google_next_timer_cancel
id: cancel_button_pressed
condition: []
action:
- if:
- condition: template
value_template: '{{ state_attr("sensor.google_next_timer","end_time") == none
}}'
then:
- service: timer.cancel
data: {}
target:
entity_id: timer.google_next_timer
- service: media_player.turn_off
target:
entity_id: media_player.google_kitchen
data: {}
else:
- choose:
- conditions:
- condition: trigger
id: update_end_time
sequence:
- service: timer.start
target:
entity_id: timer.google_next_timer
data:
duration: '{%- set now = now()|as_timestamp %}
{%- set end_time = state_attr("sensor.google_next_timer","end_time")|as_timestamp
%}
{%- set seconds_until_end = end_time - now %}
{{ seconds_until_end }}
'
- delay:
seconds: 5
- service: script.cast
continue_on_error: true
data:
dashboard_path: dashboard-cast
view_path: timers
display:
- 0aae07dda66f42e9b8a67979e34770d0
- 7d6b52507e25e7eeba10914e56052d1c
- conditions:
- condition: trigger
id: timer_started
enabled: true
sequence:
- service: script.cast
data:
displays:
- 7d6b52507e25e7eeba10914e56052d1c
dashboard_path: dashboard-cast
view_path: timers
- conditions:
- condition: trigger
id: timer_finished
sequence:
- service: script.notify_speech
data:
media_player: media_player.google_kitchen
message: Your {{ state_attr("sensor.google_next_timer", "label") }} just
ended.
- service: script.notify_web
data:
type: alert
title: '{{ state_attr("sensor.google_next_timer", "label") }} has ended'
message: '{%- set end_time = state_attr("sensor.google_next_timer","end_time")|default(now())|as_datetime
%}
**{{ state_attr("sensor.google_next_timer", "label") }}** {{ " ended
at " ~
"{:1}:{:02}:{:02}".format(end_time.hour, end_time.minute, end_time.second)
}}
'
- service: script.cast
continue_on_error: true
data:
dashboard_path: dashboard-cast
view_path: timers
dismiss_after: 120
display:
- 0aae07dda66f42e9b8a67979e34770d0
- 7d6b52507e25e7eeba10914e56052d1c
- conditions:
- condition: or
conditions:
- condition: trigger
id: cancel_button_pressed
- condition: trigger
id: timer_cancelled
sequence:
- service: google_home.delete_timer
data:
entity_id: '{{ state_attr("sensor.google_next_timer","active_sensor")
}}'
timer_id: '{{ state_attr("sensor.google_next_timer","id") }}'
- service: timer.cancel
target:
entity_id: timer.google_next_timer
data: {}
- service: script.notify_web
data:
message: Timer stopped
default: []
mode: single
- id: '1654047415255'
alias: Restart tuya lights when unavailable
description: ''
trigger:
- platform: state
entity_id:
- light.driveway_flood
to: unavailable
alias: When the driveway lights stays offline for 30 minutes.
for:
hours: 0
minutes: 30
seconds: 0
id: driveway_light_offline
condition: []
action:
- if:
- condition: trigger
id:
- driveway_light_offline
then:
- service: switch.turn_off
continue_on_error: true
data: {}
target:
entity_id: switch.driveway_flood_light_power_cycler
alias: Turn off the plug, which automatically turns itself back on after a delay.
alias: When triggered by driveway_light_offline, cycle the power to the light.
- delay:
hours: 0
minutes: 10
seconds: 0
milliseconds: 0
mode: single
- id: '1654483867439'
alias: Vacuum update status periodically
description: ''
trigger:
- platform: time_pattern
hours: /3
minutes: '0'
condition:
- condition: device
device_id: 8532ec8c935bfb73fc9438d6a98033cb
domain: vacuum
entity_id: vacuum.downstairs
type: is_docked
- condition: device
device_id: 05429a8986c6f325628f5d664519825e
domain: vacuum
entity_id: vacuum.play_room
type: is_docked
action:
- service: script.vacuum_update
data:
vacuum:
- vacuum.downstairs
- vacuum.play_room
mode: single
- id: '1654484047176'
alias: Vacuum update status while not docked
description: ''
trigger:
- platform: event
event_type: call_service
id: family_room
event_data:
domain: vacuum
service: start
service_data:
entity_id: vacuum.downstairs
- platform: event
event_type: call_service
id: play_room
event_data:
domain: vacuum
service: start
service_data:
entity_id: vacuum.play_room
condition: []
action:
- service: script.vacuum_update
data: {}
- wait_for_trigger:
- platform: event
event_type: state_changed
event_data:
entity_id: vacuum.downstairs
- platform: event
event_type: state_changed
event_data:
entity_id: vacuum.play_room
timeout:
hours: 0
minutes: 1
seconds: 0
milliseconds: 0
- if:
- condition: trigger
id: family_room
then:
- repeat:
until:
- condition: device
device_id: 8532ec8c935bfb73fc9438d6a98033cb
domain: vacuum
entity_id: vacuum.downstairs
type: is_docked
sequence:
- delay:
hours: 0
minutes: 2
seconds: 30
milliseconds: 0
- service: script.vacuum_update
data:
vacuum:
- vacuum.downstairs
- if:
- condition: trigger
id: play_room
then:
- repeat:
until:
- condition: device
device_id: 05429a8986c6f325628f5d664519825e
domain: vacuum
entity_id: vacuum.play_room
type: is_docked
sequence:
- delay:
hours: 0
minutes: 2
seconds: 30
milliseconds: 0
- service: script.vacuum_update
data:
vacuum:
- vacuum.play_room
mode: parallel
max: 2
- id: '1654547714136'
alias: Vacuum refresh until charged
description: 'Refresh state when docked until 100% charged.
'
trigger:
- platform: device
device_id: 8532ec8c935bfb73fc9438d6a98033cb
domain: vacuum
entity_id: vacuum.downstairs
type: docked
id: family_room
- platform: device
device_id: 05429a8986c6f325628f5d664519825e
domain: vacuum
entity_id: vacuum.play_room
type: docked
id: play_room
condition: []
action:
- if:
- condition: trigger
id: family_room
then:
- repeat:
until:
- condition: numeric_state
entity_id: vacuum.downstairs
attribute: battery_level
above: '99'
sequence:
- delay:
hours: 0
minutes: 10
seconds: 0
milliseconds: 0
- service: script.vacuum_update
data:
vacuum:
- vacuum.downstairs
- if:
- condition: trigger
id: play_room
then:
- repeat:
until:
- condition: numeric_state
entity_id: vacuum.play_room
attribute: battery_level
above: '99'
sequence:
- delay:
hours: 0
minutes: 10
seconds: 0
milliseconds: 0
- service: script.vacuum_update
data:
vacuum:
- vacuum.play_room
mode: single
- id: '1655258894395'
alias: Update day off + work day modified sensors
description: ''
trigger:
- id: calendar
platform: calendar
entity_id: calendar.nerene
event: start
- platform: homeassistant
event: start
id: restart
enabled: true
- id: end_of_day
platform: time
at: '23:59:00'
- platform: time
at: 00:01:00
id: start_of_day
condition: []
action:
- if:
- condition: or
conditions:
- condition: trigger
id: calendar
- condition: trigger
id: start_of_day
- condition: trigger
id: restart
then:
- variables:
today: '{{ now() }}
'
event_date: '{{ as_datetime(state_attr("calendar.nerene","start_time")) }}
'
event_midnight: '{%- set event_date = as_datetime(state_attr("calendar.nerene","start_time"))
%}
{%- set seconds_from_midnight = (event_date.hour*3600) + (event_date.minute*60)
%}
{{ (event_date - timedelta(seconds=seconds_from_midnight)) }}
'
event_message: '{{ state_attr("calendar.nerene","message") }}
'
message: "{%- set today = today|as_timestamp %}\n{%- set event_date = as_datetime(state_attr(\"calendar.nerene\",\"start_time\"))
%}\n{%- set seconds_from_midnight = (event_date.hour*3600) + (event_date.minute*60)
%}\n{%- set event_midnight = (event_date - timedelta(seconds=seconds_from_midnight))
%}\n{%- set event_midnight = event_midnight|as_timestamp %}\n{%- if today
>= event_midnight %}\n {{ event_message }}\n{%- endif %}\n"
mqtt_message_attributes:
today: '{{ today }}'
next_event_date: '{{ event_date }}'
next_event_midnight: '{{ event_midnight }}'
next_event_message: '{{ event_message }}'
- alias: Debug output. (Disable to turn off.)
service: script.debug
data:
message: 'today: "{{ now() }}"
event_date: "{{ event_date }}"
event_midnight: "{{ event_midnight }}"
event_message: "{{ event_message }}"
message: "{{ message }}"
mqtt_message_attributes: "{{ mqtt_message_attributes }}
'
enabled: false
- service: script.store_mqtt_sensor
data:
name: nerene_events_today
state: "{%- set today = now()|as_timestamp %} {%- set event_date = state_attr(\"calendar.nerene\",\"start_time\")|as_timestamp
%} {%- if today >= event_date %}\n {%- set events = state_attr(\"binary_sensor.days_off\",\"events_today\")|trim
%}\n {%- set events = events ~ \",\" if events not in [\"\",\"None\"] %}\n
\ {{ events ~ state_attr(\"calendar.nerene\",\"message\") }}\n{%- else %}\n
\ {%- set events_today = state_attr(\"binary_sensor.days_off\",\"events_today\")
%}\n {{ iif(events_today is not none, events_today, \"\") }}\n{%- endif
%}\n"
else: []
- if:
- condition: trigger
id: end_of_day
then:
- service: script.store_mqtt_sensor