/
presence.yaml
executable file
·484 lines (463 loc) · 14.5 KB
/
presence.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
###############################################################################
# @author : Jeffrey Stone
# @date : 02/19/2019
# @package : Presence
# @description : A Collection of Presence Related Trackers and Sensors
###############################################################################
input_datetime:
last_time_home_jeff:
name: Jeff Last Seen
has_date: true
has_time: true
last_time_home_kat:
name: Kat Last Seen
has_date: true
has_time: true
last_time_home_skylar:
name: Skylar Last Seen
has_date: true
has_time: true
# Testing Proximity Sensors
proximity:
home_jeff:
devices:
- device_tracker.life360_jeffrey_stone
zone: home
tolerance: 5
unit_of_measurement: mi
home_kat:
devices:
- device_tracker.life360_kat_stone
zone: home
tolerance: 5
unit_of_measurement: mi
home:
devices:
- device_tracker.life360_jeffrey_stone
- device_tracker.life360_kat_stone
zone: home
tolerance: 5
unit_of_measurement: mi
sensor:
- platform: template
sensors:
jeff_location:
friendly_name: "Jeff"
unit_of_measurement: ""
value_template: >-
{% set person = states.person.jeffrey.state %}
{%- if person in ['Sprouts','Kroger1','Kroger2'] %}
Grocery Store
{% elif person in ['HomeDepot','Lowes'] %}
Home Improvement Store
{% elif person in ['Walmart','Target'] %}
Super Store
{% else %}
{% if person in ['not_home'] %}
{{ state_attr('device_tracker.life360_jeffrey_stone','address') }}
{% else %}
{{ states('person.jeffrey') }}
{%- endif %}
{%- endif %}
- platform: template
sensors:
skylar_location:
friendly_name: "Skylar"
unit_of_measurement: ""
value_template: >-
{% if is_state('input_boolean.skylar_school', 'on') %}
school
{% elif is_state('calendar.skylar_events', 'on') %}
{{ state_attr('calendar.skylar_events', 'message') }}
{%- elif is_state('person.jeffrey', 'home') and is_state('person.katherine', 'home') and is_state('input_boolean.skylar_school', 'off')%}
home
{%- elif is_state('person.jeffrey', 'Summit') and is_state('input_boolean.skylar_school', 'off')%}
{{ states('sensor.kat_location') }}
{%- elif is_state('person.katherine', 'ZooAtlanta') and is_state('input_boolean.skylar_school', 'off')%}
{{ states('person.jeffrey') }}
{% else %}
Unknown
{%- endif %}
- platform: template
sensors:
kat_location:
friendly_name: "Kat"
unit_of_measurement: ""
value_template: >-
{% set person = states('person.katherine') %}
{%- if person in ['Sprouts','Kroger1','Kroger2'] %}
Grocery Store
{% elif person in ['HomeDepot','Lowes'] %}
Home Improvement Store
{% elif person in ['Walmart','Target'] %}
Super Store
{% else %}
{%- if person in ['ZooAtlanta'] %}
Zoo Atlanta
{% elif person in ['not_home'] %}
{{ state_attr('device_tracker.life360_kat_stone', 'address') }}
{% else %}
{{ states('person.katherine') }}
{%- endif %}
{%- endif %}
- platform: mqtt
name: "Family Status"
state_topic: "house/family/status"
payload_available: "online"
payload_not_available: "offline"
- platform: mqtt
name: "Family Arrived"
state_topic: "house/family/arrived"
payload_available: "online"
payload_not_available: "offline"
- platform: template
sensors:
jeff_home:
value_template: >-
{{ is_state('device_tracker.jeffrey_s_iphone_11', 'home') or is_state('device_tracker.jeffrey_s_iphone_11_app', 'home')
or is_state('device_tracker.life360_jeffrey_stone', 'home') }}
- platform: template
sensors:
kat_home:
value_template: >-
{{ is_state('device_tracker.iphone', 'home')
or is_state('device_tracker.life360_kat_stone', 'home') or is_state('device_tracker.iphone', 'home') }}
automation:
- id: skylar_is_awake
alias: Skylar is Awake
initial_state: true
trigger:
- platform: state
entity_id: binary_sensor.skylar_bedroom_motion_occupancy
to: "on"
from: "off"
- platform: state
entity_id: binary_sensor.skylar_room_occupancy
to: "on"
from: "off"
condition:
- condition: time
after: "05:00:00"
before: "08:30:00"
- condition: state
entity_id: input_boolean.skylar_awake
state: "off"
action:
- service: input_datetime.set_datetime
entity_id: input_datetime.skylar_awake_at
data:
time: "{{ now().strftime('%H:%M') }}"
- service: input_boolean.turn_on
entity_id: input_boolean.skylar_awake
- service: switch.turn_off
entity_id: switch.rainbow_light
- id: skylar_early_morning_tv
alias: Skylar Early Morning TV
initial_state: true
trigger:
- platform: state
entity_id: media_player.theater_tv
to: "on"
from: "off"
- platform: state
entity_id: media_player.croft_tv
to: "playing"
condition:
- condition: time
after: "05:00:00"
before: "08:30:00"
- condition: state
entity_id: input_boolean.skylar_dressed_reminder
state: "off"
- condition: state
entity_id: input_boolean.skylar_awake
state: "on"
action:
- service: script.status_annc
data:
who: >-
{% if is_state('media_player.theater_tv', 'on') %}
theater
{% else %}
croft
{% endif %}
call_interuption: 1
call_skylar_dressed_reminder: 1
- service: input_boolean.turn_on
entity_id: input_boolean.skylar_dressed_reminder
- id: kat_arrives_zoo
alias: Kat Arrives at Zoo
initial_state: true
trigger:
- platform: zone
event: enter
zone: zone.zoo_atlanta
entity_id: person.katherine
action:
- service: input_boolean.turn_off
entity_id: input_boolean.kat_travel_monitor
- service: script.status_annc
data:
who: "{{ states('sensor.room_audio') }}"
speech_message: "Kat has arrived at work."
- id: kat_leaves_zoo
alias: Kat Leaves Zoo Notification
initial_state: true
trigger:
- platform: zone
event: leave
zone: zone.zoo_atlanta
entity_id: person.katherine
action:
- service: input_boolean.turn_on
entity_id: input_boolean.kat_travel_monitor
- service: script.status_annc
data_template:
who: "{{ states('sensor.room_audio') }}"
call_interpruption: 1
call_kat_location: 1
- id: skylar_at_school
alias: Skylar is at School
trigger:
- entity_id: person.jeffrey
event: leave
platform: zone
zone: zone.starling
- entity_id: person.katherine
event: leave
platform: zone
zone: zone.starling
- entity_id: person.skylar
event: enter
platform: zone
zone: zone.starling
condition:
- condition: time
before: "13:30:00"
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: state
entity_id: input_boolean.skylar_school
state: "off"
action:
- service: input_boolean.turn_on
entity_id: input_boolean.skylar_school
- service: script.text_alert
data:
who: parents
message: "Skylar has been dropped off at school."
initial_state: true
- id: skylar_left_school
alias: Skylar left School
trigger:
- entity_id: person.jeffrey
event: leave
platform: zone
zone: zone.starling
- entity_id: person.katherine
event: leave
platform: zone
zone: zone.starling
- entity_id: person.skylar
event: leave
platform: zone
zone: zone.starling
condition:
- condition: time
after: "11:30:00"
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: state
entity_id: input_boolean.skylar_school
state: "on"
action:
- service: input_boolean.turn_off
entity_id: input_boolean.skylar_school
- service: script.text_alert
data:
who: parents
message: "Skylar has been picked up from school."
initial_state: true
- id: jeff_arrives_summit
alias: Jeff Arrives At Summit
trigger:
- entity_id: person.jeffrey
event: enter
platform: zone
zone: zone.summit
action:
- service: script.text_notify
data:
who: "kat"
message: "Jeff has arrived at Summit"
- service: script.jeff_destination_na
initial_state: true
- id: e1cb15b0-0423-11eb-adc1-0242ac120002
alias: Zone Debugger
trigger:
- platform: state
entity_id: person.jeffrey
condition:
- condition: state
entity_id: input_boolean.jeff_location_debug
state: 'on'
action:
- service: script.jeff_location_debug
- id: jeff_leaves_summit
alias: Jeff Leaves Summit
initial_state: true
trigger:
- entity_id: person.jeffrey
event: leave
platform: zone
zone: zone.summit
action:
- service: input_boolean.turn_off
entity_id: input_boolean.jeff_traffic_alert_home
- id: welcome_home
alias: Welcome Home
mode: restart
trigger:
- platform: state
entity_id:
- person.jeffrey
- person.katherine
- person.uncle_matt
- person.papa
- person.skylar
from: "not_home"
to: "home"
action:
- choose:
- conditions:
- condition: state
entity_id: input_boolean.welcome_home
state: "on"
sequence:
- service: script.turn_on
entity_id: script.welcome_briefing
default:
- service: group.set
data:
object_id: "arriving"
add_entities: >-
{{ trigger.to_state.entity_id }}
- wait_template: "{{ is_state('binary_sensor.laundry_room_door', 'on') }}"
timeout: "00:3:00"
- service: script.status_annc
data_template:
who: "{{ states.sensor.room_presence.state }}"
call_interuption: 1
speech_message: >
{% set person = expand('group.arriving')|map(attribute='name')|join(' and ') %}
{% set peoplecount = expand('group.arriving') | count %}
{% if peoplecount == 1 %}
{% set is_are = ' is ' %}
{% set has_have = ' has ' %}
{% else %}
{% set is_are = ' are ' %}
{% set has_have = ' have ' %}
{% endif %}
{%- macro greeting_sentence(person, is_are, has_have) -%}
{{ [
person ~ has_have + " arrived.",
"My sensors are picking up the presence of additional humans. " ~ person ~ has_have + " been identified as home.",
"Guess who is home?" ~ person ~ is_are,
"I am sensing a disturbance in the force. " ~ person +" must be home!",
person ~ is_are + "now in the house.",
person ~ is_are + " now here. Hash tag Welcome Home.",
person ~ is_are + " now here. Hash tag Home.",
"I know a secret! " ~ person ~ is_are +" home!",
"Just a quick announcement. " ~ person ~ has_have +" arrived!",
"Hey" ~ person + "! High Five! Glad you are finally home.",
"Just a quick announcement. " ~ person ~ has_have + " arrived!",
person ~ has_have + " finally made it home."
] | random }}
{%- endmacro -%}
{{greeting_sentence(person, is_are, has_have)}}
- delay: 00:02:00
- service: group.set
data:
object_id: "arriving"
entities: []
- id: guests_have_arrived
alias: Guests have arrived
trigger:
- entity_id: person.papa
event: enter
platform: zone
zone: zone.home
- entity_id: person.uncle_matt
event: enter
platform: zone
zone: zone.home
action:
- service: script.standby
- service: script.family_is_home
- service: input_boolean.turn_on
entity_id: input_boolean.guest_mode
initial_state: true
- id: disable_bad_traffic_home_jeff
alias: Disabling Jeff Bad Traffic Home
initial_state: true
trigger:
- platform: numeric_state
entity_id: sensor.jeff_ett_home
below: 40
- platform: state
entity_id: sensor.jeff_destination
to: Home
condition:
- condition: state
entity_id: input_boolean.jeff_traffic_alert_home
state: "on"
action:
- service: input_boolean.turn_off
entity_id: input_boolean.jeff_traffic_alert_home
script:
family_is_home:
sequence:
- condition: state
entity_id: group.family
state: "home"
- service: script.standby
family_is_away:
sequence:
- condition: state
entity_id: group.family
state: "not_home"
- service: script.appliances_off
- service: scene.turn_on
entity_id: scene.lights_out
- service: input_boolean.turn_on
entity_id: input_boolean.sentry_mode
- service: scene.turn_on
entity_id: scene.all_fans_off
- service: input_boolean.turn_on
entity_id: input_boolean.welcome_home
reset_skylar_sensors:
sequence:
- delay: 02:00:00
- service: input_datetime.set_datetime
entity_id: input_datetime.skylar_awake_at
data:
time: "00:00:00"
- service: input_boolean.turn_off
entity_id: input_boolean.skylar_awake
jeff_location_debug:
sequence:
- condition: state
entity_id: input_boolean.jeff_location_debug
state: 'on'
- service: script.text_alert
data:
who: jeff
message: "Jeff is at {{ states('person.jeffrey') }}"