forked from arsaboo/homeassistant-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautomations.yaml
executable file
·1970 lines (1892 loc) · 59.8 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
###############################################################
## Presence
################################################################
- id: update_meta_tracker
alias: "Update Device Meta Tracker"
initial_state: 'on'
trigger:
# Delayed action for router-based and Owntracks trackers that are not 100% reliable
- platform: state
entity_id:
- device_tracker.myiphone
- device_tracker.rashmisiphone
- device_tracker.alokphone_alokphone
- device_tracker.rashmiphone_rashmiphone
to: 'not_home'
for: '00:07:00'
- platform: state
entity_id:
- device_tracker.alokphone_alokphone
- device_tracker.rashmiphone_rashmiphone
to: 'home'
for: '00:00:30'
- platform: state
entity_id:
- device_tracker.alokiosiphone
- device_tracker.alok_alok
- device_tracker.e1594e53_21df_414c_82da_f655d5282fca
- device_tracker.rashmiappiphone
- device_tracker.sonu_sonu
- device_tracker.b4445761_f6c0_4b7f_835f_cfdc03b47111
- platform: state
entity_id:
- device_tracker.myiphone
- device_tracker.elantrase
- device_tracker.rashmisiphone
to: 'home'
action:
- service: script.updatetracker
data_template:
entityid: '{{trigger.entity_id}}'
fromstate: '{{trigger.from_state.state}}'
tostate: '{{trigger.to_state.state}}'
# - service: logbook.log
# data_template:
# name: "Meta Tracker: "
# message: "{{trigger.entity_id}} changed from {{trigger.from_state.state}} to {{trigger.to_state.state}}"
# - service: script.notify_me
#################################################################
## Security System
#################################################################
- id: abode_ios_notifications
alias: Abode Actionable Notification
trigger:
- platform: event
event_type: abode_alarm
action:
- service: notify.ios
data:
message: 'Abode alarm triggered!'
data:
push:
badge: 0
category: "abode_alarm"
- id: disarm_abode_from_away
alias: 'Disarm Abode from Away'
initial_state: 'on'
condition:
- condition: state
entity_id: input_select.abodestatus
state: 'armed_away'
- condition: state
entity_id: input_boolean.abodeupdate
state: 'on'
- condition: template
value_template: >
{%- if states.automation.arm_abode.attributes.last_triggered -%}
{{ (as_timestamp(now()) - as_timestamp(states.automation.arm_abode.attributes.last_triggered)) > 240 }}
{%- else -%}
true
{%- endif -%}
trigger:
- platform: state
entity_id: group.household
from: 'not_home'
to: 'home'
- platform: event
event_type: ios.notification_action_fired
event_data:
actionName: DISARM_ABODE
action:
service: homeassistant.turn_on
entity_id: script.abodestandby
- id: close_garage_door_notification
alias: 'Close Garage Door Notification'
initial_state: 'on'
condition:
condition: state
entity_id: cover.garagedoor
state: 'open'
trigger:
- platform: state
entity_id: input_select.abodestatus
to: 'armed_home'
- platform: state
entity_id: input_select.abodestatus
to: 'armed_away'
action:
- service: notify.pushbullet
data:
message: "Garage Door Open"
title: "Garage Door Open"
- service: homeassistant.turn_on
entity_id: script.notificationgaragedoor
- id: disarm_abode_at_night
alias: 'Disarm Abode at night'
initial_state: 'on'
condition:
- condition: state
entity_id: input_select.abodestatus
state: 'armed_home'
- condition: state
entity_id: input_boolean.abodeupdate
state: 'on'
trigger:
- platform: state
entity_id:
- device_tracker.meta_rashmi
- device_tracker.meta_alok
from: 'not_home'
to: 'home'
action:
service: homeassistant.turn_on
entity_id: script.abodestandby
- id: abode_home_from_standby
alias: 'Abode Home from Standby'
initial_state: 'on'
condition:
condition: and
conditions:
- condition: state
entity_id: input_select.abodestatus
state: 'disarmed'
- condition: time
after: '22:15:00'
before: '07:00:00'
- condition: state
entity_id: input_boolean.abodeupdate
state: 'on'
- condition: template
value_template: >
{%- if states.input_select.abodestatus.last_changed -%}
{{ (as_timestamp(now()) - as_timestamp(states.input_select.abodestatus.last_changed)) > 300 }}
{%- else -%}
true
{%- endif -%}
trigger:
- platform: time_pattern
minutes: '/10'
action:
- service: homeassistant.turn_on
entity_id: script.abodehome
- id: abode_standby
alias: 'Abode Standby'
initial_state: 'on'
condition:
condition: and
conditions:
- condition: state
entity_id: group.household
state: 'home'
- condition: time
after: '08:15:00'
before: '21:45:00'
- condition: state
entity_id: input_boolean.abodeupdate
state: 'on'
- condition: template
value_template: >
{%- if states.input_select.abodestatus.last_changed -%}
{{ (as_timestamp(now()) - as_timestamp(states.input_select.abodestatus.last_changed)) > 300 }}
{%- else -%}
true
{%- endif -%}
- condition: or
conditions:
- condition: state
entity_id: input_select.abodestatus
state: 'armed_home'
- condition: state
entity_id: input_select.abodestatus
state: 'armed_away'
trigger:
- platform: time_pattern
minutes: '/10'
action:
- service: homeassistant.turn_on
entity_id: script.abodestandby
- id: abode_arm
alias: 'Arm Abode'
initial_state: 'on'
condition:
- condition: state
entity_id: input_boolean.abodeupdate
state: 'on'
- condition: template
value_template: >
{%- if states.automation.disarm_abode_from_away.attributes.last_triggered -%}
{{ (as_timestamp(now()) - as_timestamp(states.automation.disarm_abode_from_away.attributes.last_triggered)) > 240 }}
{%- else -%}
true
{%- endif -%}
- condition: template
value_template: "{{ states('input_select.abodestatus') != 'armed_away' }}"
trigger:
- platform: state
entity_id: group.household
from: 'home'
to: 'not_home'
- platform: state
entity_id: group.household
from: 'home'
to: 'not_home'
for: '00:10:00'
action:
service: homeassistant.turn_on
entity_id: script.abodeaway
- id: abode_home_at_night
alias: 'Abode Home at night'
initial_state: 'on'
condition:
condition: and
conditions:
- condition: state
entity_id: input_boolean.abodeupdate
state: 'on'
- condition: state
entity_id: group.household
state: 'home'
trigger:
platform: time
at: '22:00:00'
action:
service: homeassistant.turn_on
entity_id: script.abodehome
- id: abode_disarm_morning
alias: 'Disarm Abode in the morning'
initial_state: 'on'
condition:
condition: and
conditions:
- condition: state
entity_id: group.household
state: 'home'
- condition: state
entity_id: input_boolean.abodeupdate
state: 'on'
trigger:
- platform: time
at: '07:20:00'
action:
- service: homeassistant.turn_on
entity_id: script.abodestandby
- service: automation.turn_on
entity_id: automation.turn_off_master_lights
- id: enable_recording
alias: Enable Recording
initial_state: 'on'
trigger:
platform: state
entity_id: input_boolean.startrecording
to: 'on'
action:
service: switch.turn_on
entity_id: switch.foscam_record
- id: disable_recording
alias: Disable Recording
initial_state: 'on'
trigger:
platform: state
entity_id: input_boolean.startrecording
to: 'off'
action:
service: switch.turn_off
entity_id: switch.foscam_record
- id: disable_thermostat_away_mode
alias: 'Disable thermostat away'
initial_state: 'on'
condition:
- condition: template
value_template: >
{{states('input_select.abodestatus') == 'disarmed' and states('group.thermostats') == 'on'}}
trigger:
- platform: time_pattern
minutes: '/5'
action:
- service: homeassistant.turn_off
data_template:
entity_id: >
{%- if states('switch.downstairs_away') == 'on' -%}
switch.downstairs_away
{%- elif states('switch.upstairs_away') == 'on' -%}
switch.upstairs_away
{%- elif states('switch.bedroom_away') == 'on' -%}
switch.bedroom_away
{%- endif -%}
- id: enable_thermostat_away_mode
alias: 'Enable thermostat away'
initial_state: 'on'
condition:
- condition: or
conditions:
- condition: template
value_template: >
{{states('input_select.abodestatus') == 'armed_away' and states('switch.downstairs_away') == 'off'}}
- condition: template
value_template: >
{{states('input_select.abodestatus') == 'armed_away' and states('switch.upstairs_away') == 'off'}}
- condition: template
value_template: >
{{states('input_select.abodestatus') == 'armed_away' and states('switch.bedroom_away') == 'off'}}
trigger:
- platform: time_pattern
minutes: '/5'
action:
- service: homeassistant.turn_on
data_template:
entity_id: >
{%- if states('switch.downstairs_away') == 'off' -%}
switch.downstairs_away
{%- elif states('switch.upstairs_away') == 'off' -%}
switch.upstairs_away
{%- elif states('switch.bedroom_away') == 'off' -%}
switch.bedroom_away
{%- endif -%}
- id: image_processing_scan
alias: 'Image Processing Scan'
initial_state: 'on'
trigger:
- platform: state
entity_id:
- binary_sensor.backyard_field_detection
- binary_sensor.driveway_field_detection
- binary_sensor.patio_field_detection
- binary_sensor.porch_field_detection
- binary_sensor.backyard_line_crossing
- binary_sensor.driveway_line_crossing
- binary_sensor.patio_line_crossing
- binary_sensor.porch_line_crossing
- binary_sensor.ring_front_door_motion
action:
- service: image_processing.scan
data_template:
entity_id: >
{% if trigger.entity_id == "binary_sensor.ring_front_door_motion" %}
image_processing.tensorflow_porch
{% else %}
image_processing.tensorflow_{{ trigger.entity_id.split('.')[1].split('_')[0] }}
{% endif %}
- service: image_processing.scan
data_template:
entity_id: >
{% if trigger.entity_id == "binary_sensor.ring_front_door_motion" %}
image_processing.deepstack_porch
{% else %}
image_processing.deepstack_{{ trigger.entity_id.split('.')[1].split('_')[0] }}
{% endif %}
# - service: image_processing.scan
# data_template:
# entity_id: "image_processing.opencv_{{ trigger.entity_id.split('.')[1].split('_')[0] }}"
- id: opencv_image_processing_notification
alias: 'OpenCV image processing'
initial_state: 'on'
trigger:
- platform: state
entity_id:
- image_processing.opencv_porch
- image_processing.opencv_patio
- image_processing.opencv_driveway
- image_processing.opencv_backyard
condition:
- condition: template
value_template: '{{ trigger.to_state.state |int > 0 }}'
action:
- service: logbook.log
data_template:
name: "OpenCV: "
message: >-
{% for object in state_attr(trigger.entity_id,'matches').keys() -%}{%- if loop.first %}{% elif loop.last %}, {% else %}, {% endif -%}{{ object|title }}{%- endfor %} detected in {{ trigger.to_state.attributes.camera.split('.')[1] }}.
- id: tf_image_processing_notification
alias: 'TF image processing'
initial_state: 'on'
trigger:
- platform: state
entity_id:
- image_processing.tensorflow_porch
- image_processing.tensorflow_patio
- image_processing.tensorflow_driveway
- image_processing.tensorflow_backyard
- image_processing.deepstack_porch
- image_processing.deepstack_patio
- image_processing.deepstack_driveway
- image_processing.deepstack_backyard
condition:
- condition: template
value_template: '{{ trigger.to_state.state |int > 0 }}'
# - condition: template
# value_template: >
# {% set camera = trigger.entity_id.split('.')[1].split('_')[1] %}
# {%- set tags = trigger.to_state.attributes.matches.keys()|list -%}
#
# {% macro get_list(obj) %}
# {%- for x in trigger.to_state.attributes.matches[obj]|list if x.box[0] > 0.25 -%}
# {%- if loop.first %}{% elif loop.last %},{% else %},{% endif -%}{{ obj }}
# {%- endfor -%}
# {% endmacro %}
#
# {% macro run() %}
# {%- for object in tags -%}
# {%- if loop.first %}{% elif loop.last %}, {% else %}, {% endif -%}{{ obj }}
# {{- get_list(object).split(',')|list|unique|list|join|title }}
# {%- endfor -%}
# {% endmacro %}
#
# {% set output = run() %}
# {{ output == '' }}
action:
- service: logbook.log
data_template:
name: "TF: "
message: >-
{% for object in state_attr(trigger.entity_id,'matches').keys() -%}{%- if loop.first %}{% elif loop.last %}, {% else %}, {% endif -%}{{ object|title }}{%- endfor %} detected in {{ trigger.entity_id.split('.')[1].split('_')[1] }} and attributes are {{ states.image_processing[trigger.entity_id.split('.')[1]].attributes.matches }}.
- id: deepstack_image_processing_notification
alias: 'Deepstack image processing'
initial_state: 'on'
trigger:
- platform: state
entity_id:
- image_processing.deepstack_porch
- image_processing.deepstack_patio
- image_processing.deepstack_driveway
- image_processing.deepstack_backyard
condition:
- condition: template
value_template: '{{ trigger.to_state.state |int > 0 }}'
action:
- service: logbook.log
data_template:
name: "Deepstack: "
message: >-
{% for object in state_attr(trigger.entity_id,'predictions').keys() -%}{%- if loop.first %}{% elif loop.last %}, {% else %}, {% endif -%}{{ object|title }}{%- endfor %} detected in {{ trigger.entity_id.split('.')[1].split('_')[1] }} and attributes are {{ states.image_processing[trigger.entity_id.split('.')[1]].attributes.predictions }}.
# {% set camera = trigger.entity_id.split('.')[1].split('_')[1] %}
# {%- set tags = state_attr(trigger.entity_id,'matches').keys()|list -%}
#
# {% macro get_list(obj) %}
# {%- for x in state_attr(trigger.entity_id,'matches')[obj]|list if x.box[0] > 0.25 -%}
# {%- if loop.first %}{% elif loop.last %},{% else %},{% endif -%}{{ obj }}
# {%- endfor -%}
# {% endmacro %}
#
# {% macro run() %}
# {%- for object in tags -%}
# {%- if loop.first %}{% elif loop.last %}, {% else %}, {% endif -%}{{ obj }}
# {{- get_list(object).split(',')|list|unique|list|join|title }}
# {%- endfor -%}
# {% endmacro %}
#
# {% set output = run() %}
# {{- output ~ ' detected in ' ~ camera if output != '' }}
# {% set camera = trigger.entity_id.split('.')[1].split('_')[1] %}
# {%- set tags = state_attr(trigger.entity_id,'matches').keys()|list -%}
# {%- for object in tags -%}
# {%- set outer_loop = loop %}
# {%- for x in state_attr(trigger.entity_id,'matches')[object]|list if x.box[0] > 0.25 -%}
# {%- if outer_loop.first %}{% elif outer_loop.last %}, {% else %},{% endif -%}{{ object }}
# {%- endfor -%}
# {% endfor -%}
# {{- ' detected in ' ~ camera if tags|count |int > 0 }}
# {% for object in state_attr(trigger.entity_id,'matches').keys() if states.image_processing[trigger.entity_id.split('.')[1]].attributes.matches[object][0].box[0] > 0.25 -%}{%- if loop.first %}{% elif loop.last %}, {% else %}, {% endif -%}{{ object }}{%- endfor %} detected in {{ trigger.entity_id.split('.')[1].split('_')[1] }}.
- id: notify_camera_pictures
alias: 'Notify camera pictures'
initial_state: 'off'
condition:
- condition: state
entity_id: input_select.abodestatus
state: 'armed_away'
- condition: template
value_template: >
{%- if states.automation.notify_camera_pictures.attributes.last_triggered -%}
{{ (as_timestamp(now()) - as_timestamp(states.automation.notify_camera_pictures.attributes.last_triggered)) > 300 }}
{%- else -%}
true
{%- endif -%}
- condition: template
value_template: >
{%- if trigger.entity_id == "binary_sensor.backyard_field_detection" or trigger.entity_id == "binary_sensor.backyard_line_crossing" -%}
{{((as_timestamp(now()) - as_timestamp(states.binary_sensor.backyard_motion.attributes.last_tripped_time)))|round|abs < 30}}
{%- elif trigger.entity_id == "binary_sensor.driveway_field_detection" or trigger.entity_id == "binary_sensor.driveway_line_crossing" -%}
{{((as_timestamp(now()) - as_timestamp(states.binary_sensor.driveway_motion.attributes.last_tripped_time)))|round|abs < 30}}
{%- elif trigger.entity_id == "binary_sensor.patio_field_detection" or trigger.entity_id == "binary_sensor.patio_line_crossing" -%}
{{((as_timestamp(now()) - as_timestamp(states.binary_sensor.patio_motion.attributes.last_tripped_time)))|round|abs < 30}}
{%- elif trigger.entity_id == "binary_sensor.porch_field_detection" or trigger.entity_id == "binary_sensor.porch_line_crossing" -%}
{{((as_timestamp(now()) - as_timestamp(states.binary_sensor.porch_motion.attributes.last_tripped_time)))|round|abs < 30}}
{%- else -%}
true
{%- endif -%}
trigger:
- platform: state
entity_id:
- binary_sensor.backyard_field_detection
- binary_sensor.driveway_field_detection
- binary_sensor.patio_field_detection
- binary_sensor.porch_field_detection
- binary_sensor.backyard_line_crossing
- binary_sensor.driveway_line_crossing
- binary_sensor.patio_line_crossing
- binary_sensor.porch_line_crossing
from: 'off'
to: 'on'
action:
- service: notify.ios
data_template:
message: "Check {{ trigger.entity_id.split('.')[1].split('_')[0] }} camera."
data:
push:
category: camera
entity_id: "camera.{{ trigger.entity_id.split('.')[1].split('_')[0] }}"
attachment:
url: "{{ states.camera[trigger.entity_id.split('.')[1].split('_')[0]].attributes.entity_picture }}"
content-type: jpg
# - service: shell_command.image_classify
# data_template:
# camera: "{{ trigger.entity_id.split('.')[1].split('_')[0] }}"
# - service: shell_command.facebox
# data_template:
# camera: "{{ trigger.entity_id.split('.')[1].split('_')[0] }}"
# - service: camera.snapshot
# data_template:
# entity_id: "camera.{{ trigger.entity_id.split('.')[1].split('_')[0] }}"
# filename: '/home/homeassistant/.homeassistant/downloads/camera/{{ trigger.entity_id.split(".")[1].split("_")[0] }}_{{ now().strftime("%d%h%Y_%H%M%S") }}.jpg'
- service: logbook.log
data_template:
name: "Camera activity: "
message: >-
{%- for state in states if state.entity_id == trigger.entity_id -%}
{{ state.attributes.friendly_name }} activated at {{ as_timestamp(now()) | timestamp_custom('%I:%M:%S %p', true) }}.
{%- endfor -%}
- service: logbook.log
data_template:
name: "Motion detected: "
message: >-
{%- if trigger.entity_id == "binary_sensor.backyard_field_detection" or trigger.entity_id == "binary_sensor.backyard_line_crossing" -%}
{{(as_timestamp(now()) - as_timestamp(states.binary_sensor.backyard_motion.attributes.last_tripped_time))|round(2)}} seconds ago.
{%- elif trigger.entity_id == "binary_sensor.driveway_field_detection" or trigger.entity_id == "binary_sensor.driveway_line_crossing" -%}
{{(as_timestamp(now()) - as_timestamp(states.binary_sensor.driveway_motion.attributes.last_tripped_time))|round(2)}} seconds ago.
{%- elif trigger.entity_id == "binary_sensor.patio_field_detection" or trigger.entity_id == "binary_sensor.patio_line_crossing" -%}
{{(as_timestamp(now()) - as_timestamp(states.binary_sensor.patio_motion.attributes.last_tripped_time))|round(2)}} seconds ago.
{%- elif trigger.entity_id == "binary_sensor.porch_field_detection" or trigger.entity_id == "binary_sensor.porch_line_crossing" -%}
{{(as_timestamp(now()) - as_timestamp(states.binary_sensor.porch_motion.attributes.last_tripped_time))|round(2)}} seconds ago.
{%- endif -%}
- id: notify_tensorflow_detection
alias: 'Notify Tensorflow detection'
initial_state: 'on'
condition:
- condition: state
entity_id: input_select.abodestatus
state: 'armed_away'
- condition: template
value_template: '{{ trigger.to_state.state |int > 0 }}'
- condition: template
value_template: >
{%- if states.automation.notify_tensorflow_detection.attributes.last_triggered -%}
{{ (as_timestamp(now()) - as_timestamp(state_attr('automation.notify_tensorflow_detection','last_triggered'))) > 30 }}
{%- else -%}
true
{%- endif -%}
trigger:
- platform: state
entity_id:
- image_processing.tensorflow_porch
- image_processing.tensorflow_patio
- image_processing.tensorflow_driveway
- image_processing.tensorflow_backyard
action:
- service: notify.ios_alokiosiphone
data_template:
message: >
{{ state_attr(trigger.entity_id,'matches').keys()|list|unique|list|join|title }} detected in {{ trigger.entity_id.split('.')[1].split('_')[1] }} camera.
data:
push:
category: camera
entity_id: "camera.{{ trigger.entity_id.split('.')[1].split('_')[1] }}"
attachment:
url: "{{ states.camera[trigger.entity_id.split('.')[1].split('_')[1]].attributes.entity_picture }}"
content-type: jpg
- id: save_camera_images
alias: 'Camera - Save images on motion'
initial_state: 'off'
trigger:
- platform: state
entity_id:
- binary_sensor.backyard_motion
- binary_sensor.backyard_field_detection
- binary_sensor.backyard_line_crossing
- binary_sensor.driveway_motion
- binary_sensor.driveway_field_detection
- binary_sensor.driveway_line_crossing
- binary_sensor.patio_motion
- binary_sensor.patio_field_detection
- binary_sensor.patio_line_crossing
- binary_sensor.porch_field_detection
- binary_sensor.porch_line_crossing
- binary_sensor.porch_motion
from: 'off'
to: 'on'
action:
- service: camera.snapshot
data_template:
entity_id: "camera.{{ trigger.entity_id.split('.')[1].split('_')[0] }}"
filename: '/home/homeassistant/.homeassistant/downloads/camera/{{ trigger.entity_id.split(".")[1].split("_")[0] }}/{{ trigger.entity_id.split(".")[1].split("_")[0] }}_{{ now().strftime("%d%h%Y_%H%M%S") }}.jpg'
#################################################################
## HASS Related
#################################################################
- id: battery_alert
alias: 'Battery Alert'
initial_state: 'on'
trigger:
- platform: state
entity_id: sensor.battery_status
action:
- service: persistent_notification.create
data_template:
title: Low Battery levels
notification_id: low-battery-alert
message: >
Check battery: {{ states('sensor.battery_status') }}
- service: notify.pushbullet
data_template:
title: "Battery status"
message: >
Check battery: {{ states('sensor.battery_status') }}
- id: heal_zwave_network
alias: Heal Z-Wave Network
initial_state: 'on'
trigger:
platform: time
at: '2:31:00'
action:
service: zwave.heal_network
# {{state_attr('zwave.garage_door_tilt_sensor','query_stage')=='CacheLoad'}}
# - id: z-wave_cacheload
# alias: Repair Z-Wave Network
# initial_state: 'on'
# trigger:
# - platform: state
# entity_id: zwave.garage_door_tilt_sensor
# to: 'initializing'
# - platform: state
# entity_id: zwave.garage_relay
# to: 'initializing'
# action:
# service: zwave.test_network
- id: update_available_notification
alias: "Update Available Notification"
initial_state: 'on'
trigger:
platform: template
value_template: "{{states('sensor.pypi_hass_version') == states('sensor.current_version') }}"
action:
- service: notify.pushbullet
data:
message: "HomeAssistant {{ states('sensor.pypi_hass_version') }} is now available"
title: "Update HASS"
- service: persistent_notification.create
data:
title: "Update Available"
message: >
Home Assistant {{ states('sensor.pypi_hass_version') }} is available, please update.
notification_id: "update_available"
- id: change_current_theme
alias: 'Change Current Theme'
initial_state: 'on'
trigger:
- platform: state
entity_id: input_select.current_theme
action:
- service: frontend.set_theme
data_template:
name: "{{states('input_select.current_theme')}}"
#################################################################
## Commute Times
#################################################################
- id: update_morning_commute_sensor
alias: "Commute - Update morning commute sensor"
initial_state: 'on'
trigger:
- platform: time_pattern
minutes: '/2'
condition:
- condition: time
after: '08:00:00'
before: '11:00:00'
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: state
entity_id: device_tracker.meta_alok
state: 'home'
action:
- service: sensor.google_travel_sensor_update
data:
entity_id: sensor.morning_commute
- id: update_evening_commute_sensor
alias: "Commute - Update evening commute sensor"
initial_state: 'on'
trigger:
- platform: time_pattern
minutes: '/2'
condition:
- condition: time
after: '17:00:00'
before: '20:00:00'
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: template
value_template: >
{%- if states('device_tracker.meta_alok') -%}
{{ states('device_tracker.meta_alok')|lower in ('buckhead', 'downtown') }}
{%- else -%}
false
{%- endif -%}
action:
- service: sensor.google_travel_sensor_update
data:
entity_id: sensor.alok_to_home
- id: morning_commute
alias: "Morning Commute"
initial_state: 'on'
condition:
condition: and
conditions:
- condition: time
after: '08:15:00'
before: '11:00:00'
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: state
entity_id: device_tracker.meta_alok
state: 'home'
trigger:
platform: numeric_state
entity_id: sensor.morning_commute
below: 43
action:
- service: notify.pushbullet
data:
message: Commute time is 43 minutes
title: Leave for Work
target: device/myiPhone
- service: homeassistant.turn_on
entity_id: script.notificationleavework
- id: evening_commute
alias: "Evening Commute"
initial_state: 'on'
condition:
condition: and
conditions:
- condition: time
after: '17:00:00'
before: '20:00:00'
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: template
value_template: >
{%- if states('device_tracker.meta_alok') -%}
{{ states('device_tracker.meta_alok') != 'home' }}
{%- else -%}
false
{%- endif -%}
trigger:
platform: template
value_template: >
{%- if states.sensor.alok_to_home.attributes.duration_in_traffic -%}
{{(states.sensor.alok_to_home.attributes.duration_in_traffic.split(' ')[0]|int) / (states.sensor.alok_to_home.attributes.duration.split(' ')[0]|int) < 1.25}}
{%- else -%}
false
{%- endif -%}
action:
service: notify.pushbullet
data_template:
message: Commute time is {{states.sensor.alok_to_home.attributes.duration_in_traffic.split(' ')[0]|int}} minutes
title: Leave for Home
target: device/myiPhone
- id: plexspy_notification
alias: "Plex Spy notification"
initial_state: 'on'
trigger:
platform: state
entity_id: sensor.plexspy
action:
- service: notify.pushbullet
data_template:
message: >
{%- if states.sensor.plexspy.attributes -%}
{% set space = joiner(' ') %}
{%- for attr in states.sensor.plexspy.attributes -%}
{%- if not attr=="friendly_name" and not attr=="unit_of_measurement" and not attr=="homebridge_hidden"-%}
{{space()}}{{attr}} is watching {{states.sensor.plexspy.attributes[attr]}}.
{%- endif -%}
{%- endfor -%}
{%- endif -%}
title: "Plex {{ trigger.to_state.state }} people streaming. "
target: device/myiPhone
- service: logbook.log
data_template:
name: "Plex {{ trigger.to_state.state }} people streaming. "
message: >
{%- if states.sensor.plexspy.attributes -%}
{% set space = joiner(' ') %}
{%- for attr in states.sensor.plexspy.attributes -%}
{%- if not attr=="friendly_name" and not attr=="unit_of_measurement" and not attr=="homebridge_hidden"-%}
{{space()}}{{attr}} is watching {{states.sensor.plexspy.attributes[attr]}}.
{%- endif -%}
{%- endfor -%}
{%- endif -%}
#################################################################
## Home Automation Related
#################################################################
- id: xiaomi_vibration_sensor_test
alias: Xiaomi Vibration sensor test
initial_state: 'on'
trigger:
- platform: event
event_type: xiaomi_aqara.movement
event_data:
entity_id: binary_sensor.vibration_158d0002a51fc2
movement_type: tilt
action:
- service: light.toggle
data:
entity_id: light.master_lights
- service: logbook.log
data_template:
name: "Xiaomi event: "
message: >
{{trigger.event.data}}
- id: micube_test
alias: MiCube event test
initial_state: 'on'
trigger:
- platform: event
event_type: xiaomi_aqara.cube_action
event_data:
entity_id: binary_sensor.cube_158d0001035aa7
action:
- service: logbook.log
data_template:
name: "MiCube event: "
message: >
{%- if trigger.event.data.action_value -%}
{{trigger.event.data.action_type}} and {{trigger.event.data.action_value}}
{%- else -%}
{{trigger.event.data.action_type}}
{%- endif -%}
- id: micube_brightness_rotate
alias: "MiCube rotate - Master lights"
initial_state: 'on'
condition:
- condition: state
entity_id: light.master_lights
state: 'on'
trigger:
platform: event
event_type: xiaomi_aqara.cube_action
event_data:
entity_id: binary_sensor.cube_158d0001035aa7
action_type: rotate
action:
- service: light.turn_on
data_template:
entity_id: light.master_lights
brightness: >
{% set state = (state_attr('light.master_lights','brightness') + trigger.event.data.action_value|int) -%}
{%- if state > 255 -%}
{%- set state = 255 -%}
{%- elif state < 0 -%}
{%- set state = 0 -%}
{%- endif %}
{{ state }}
- id: micube_scenes_reset
alias: "MiCube scene reset"
initial_state: on
condition:
- condition: state
entity_id: light.master_lights
state: 'on'
trigger:
platform: event
event_type: xiaomi_aqara.cube_action
event_data:
entity_id: binary_sensor.cube_158d0001035aa7
action_type: flip180
action:
service: script.set_hue_scene
data_template:
group: "Master"
scene: "Bright"
- id: micube_master_scenes
alias: "MiCube Master scene"
initial_state: on
condition:
- condition: state
entity_id: light.master_lights
state: 'on'
trigger:
- platform: event
event_type: xiaomi_aqara.cube_action
event_data:
entity_id: binary_sensor.cube_158d0001035aa7
action_type: flip90
action:
- service: script.set_hue_scene
data_template:
group: "Master"
scene: >
{{ ['Arctic aurora', 'Galaxy', 'Starlight', 'Nightlight', 'Savanna sunset', 'Spring blossom', 'Tropical twilight'] | random }}
- service: automation.turn_off
entity_id: automation.turn_off_master_lights
- id: micube_toggle_master
alias: "MiCube Toggle Master"
initial_state: on
trigger:
platform: event
event_type: xiaomi_aqara.cube_action
event_data:
entity_id: binary_sensor.cube_158d0001035aa7
action_type: tap_twice
action:
- service: light.toggle
data:
entity_id: light.master_lights