-
Notifications
You must be signed in to change notification settings - Fork 30
/
scripts.yaml
538 lines (523 loc) · 19.9 KB
/
scripts.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
broadcast_alert_in_the_house:
alias: important broadcast alert in the house
sequence:
- variables:
light_entity_ids: "{% set light_group = state_attr('light.group_notifications_light','entity_id')%}
\ {% set ns = namespace( rgb_dict= [] ) %} {% for entity_id in light_group
%}\n {% set light_state = states(entity_id) %}\n {% set light_rgb_color
= state_attr(entity_id, \"rgb_color\") %}\n {% if light_state != 'unavailable'
and light_rgb_color %}\n {%- set rgb_values = light_rgb_color | replace('(','')
| replace(')','')| replace(' ','')| string -%}\n {% set rgb_dict =
[(entity_id , rgb_values, states(entity_id))] %}\n {% set ns.rgb_dict
= ns.rgb_dict + rgb_dict %}\n {% elif light_state != 'unavailable' %}\n
\ {%- set rgb_values = \"0,0,0\" %}\n {% set rgb_dict = [(entity_id
, rgb_values, states(entity_id))] %}\n {% set ns.rgb_dict = ns.rgb_dict
+ rgb_dict %}\n {% endif %} \n{% endfor %} {{ ns.rgb_dict }}\n"
alias: 'Store Lights entity_id and current rgb values '
- variables:
playing_chromecasts: "{% set ns = namespace(active_chromecasts = []) %} {#
create a namespace object to store variables #} {% for media_player in states.media_player
-%} \n {%- if \"universal\" in media_player.entity_id and \"chromecast\"
in media_player.entity_id and \"speaker\" not in media_player.entity_id and
\"display\" not in media_player.entity_id -%} \n {%- if media_player.state
== 'playing' -%}\n {% set current_chromecast = media_player.entity_id %}\n
\ {%- set ns.active_chromecasts = ns.active_chromecasts + [current_chromecast]
-%} \n {%- endif -%}\n {%- endif -%}\n{% endfor %} {{ ns.active_chromecasts
| unique | list}}\n"
non_playing_chromecasts: "{% set ns = namespace(active_chromecasts = []) %}
\ {# create a namespace object to store variables #} {% for media_player in
states.media_player -%} \n {%- if \"universal\" in media_player.entity_id
and \"chromecast\" in media_player.entity_id and \"speaker\" not in media_player.entity_id
and \"display\" not in media_player.entity_id -%} \n {%- if media_player.state
!= 'playing' -%}\n {% set current_chromecast = media_player.entity_id %}\n
\ {%- set ns.active_chromecasts = ns.active_chromecasts + [current_chromecast]
-%} \n {%- endif -%}\n {%- endif -%}\n{% endfor %} {{ ns.active_chromecasts
| unique | list}}\n"
alias: Store Chromecasts in variables
- alias: Run Alerts
parallel:
- alias: Pause Playing Chromecasts
repeat:
sequence:
- service: media_player.media_pause
metadata: {}
data: {}
target:
entity_id: '{{playing_chromecasts[repeat.index - 1]}}'
for_each: '{{ playing_chromecasts }}'
enabled: false
- service: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.mass_home_group
message: '{{ message }}'
target:
entity_id: tts.piper
alias: TTS in the home group
- alias: Broadcast image to paused TVs if image is present
if:
- condition: template
value_template: '{% if image %}
true
{% else %}
false
{% endif %}'
then:
- alias: Broadcast Image to paused chromecasts
repeat:
sequence:
- service: media_player.play_media
metadata: {}
data:
media_content_id: '{{image}}'
media_content_type: video
entity_id: '{{non_playing_chromecasts[repeat.index - 1]}}'
for_each: '{{ non_playing_chromecasts }}'
enabled: false
- service: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.mass_closet_wiim_speaker
message: '{{ message }}'
target:
entity_id: tts.piper
alias: TTS in the closet
- service: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.bedroom_speaker
message: '{{ message }}'
target:
entity_id: tts.piper
alias: TTS in the bedroom
- service: rest_command.willow_notify
metadata: {}
data:
text: Someone is at the door!
backlight: true
backlightMax: false
repeat: 1
volume: 100
enabled: false
- if:
- condition: template
value_template: '{% if color %}
true
{% else %}
false
{% endif %}'
then:
- alias: Turn all lights to selected color
repeat:
sequence:
- service: light.turn_on
target:
entity_id: '{{light_entity_ids[repeat.index].0}}'
data:
color_name: '{{color}}'
enabled: true
count: '{{ light_entity_ids | length - 1 }}'
- alias: Restore lights to their initial state
repeat:
sequence:
- if:
- condition: template
value_template: '{{ not light_entity_ids[repeat.index].2 | bool }}'
then:
- service: light.turn_{{ light_entity_ids[repeat.index].2 }}
target:
entity_id: '{{light_entity_ids[repeat.index].0}}'
enabled: true
alias: Turn back off lights to previous state
alias: Turn off lights back to off
- if:
- condition: template
value_template: '{{ light_entity_ids[repeat.index].2 | bool }}'
then:
- service: light.turn_{{ light_entity_ids[repeat.index].2 }}
target:
entity_id: '{{light_entity_ids[repeat.index].0}}'
data:
rgb_color: '{{light_entity_ids[repeat.index].1}}'
enabled: true
alias: Turn back on lights to previous state
alias: Turn on lights back to their original colors
count: '{{ light_entity_ids | length - 1 }}'
mode: queued
icon: mdi:speaker-message
max: 3
change_received_lights_to_random_colors:
alias: Change received lights to random color
sequence:
- repeat:
sequence:
- service: light.turn_on
metadata: {}
data:
hs_color: '{{ range(1, 360) | random | string + '','' + saturation | string
}}'
target:
entity_id: '{{lights[repeat.index - 1]}}'
for_each: '{{ lights }}'
mode: restart
icon: mdi:sale
fields: {}
start_visual_playlist_on_plex:
alias: Start requsted Playlist on plex for all unplaying chromecasts
sequence:
- variables:
chromecasts: '{{integration_entities(''cast'') | select(''search'', ''chromecast'')
| list}}
'
- repeat:
sequence:
- if:
- condition: template
value_template: '{{states(chromecasts[repeat.index ]) == "off"}}'
then:
- variables:
playlist: 'plex://{"playlist_name":"{{requested_playlist}}","shuffle":"1"}
'
- service: media_player.play_media
data:
media_content_id: '{{playlist}}'
media_content_type: playlist
target:
entity_id: '{{chromecasts[repeat.index]}}'
- delay:
hours: 0
minutes: 0
seconds: 15
milliseconds: 0
for_each: '{{ chromecasts }}'
mode: single
icon: mdi:led-strip-variant
'1714666287611':
alias: non-important broadcast alert in the house
sequence:
- variables:
on_light_entity_ids: "{% set light_group = state_attr('light.group_notifications_light','entity_id')%}
\ {% set ns = namespace( rgb_dict= [] ) %} {% for entity_id in light_group
%}\n {% set light_state = states(entity_id) %}\n {% set light_rgb_color
= state_attr(entity_id, \"rgb_color\") %}\n {% if light_state == 'on' and
light_rgb_color %}\n {%- set rgb_values = light_rgb_color | replace('(','')
| replace(')','')| replace(' ','')| string -%}\n {% set rgb_dict =
[(entity_id , rgb_values, states(entity_id))] %}\n {% set ns.rgb_dict
= ns.rgb_dict + rgb_dict %}\n {% endif %} \n{% endfor %} {{ ns.rgb_dict
}}\n"
alias: 'Store Lights entity_id and current rgb values '
- alias: Run Alerts
parallel:
- service: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.mass_closet_wiim_speaker
message: '{{ message }}'
target:
entity_id: tts.piper
alias: TTS in the closet
- service: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.mass_home_group
message: '{{ message }}'
target:
entity_id: tts.piper
alias: TTS in the home group
- service: tts.speak
metadata: {}
data:
cache: true
media_player_entity_id: media_player.bedroom_speaker
message: '{{ message }}'
target:
entity_id: tts.piper
alias: TTS in the bedroom
- if:
- condition: template
value_template: '{% if color %}
true
{% else %}
false
{% endif %}'
then:
- alias: Turn all lights to selected color
repeat:
sequence:
- service: light.turn_on
target:
entity_id: '{{on_light_entity_ids[repeat.index].0}}'
data:
color_name: '{{color}}'
enabled: true
count: '{{ on_light_entity_ids | length - 1 }}'
- alias: Restore lights to their initial state
repeat:
sequence:
- if:
- condition: template
value_template: '{{ not on_light_entity_ids[repeat.index].2 | bool }}'
then:
- service: light.turn_{{ light_entity_ids[repeat.index].2 }}
target:
entity_id: '{{on_light_entity_ids[repeat.index].0}}'
enabled: true
alias: Turn back off lights to previous state
alias: Turn off lights back to off
- if:
- condition: template
value_template: '{{ on_light_entity_ids[repeat.index].2 | bool }}'
then:
- service: light.turn_{{ light_entity_ids[repeat.index].2 }}
target:
entity_id: '{{on_light_entity_ids[repeat.index].0}}'
data:
rgb_color: '{{on_light_entity_ids[repeat.index].1}}'
enabled: true
alias: Turn back on lights to previous state
alias: Turn on lights back to their original colors
count: '{{ on_light_entity_ids | length - 1 }}'
mode: queued
icon: mdi:speaker-message
max: 3
changes_all_on:
alias: Changes all on lights to random colors
sequence:
- variables:
on_lights: "{% set ns = namespace(lights=[]) %} {% set groups = integration_entities('group')|
\ select('search', '^light.') | list %} {% for group in groups %}\n {%
set individual_lights = state_attr(group,'entity_id')%}\n {% for individual_light
in individual_lights %}\n {% if \"group\" not in individual_light and
state_attr(individual_light, 'rgb_color') and states(individual_light) ==
'on' %}\n {% set ns.lights = ns.lights + [individual_light] %}\n {%
endif %}\n {% endfor %} \n{% endfor %} {{ ns.lights }}\n"
- repeat:
sequence:
- service: light.turn_on
metadata: {}
data:
hs_color: '{{ range(1, 360) | random | string + '','' + 100 | string }}'
target:
entity_id: '{{on_lights[repeat.index - 1]}}'
for_each: '{{ on_lights }}'
mode: restart
icon: mdi:sale
fields: {}
'1714667687332':
alias: Changes all on lights to random pastel colors
sequence:
- variables:
on_lights: "{% set ns = namespace(lights=[]) %} {% set groups = integration_entities('group')|
\ select('search', '^light.') | list %} {% for group in groups %}\n {%
set individual_lights = state_attr(group,'entity_id')%}\n {% for individual_light
in individual_lights %}\n {% if \"group\" not in individual_light and
state_attr(individual_light, 'rgb_color') and states(individual_light) ==
'on' %}\n {% set ns.lights = ns.lights + [individual_light] %}\n {%
endif %}\n {% endfor %} \n{% endfor %} {{ ns.lights }}\n"
- repeat:
sequence:
- service: light.turn_on
metadata: {}
data:
hs_color: '{{ range(1, 360) | random | string + '','' + 30 | string }}'
target:
entity_id: '{{on_lights[repeat.index - 1]}}'
for_each: '{{ on_lights }}'
mode: restart
icon: mdi:sale
fields: {}
generate_and_save_localai_image:
alias: Generate and save LocalAI image
sequence:
- service: rest_command.local_ai_generate_image
metadata: {}
data:
prompt: '{{prompt}}'
model: '{{model}}'
size: '{{size}}'
steps: '{{steps}}'
response_variable: return
- service: downloader.download_file
metadata: {}
data:
overwrite: true
url: '{{return.content.data[0].url}}'
filename: stable_diffusion.jpg
mode: single
icon: mdi:image-frame
generate_and_save_sd_image:
alias: Generate and save SD image
sequence:
- service: rest_command.stability_ai_get_session_id
metadata: {}
data: {}
response_variable: return
- service: downloader.download_file
metadata: {}
data:
overwrite: true
url: '{{return.content.data[0].url}}'
filename: stable_diffusion.jpg
mode: single
icon: mdi:image-frame
changes_all_on_lights_to_warm_colors:
alias: Changes all on lights to warm colors
sequence:
- variables:
on_lights: "{% set ns = namespace(lights=[]) %} {% set groups = integration_entities('group')|
\ select('search', '^light.') | list %} {% for group in groups %}\n {%
set individual_lights = state_attr(group,'entity_id')%}\n {% for individual_light
in individual_lights %}\n {% if \"group\" not in individual_light and
state_attr(individual_light, 'rgb_color') and states(individual_light) ==
'on' %}\n {% set ns.lights = ns.lights + [individual_light] %}\n {%
endif %}\n {% endfor %} \n{% endfor %} {{ ns.lights }}\n"
- repeat:
sequence:
- service: light.turn_on
metadata: {}
data:
hs_color: "{% set hue_under_20 = range(1, 20) | random | string + ',' +
100 | string %} {% set hue_over_260 = range(260, 360) | random | string
+ ',' + 100 | string %} {% set random = range(1, 3) | random %} {%
if random == 1 %}\n {{hue_under_20 }}\n{% elif random > 1 %} {{hue_over_260}}
{%endif%}\n"
target:
entity_id: '{{on_lights[repeat.index - 1]}}'
for_each: '{{ on_lights }}'
mode: restart
icon: mdi:sale
fields: {}
'1716330781093':
alias: Changes all on lights to warm pale colors
sequence:
- variables:
on_lights: "{% set ns = namespace(lights=[]) %} {% set groups = integration_entities('group')|
\ select('search', '^light.') | list %} {% for group in groups %}\n {%
set individual_lights = state_attr(group,'entity_id')%}\n {% for individual_light
in individual_lights %}\n {% if \"group\" not in individual_light and
state_attr(individual_light, 'rgb_color') and states(individual_light) ==
'on' %}\n {% set ns.lights = ns.lights + [individual_light] %}\n {%
endif %}\n {% endfor %} \n{% endfor %} {{ ns.lights }}\n"
- repeat:
sequence:
- service: light.turn_on
metadata: {}
data:
hs_color: "{% set hue_under_20 = range(1, 20) | random | string + ',' +
30 | string %} {% set hue_over_260 = range(260, 360) | random | string
+ ',' + 30 | string %} {% set random = range(1, 3) | random %} {%
if random == 1 %}\n {{hue_under_20 }}\n{% elif random > 1 %} {{hue_over_260}}
{%endif%}\n"
target:
entity_id: '{{on_lights[repeat.index - 1]}}'
for_each: '{{ on_lights }}'
mode: restart
icon: mdi:sale
fields: {}
generate_fake_white_colors:
alias: Generate fake white colors
sequence:
- variables:
on_lights: "{% set ns = namespace(lights=[]) %} {% set groups = integration_entities('group')|
\ select('search', '^light.') | list %} {% for group in groups %}\n {%
set individual_lights = state_attr(group,'entity_id')%}\n {% for individual_light
in individual_lights %}\n {% if \"group\" not in individual_light and
state_attr(individual_light, 'rgb_color') and states(individual_light) ==
'on' %}\n {% set ns.lights = ns.lights + [individual_light] %}\n {%
endif %}\n {% endfor %} \n{% endfor %} {{ ns.lights }}\n"
- repeat:
sequence:
- service: light.turn_on
metadata: {}
data:
hs_color: "{% set hue_under_20 = range(1, 20) | random | string + ',' +
30 | string %} {% set hue_over_260 = range(260, 360) | random | string
+ ',' + 30 | string %} {% set random = range(1, 3) | random %} {%
if random == 1 %}\n {{hue_under_20 }}\n{% elif random > 1 %} {{hue_over_260}}
{%endif%}\n"
target:
entity_id: '{{on_lights[repeat.index - 1]}}'
for_each: '{{ on_lights }}'
mode: restart
icon: mdi:sale
fields: {}
in_home_defense_script:
alias: In Home defense script
sequence:
- service: switch.turn_on
metadata: {}
data: {}
target:
entity_id: switch.group_fosi_receivers
- service: media_player.play_media
target:
entity_id: media_player.mass_home_group
data:
media_content_id: https://hass.purgatoire.ca/local/civil-defense-siren.wav
media_content_type: music
- service: media_player.volume_set
metadata: {}
data:
volume_level: 1
target:
entity_id: media_player.group_home_speakers
- wait_for_trigger:
- platform: state
entity_id:
- binary_sensor.motion_home
to: 'off'
from: 'on'
for:
hours: 0
minutes: 5
seconds: 0
timeout:
hours: 0
minutes: 15
seconds: 0
milliseconds: 0
- service: media_player.media_stop
metadata: {}
data: {}
target:
entity_id: media_player.group_home_speakers
mode: restart
changes_all_on_lights_to_fake_white:
alias: Changes all on lights to fake white
sequence:
- variables:
light_groups: '{% set groups = integration_entities(''group'')| select(''search'',
''^light.(?!.*?all.*?)(?!.*?notifications.*?)(?!.*?bedroom.*?)(?!.*?bathroom.*?)'') |
list %} {{groups}}
'
- repeat:
sequence:
- variables:
on_lights: "{% set ns = namespace(h=(range(0, 360) | random),\n s=100,
group_colors=[]) %} \n\n {% for group in light_groups %}\n {% set
entity_ids = state_attr(group,'entity_id') %}\n {% set num_colors
= entity_ids | length %}\n {% set ns.complementary_colors = [] %}\n\n
\ {% for i in range(num_colors) %}\n {% set ns.h = (ns.h + (360
/ num_colors)) | int %}\n {% if ns.h >= 360 %}\n {% set
ns.h = ns.h - 360 %}\n {% endif %}\n {% set ns.complementary_colors
= ns.complementary_colors + [{'entity_id': entity_ids[i], 'hs_color':
[ns.h, ns.s]}] %}\n {% endfor %}\n \n {% set ns.group_colors
= ns.group_colors + [ns.complementary_colors] %}\n {% endfor %}\n\n
\ {{ ns.group_colors }}\n"
- repeat:
sequence:
- service: light.turn_on
data:
hs_color: '{{ repeat.item[0].hs_color }}'
target:
entity_id: '{{ repeat.item[0].entity_id }}'
for_each: '{{ on_lights }}'
for_each: '{{ light_groups }}'
mode: restart
icon: mdi:sale
fields: {}