-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathtemplate.yaml
executable file
·501 lines (462 loc) · 29.9 KB
/
template.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
- binary_sensor:
- name: "All Present Sleeping"
unique_id: all_present_sleeping
delay_off:
minutes: 0
state: >
{% if ((is_state('person.maximiliano', 'home') and is_state('binary_sensor.maxi_sleeping', 'on' ) ) or not is_state('person.maximiliano', 'home' )) %}on{% else %}off{% endif %}
- name: "Sensor Patio Occupancy"
state: >
{{ not is_state('sensor.patio_camera_person_count', "0")
or is_state('binary_sensor.sensor_patio_motion_occupancy', 'on')
or is_state('binary_sensor.sensor_patio_ceiling_motion_occupancy', 'on')
}}
- name: "maxi is talking"
unique_id: "maxi_is_talking"
state: >-
{{ (not is_state('sensor.phone_fold4_phone_state', "idle"))
or is_state('binary_sensor.pc_maxi_desktop_microphoneactive', 'on')
}}
- name: "maxi is listening"
unique_id: "maxi_is_listening"
state: >-
{{ ( is_state('sensor.phone_fold4_media_session', "Playing")
or not is_state('sensor.phone_fold4_phone_state', "idle")
or states('sensor.pc_maxi_desktop_audio_audio_sessions') | int > 0 and is_state('sensor.maxi_location', "office") and is_state('sensor.pc_maxi_desktop_audio_default_device_muted', "False") )
}}
- name: Lola Went Out
unique_id: "lola_went_out"
state: >
{% if (as_timestamp(now()) - as_timestamp(states.sensor.front_door_camera_dog_count.last_changed )) < 32400 %}
on
{% else %}
off
{% endif %}
- sensor:
- name: "Existing Rooms"
unique_id: "existing_rooms"
state: >-
{% set areas = states | selectattr('attributes.device_class', 'defined') | map(attribute='entity_id') | map('area_id') | unique | reject('none') | list %}
{{ areas }}
- name: "current time"
unique_id: "current_time"
state: >-
{{now().strftime('%H:%M %p')}}
- name: "Closet Lights Brightness"
unique_id: "closet_lights_brightness"
state: >-
{% if state_attr('light.group_closet_lights', 'brightness') %}
{{ state_attr('light.group_closet_lights', 'brightness') }}
{% else %}
1
{% endif %}
- name: "Office Lights color"
unique_id: "office_lights_color"
state: >-
{% if state_attr('light.group_office_lights', 'rgb_color') %}
{{ state_attr('light.group_office_lights', 'rgb_color') }}
{% else %}
0
{% endif %}
- name: "Playing on Bedroom Speaker"
unique_id: "playing_on_bedroom_speaker"
state: >-
{% if state_attr('media_player.bedroom_speaker', 'media_series_title') %}
{{ state_attr('media_player.bedroom_speaker', 'media_series_title') }}
{% elif state_attr('media_player.bedroom_speaker', 'media_album_name') %}
{{ state_attr('media_player.bedroom_speaker', 'media_title') }} - {{ state_attr('media_player.bedroom_speaker', 'media_album_name') }} by {{ state_attr('media_player.bedroom_speaker', 'media_artist') }}
{% elif state_attr('media_player.bedroom_speaker', 'media_title') %}
{{ state_attr('media_player.bedroom_speaker', 'media_title') }}
{% elif state_attr('media_player.bedroom_speaker', 'app_name') %}
{{ state_attr('media_player.bedroom_speaker', 'app_name') }}
{% endif %}
- name: "Playing on home group Speaker"
unique_id: "playing_on_home_group_speaker"
state: >-
{% if state_attr('media_player.group_home_speakers', 'media_series_title') %}
{{ state_attr('media_player.group_home_speakers', 'media_series_title') }}
{% elif state_attr('media_player.group_home_speakers', 'media_album_name') %}
{{ state_attr('media_player.group_home_speakers', 'media_title') }} - {{ state_attr('media_player.group_home_speakers', 'media_album_name') }} by {{ state_attr('media_player.group_home_speakers', 'media_artist') }}
{% elif state_attr('media_player.group_home_speakers', 'media_title') %}
{{ state_attr('media_player.group_home_speakers', 'media_title') }}
{% elif state_attr('media_player.group_home_speakers', 'app_name') %}
{{ state_attr('media_player.group_home_speakers', 'app_name') }}
{% endif %}
- name: "Maxi Location"
unique_id: "maxi_location"
state: >-
{% set braceletroom = states('sensor.b7bracelet1') %}
{% set watchroom = states('sensor.watch_galaxy4') %}
{% set watchonbody = states('binary_sensor.galaxy_watch_4_on_body_sensor') %}
{% set phoneroom = states('sensor.phone_fold4') %}
{% set gpslocation = states('device_tracker.phone_galaxy_fold_4') %}
{% if watchonbody == "on" and watchroom != "not_home" %}
{% set location = watchroom %}
{% elif braceletroom != "not_home" %}
{% set location = braceletroom %}
{% elif phoneroom != "not_home" %}
{% set location = phoneroom %}
{% elif gpslocation != "not_home"%}
{% set location = "At " + gpslocation %}
{% else %}
{% set location = unkown %}
{% endif %}
{{ location }}
- name: "Maxis Current Game"
unique_id: "currentgamemaxi"
state: >-
{% if state_attr('sensor.maxi1134_8202', 'game') %}
{{ state_attr('sensor.maxi1134_8202', 'game') }}
{% elif state_attr('sensor.steam_maxi', 'game') %}
{{state_attr('sensor.steam_maxi', 'game')}}
{% else %} idle
{% endif %}
- name: "Maxis Current Discord Game"
state: >-
{% if state_attr('sensor.maxi1134_8202', 'game') %}
{{ state_attr('sensor.maxi1134_8202', 'game') }}
{% else %}idle
{% endif %}
- name: "Maxis Current Steam Game"
state: >-
{% if state_attr('sensor.steam_maxi', 'game') %}
{{state_attr('sensor.steam_maxi', 'game')}}
{% else %}idle
{% endif %}
- name: "amount partners home"
unique_id: "amount_partners_home"
state: >-
{# set the ammount of partners home #}
{% if states('person.maximiliano') == "home" %} {# If I am home, the amount should be zone.home -1 #}
{% set partnershome = states('zone.home') | int - 1 %}
{% else %}{# If I am not home, the amount should be zone.home #}
{% set partnershome = states('zone.home') | int %}
{% endif %}
{{partnershome | int }}
- name: "amount friends home"
unique_id: "amount_friends_home"
state: >-
{# Set friendshome to the amount of friends #}
{% set friendshome = states('sensor.guest_wifi_count') | int - states('sensor.amount_partners_home') | int %}
{{friendshome}}
- name: "amount people home"
unique_id: amount_people_home
state: >-
{# Set peoplehome to the amount of people #}
{% set peoplehome = states('sensor.amount_friends_home') | int + states('sensor.amount_partners_home') | int %}
{{peoplehome}}
- name: "last active room"
unique_id: last_active_room
state: >-
{% set rooms = states('sensor.existing_rooms') %}
{# Check for motionsensors in the rooms and then store them in a list #}
{% set ns = namespace( active_motion_sensors = [] )%}
{% for allowed_rooms in rooms %}
{% for state in states.binary_sensor -%}
{% if allowed_rooms in state.entity_id and "binary_sensor.sensor_" in state.entity_id and "occupancy" in state.entity_id %}
{% set sensor = {'entity_id': state.entity_id,'state': state.state, 'last_changed': state.last_changed} %}
{% set ns.active_motion_sensors = ns.active_motion_sensors + [sensor] %}
{%- endif %}
{% endfor %}
{% endfor %}
{# sorts the motion sensor list to output the active room where there was last motion#}
{% if ns.active_motion_sensors | selectattr('state', 'eq', 'on')| sort(attribute='last_changed') %}
{% set sorted_sensors = ns.active_motion_sensors | selectattr('state', 'eq', 'on')| sort(attribute='last_changed') %}
{% set last_sensor = sorted_sensors | last %}
{% else %} {# If no sensor is on, take latest active sensor#}
{% set sorted_sensors = ns.active_motion_sensors | sort(attribute='last_changed') %}
{% set last_sensor = sorted_sensors | last %}
{% endif %}
{# set the lasttvactiveroom variant #}
{% set room_before_split =last_sensor.entity_id | replace('binary_sensor.sensor_','')| replace('_motion_occupancy','')| replace('fp2_','')%}
{% set lasttvactiveroom = room_before_split.split('_') | first %}
{{lasttvactiveroom}}
- name: "active_sleeper_rooms"
unique_id: "active_sleeper_rooms"
state: >-
{% set ns = namespace(active_sleeper_rooms = []) %} {# create a namespace object to store variables #}
{%- for boolean in states.input_boolean -%}
{% if boolean.state == "on" and "input_boolean.sleeper_" in boolean.entity_id %}
{% set sensor = boolean.entity_id | replace('input_boolean.sleeper_in_','') %}
{% set ns.active_sleeper_rooms = ns.active_sleeper_rooms + [sensor] %}
{%- endif %}
{% endfor %}
{{ ns.active_sleeper_rooms }}
- name: "active_sleepers"
unique_id: "active_sleepers"
state: >-
{{ states.input_boolean | selectattr('state','eq','on') | selectattr('entity_id','search',"input_boolean.sleeper_") | list | count }}
attributes:
rooms: >
{% set ns = namespace(items=[]) %}
{% for inp in states.input_boolean | selectattr('state','eq','on') | selectattr('entity_id','search',"input_boolean.sleeper_") %}
{% set ns.items = ns.items + [ (loop.index, inp.entity_id | replace('input_boolean.sleeper_in_','') ) ] %}
{% endfor %}
{{ dict.from_keys(ns.items) }}
- name: "active_sleeper_amount"
unique_id: "active_sleeper_amount"
state: >-
{{ states('sensor.active_sleeper_rooms') | wordcount }}
- name: "active_chromecast_rooms"
unique_id: "active_chromecast_rooms"
state: >-
{% set ns = namespace(mediaactiverooms = []) %} {# create a namespace object to store variables #}
{% for media_player in states.media_player -%}
{%- if "plex" not in media_player.entity_id and "chromecast" in media_player.entity_id and "universal" not in media_player.entity_id and "template" not in media_player.entity_id and "roku" not in media_player.entity_id and "speaker" not in media_player.entity_id and "display" not in media_player.entity_id -%}
{%- if media_player.state == 'playing' -%}
{% set currentroomname = media_player.entity_id | replace('media_player.','') | replace('chromecast.','') %}
{%- set ns.mediaactiverooms = ns.mediaactiverooms + [currentroomname.split('_') | first] -%}
{%- endif -%}
{%- endif -%}
{% endfor %}
{{ ns.mediaactiverooms | unique | list}}
- name: "active_speakers_rooms"
unique_id: "active_speakers_rooms"
state: >-
{% set ns = namespace(mediaactiverooms = []) %} {# create a namespace object to store variables #}
{% for media_player in states.media_player -%}
{%- if "plex" not in media_player.entity_id and "speaker" in media_player.entity_id and "universal" not in media_player.entity_id and "template" not in media_player.entity_id and "roku" not in media_player.entity_id and "chromecast" not in media_player.entity_id and "group" not in media_player.entity_id and "display" not in media_player.entity_id -%}
{%- if media_player.state == 'playing' -%}
{% set currentroomname = media_player.entity_id | replace('media_player.','') | replace('speaker.','') %}
{%- set ns.mediaactiverooms = ns.mediaactiverooms + [currentroomname.split('_') | first] -%}
{%- endif -%}
{%- endif -%}
{% endfor %}
{{ ns.mediaactiverooms | unique | list}}
- name: "active_motion"
unique_id: "active_motion"
state: >-
{% set ns = namespace(mediaactiverooms = []) %} {# create a namespace object to store variables #}
{% for motion_sensor in states.binary_sensor -%}
{%- if "occupancy" in motion_sensor.entity_id -%}
{%- if motion_sensor.state == 'on' -%}
{% set currentroomname = motion_sensor.entity_id | replace('binary_sensor.','') | replace('sensor_','') | replace('fp2_','') | replace('_motion_occupancy.','') %}
{%- set ns.mediaactiverooms = ns.mediaactiverooms + [currentroomname.split('_') | first] -%}
{%- endif -%}
{%- endif -%}
{% endfor %}
{% if ns.mediaactiverooms | list | length > 0 %}
on
{% else %}
off
{%endif%}
attributes:
rooms: >-
{% set ns = namespace(mediaactiverooms = []) %} {# create a namespace object to store variables #}
{% for motion_sensor in states.binary_sensor -%}
{%- if "occupancy" in motion_sensor.entity_id -%}
{%- if motion_sensor.state == 'on' -%}
{% set currentroomname = motion_sensor.entity_id | replace('binary_sensor.','') | replace('sensor_','') | replace('fp2_','') | replace('_motion_occupancy.','') %}
{%- set ns.mediaactiverooms = ns.mediaactiverooms + [currentroomname.split('_') | first] -%}
{%- endif -%}
{%- endif -%}
{% endfor %}
{{ ns.mediaactiverooms | unique | list}}
- name: "active_media_playback"
unique_id: "active_media_playback"
state: >-
{% set ns = namespace(mediaactiverooms = []) %} {# create a namespace object to store variables #}
{% for media_player in states.media_player -%}
{%- if "plex" not in media_player.entity_id and ( "chromecast" in media_player.entity_id or "speaker" in media_player.entity_id ) and "universal" not in media_player.entity_id and "template" not in media_player.entity_id and "roku" not in media_player.entity_id and "display" not in media_player.entity_id -%}
{%- if media_player.state == 'playing' -%}
{% set currentroomname = media_player.entity_id | replace('media_player.','') | replace('chromecast.','') %}
{%- set ns.mediaactiverooms = ns.mediaactiverooms + [currentroomname.split('_') | first] -%}
{%- endif -%}
{%- endif -%}
{% endfor %}
{% if ns.mediaactiverooms | list | length > 0 %}
on
{% else %}
off
{%endif%}
attributes:
speakers: >-
{% set ns = namespace(mediaactiverooms = []) %} {# create a namespace object to store variables #}
{% for media_player in states.media_player -%}
{%- if "plex" not in media_player.entity_id and "speaker" in media_player.entity_id and "universal" not in media_player.entity_id and "template" not in media_player.entity_id and "roku" not in media_player.entity_id and "chromecast" not in media_player.entity_id and "group" not in media_player.entity_id and "display" not in media_player.entity_id -%}
{%- if media_player.state == 'playing' -%}
{% set currentroomname = media_player.entity_id | replace('media_player.','') | replace('speaker.','') %}
{%- set ns.mediaactiverooms = ns.mediaactiverooms + [currentroomname.split('_') | first] -%}
{%- endif -%}
{%- endif -%}
{% endfor %}
{{ ns.mediaactiverooms | unique | list}}
chromecasts: >-
{% set ns = namespace(mediaactiverooms = []) %} {# create a namespace object to store variables #}
{% for media_player in states.media_player -%}
{%- if "plex" not in media_player.entity_id and "chromecast" in media_player.entity_id and "universal" not in media_player.entity_id and "template" not in media_player.entity_id and "roku" not in media_player.entity_id and "speaker" not in media_player.entity_id and "display" not in media_player.entity_id -%}
{%- if media_player.state == 'playing' -%}
{% set currentroomname = media_player.entity_id | replace('media_player.','') | replace('chromecast.','') %}
{%- set ns.mediaactiverooms = ns.mediaactiverooms + [currentroomname.split('_') | first] -%}
{%- endif -%}
{%- endif -%}
{% endfor %}
{{ ns.mediaactiverooms | unique | list}}
- name: Is maxi asleep?
unique_id: "is_maxi_asleep"
state: >
{% set room = states.sensor.maxi_location.state %} {# get the current maxi location sensor state #}
{% set sleeperamount = states('sensor.active_sleeper_amount') | int %}
{% set activesleeperrooms = states('sensor.active_sleeper_rooms') %}
{% set lasttvactiveroom = states('sensor.last_active_room') %}
{% set phone_sleep_confidence = states('sensor.phone_fold4_sleep_confidence') | int %}
{% set sleepingstate = "awake" %}
{% if sleeperamount > 0 %}
{% if states.binary_sensor.maxi_alone.state == "on" %}
{# if the maxi_alone sensor is on, indicating there is only maxi present #}
{% if sleeperamount > 1 %}
{# if there is more than one "sleeper" input_boolean that is "on" #}
{% if room in activesleeperrooms %}
{% set sleepingstate = "asleep" %}
{% elif lasttvactiveroom in activesleeperrooms %}
{% set sleepingstate = "asleep" %}
{% endif %}
{% elif sleeperamount == 1 %}
{# if there is only one "sleeper" input_boolean that is "on" #}
{% set sleepingstate = "asleep" %} {# set the roomname to the only "sleeper" input_boolean that is "on" #}
{% endif %}
{% elif states.binary_sensor.maxi_alone.state == "off" and room in activesleeperrooms %}
{# if the maxi_alone sensor is off, it indicates that there is more than maxi present #}
{% set sleepingstate = "asleep" %}
{% elif states.person.maximiliano.state == "not_home" %} {# if maxi is not home #}
{# check phone sleep confidence to determine if I am sleeping #}
{% if phone_sleep_confidence > 94 and room != "not_home" %}
{# Assume I am sleeping if confidence is over 94% #}
{% set sleepingstate = "asleep" %} {# set sleeping state as asleep #}
{% endif %}
{% endif %}
{% else %}
{% set sleepingstate = "awake" %}
{% endif %}
{{ sleepingstate }}
attributes:
location: >
{% set room = states.sensor.maxi_location.state %} {# get the current maxi location sensor state #}
{% set sleeperamount = states('sensor.active_sleeper_amount') | int %}
{% set activesleeperrooms = states('sensor.active_sleeper_rooms') %}
{% set lasttvactiveroom = states('sensor.last_active_room') %}
{% set phone_sleep_confidence = states('sensor.phone_fold4_sleep_confidence') | int %}
{% set sleepingspot = "" %}
{% if sleeperamount > 0 %}
{% if states.binary_sensor.maxi_alone.state == "on" %} {# if the maxi_alone sensor is on, indicating there is only maxi present #}
{% if sleeperamount > 1 %} {# if there is more than one "sleeper" input_boolean that is "on" #}
{% if room in activesleeperrooms %}
{% set sleepingspot = room %}
{% elif lasttvactiveroom in activesleeperrooms %}
{% set sleepingspot = lasttvactiveroom %}
{% else %}
{# this below code set sleepingspots as the last sleeper that eas turned on#}
{% set sleepingspot = states.input_boolean | selectattr('state','eq','on') | selectattr('entity_id','search',"input_boolean.sleeper_") | sort(attribute='last_updated', reverse=True) | map(attribute="entity_id") | first | default | replace("input_boolean.sleeper_in_","") %}
{% endif %}
{% elif sleeperamount == 1 %} {# if there is only one "sleeper" input_boolean that is "on" #}
{% set sleepingspot = states.sensor.active_sleepers.attributes.rooms.1%} {# set the roomname to the only "sleeper" input_boolean that is "on" #}
{% endif %}
{% elif states.binary_sensor.maxi_alone.state == "off" %} {# if the maxi_alone sensor is off, it indicates that there is more than maxi present #}
{# this below code set sleepingspots as the last sleeper that was turned on#}
{% set sleepingspot = states.input_boolean | selectattr('state','eq','on') | selectattr('entity_id','search',"input_boolean.sleeper_") | sort(attribute='last_updated', reverse=True) | map(attribute="entity_id") | first | default | replace("input_boolean.sleeper_in_","") %}
{% elif states.person.maximiliano.state == "not_home" %} {# if maxi is not home #}
{# check phone sleep confidence to determine if I am sleeping #}
{% if phone_sleep_confidence > 94 and room != "not_home" %} {# Assume I am sleeping if confidence is over 94% #}
{% set sleepingspot = room %} {# set sleeping spot at current outside of home location #}
{% endif %}
{% endif %}
{% else %}
{% endif %}
{{ sleepingspot }}
- name: "Where is maxi sleeping?"
unique_id: maxi_sleeping_spot
state: >-
{{ state_attr('sensor.is_maxi_asleep', "location") }}
- name: "Maxi current Activity"
unique_id: maxi_current_activity
state: >-
{% set ns = namespace( activityname="unsure", mediaactiverooms=[],lasttvactiveroom = states('sensor.last_active_room'), active_sleepers_amount=0, allowed_ids=[],active_sleeper_rooms=[], motion_sensors=[], room = states.sensor.maxi_location.state, active_motion_sensors = [] ) %} {# create a namespace object to store variables #}
{% set room = states('sensor.maxi_location') %}
{% set partnershome = states('sensor.amount_partners_home') | int %}
{% set friendshome = states('sensor.amount_friends_home') | int %} {# Set friendshome to the amount of people #}
{% set peoplehome = states('sensor.amount_people_home') | int %}{# Set peoplehome to the amount of people #}
{% set ns.active_sleepers_amount = states('sensor.active_sleeper_amount') | int %}
{% set ns.active_chromecasts_room = state_attr('sensor.active_media_playback', 'chromecasts') %}
{% if states.binary_sensor.maxi_alone.state == "on" %} {# if the maxi_alone sensor is on, indicating there is only maxi present #}
{# Set the activity as gaming if a game is launched #}
{% if states('sensor.is_maxi_asleep') == "asleep" %}
{% set ns.activityname = "Sleeping" %}
{% elif states('sensor.currentgamemaxi') != "idle" %}
{% set ns.activityname = "Playing a video game" %}
{% elif room == "office" and states('sensor.maxi1134_8202') != "idle" %}
{% set ns.activityname = "Using the computer" %}
{% elif ns.activityname == "unsure" %}
{% if ns.active_chromecasts_room | length > 0 %}
{# Check if I am in a room with mediaplayback #}
{% for activeroom in ns.active_chromecasts_room %}
{% if ns.room in activeroom %}
{% set ns.activityname = "Watching TV in the " + room %}
{% endif %}
{% endfor %}
{% if ns.activityname == "unsure" %}
{% set ns.activityname = "Watching TV in the " + ns.lasttvactiveroom %}
{% endif %}
{% endif %}
{% endif %}
{% elif states.binary_sensor.maxi_alone.state == "off" %} {# if the maxi_alone sensor is off, it indicates that there is more than maxi present #}
{% if friendshome == 0 and partnershome > 0 %} {# If mor than one user is home, and no guest are there. #}
{# Need to greatly expand this to know what we are doing #}
{% if states('sensor.is_maxi_asleep') == "asleep"%} {# if maxi is sleeping #}
{% set ns.activityname = "Sleeping" %}
{% elif ns.active_sleepers_amount < partnershome and states('sensor.is_maxi_asleep') == "awake" %} {# Trigger if less people are asleep than are present and that is not maxi #}
{% if room in ns.active_chromecasts_room %}
{% set ns.activityname = "Watching TV with girls in the " + room %}
{% elif states('zone.home') == 2 and states('person.alexe') == home and room == "closet" and states('input_boolean.sleeper_in_closet') == "off" %}
{% set ns.activityname = "Playtime" %}
{% elif states('zone.home') == 2 and states('person.myriam') == home and room == "closet" and states('input_boolean.sleeper_in_closet') == "off" %}
{% set ns.activityname = "Playtime" %} {% else %}
{% set ns.activityname = "With girls in the " + room %}
{% endif %}
{% elif ns.active_sleepers_amount >= partnershome and states('sensor.is_maxi_asleep') == "awake" %} {# if more sleepers than users and maxi is awake#}
{% if states('sensor.currentgamemaxi') != "idle" %}
{% set ns.activityname = "Playing " + states('sensor.currentgamemaxi') %}
{% elif room == "office" and states('sensor.maxi1134_8202') != "idle" %}
{% set ns.activityname = "Using the computer" %}
{% elif room in ns.active_chromecasts_room %}
{% set ns.activityname = "Watching TV in the " + room %}
{% else %}
{% set ns.activityname = "todetermine" %}
{% endif %}
{% endif %}
{% elif friendshome > 0 %} {# if we have more people over than users #}{# assume a chilling #}
{% set ns.activityname = "Chilling" %}
{% else %}
{% endif %}
{% else %}
EDGECASE
{% endif %}
{{ns.activityname }}
- name: "plex token"
unique_id: plex_token
state: !secret plex_token
- name: "Maxi Location v3"
unique_id: maxi_location_v3
state: >-
{% set braceletroom = states('sensor.b7bracelet1') %}
{% set watchroom = states('sensor.watch_galaxy4') %}
{% set watchonbody = states('binary_sensor.galaxy_watch_4_on_body_sensor') %}
{% set phoneroom = states('sensor.phone_fold4') %}
{% set gpslocation = states('device_tracker.phone_galaxy_fold_4') %}
{% set lastactiveroom = states('sensor.last_active_room') %}
{% set maxialone = states('binary_sensor.maxi_alone') %}
{% if maxialone == "off" %}
{% if watchonbody == "on" and watchroom != "not_home" %}
{% set location = watchroom %}
{% elif braceletroom != "not_home" %}
{% set location = braceletroom %}
{% elif phoneroom != "not_home" %}
{% set location = phoneroom %}
{% elif gpslocation != "not_home"%}
{% set location = "At " + gpslocation %}
{% else %}
{% set location = unkown %}
{% endif %}
{% else %}
{% set location = lastactiveroom %}
{% endif %}
{{ location }}