/
auto_update_scheduled.yaml
992 lines (915 loc) · 40.2 KB
/
auto_update_scheduled.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
blueprint:
name: Home Assistant Auto-update on a schedule base
author: Edward Firmo (https://github.com/edwardtfn)
homeassistant:
min_version: '2023.3.0'
description: >
# Home Assistant Auto-update
Update Home Assistant automatically when a new update is available.
Attention:
* HACS updates NOT included. It may work if you enable "[Experimental features](https://hacs.xyz/docs/configuration/options/#options)" on your HACS integration or when HACS updates funcionality is released.
* Home Assistant may restart automatically as part of the update process.
* **Use under your own risk!** Please see the discussions on Home Assistant community around the risks involved on auto-updating the system.
For questions and suggestions, please use [this thread in Home Assistant Community portal](https://community.home-assistant.io/t/scheduled-auto-update-for-home-assistant/459281).
domain: automation
source_url: https://raw.githubusercontent.com/edwardtfn/HomeAssistant-Config/main/blueprints/automation/EdwardTFN/auto_update_scheduled.yaml
input:
verbose_logging_bool:
name: Log addon progress with verbosity to the logbook?
default: false
selector:
boolean: {}
backup_bool:
name: Create a full backup before start the updates?
#description: Note => This automation will skip the backup if another backup was completed in the last two hours before starting the updates.
default: true
selector:
boolean:
max_backup_age:
name: Maximum backup age (or zero, to disable)
description:
This requires the [Google Drive Backup](https://github.com/sabeechen/hassio-google-drive-backup)
addon to be installed and configured to automatically backup, and provide
a sensor with the backup states. The setting only checks for the age of
the automatic backups from that addon, not the backups created internally
by this blueprint.
default:
days: 0
hours: 0
minutes: 0
seconds: 0
selector:
duration:
enable_day: true
restart_type:
name: Force Home Assistant to restart if required by any update?
description: This won't affect updates where a restart is automatic, but for updates requiring a manual restart (quite common on HACS) this blueprint can automatically force a restart by the end of the updates.
default: "no-restart"
selector:
select:
multiple: false
options:
- label: "Don't force a restart"
value: "no-restart"
- label: "Restart Home Assistant core"
value: "core"
- label: "Restart Home Assistant host"
value: "host"
schedule_entity:
name: Schedule entity
description: 'You can create an [Schedule](https://www.home-assistant.io/integrations/schedule) under [Settings > Devices & Services > Helpers](https://my.home-assistant.io/redirect/config_flow_start/?domain=schedule).
Note => The schedule windows will define when an update will start. It is possible that a backup, an update or a restart process finishes after the schedule window, but new updates won''t stars outside the schedule windows.'
default: []
selector:
entity:
multiple: false
domain: schedule
schedule_monthday:
name: Earliest day in the month to update Home Assistant
description: >
Usually a new major version of Home Assistant is available on the begining of every month.
Some people consider those releases as not stable enough and prefer to avoid those versions, not updating the system until the mid of the month (day 15).
Note => If you select a day higher than 28 the updates won't run every month.
default: 1
selector:
number:
min: 1
max: 31
step: 1
mode: slider
core_os_update_mode:
name: Update mode for Home Assistant core and OS updates
description: >
Please select the update mode for Home Assistant core and Home Assistan OS updates.
* All: All updates will be installed.
* Patches only:
✅ From 2022.11.0 to 2022.11.3 will be updated (patches).
❌ From 2022.11.x to 2022.12.x will be ignored (minor update).
❌ From 2022.12.x to 2023.1.x will be ignored (major update).
* Don't update: Ignore any update.
# * Major & minor only:
# ❌ From 2022.11.0 to 2022.11.3 will be ignored (patches).
# ✅ From 2022.11.x to 2022.12.x will be updated (minor update).
# ✅ From 2022.12.x to 2023.1.x will be updated (major update).
default: "all"
selector:
select:
multiple: false
options:
- label: All
value: "all"
- label: Patches only
value: "patches"
- label: Don't update
value: "ignore"
# - label: Major & minor updates only
# value: "major_and_minor"
firmware_update_mode:
name: Update mode for device's firmware
description: >
Please select the update mode for firmware in the devices connected to Home Assistant (when supported as an HA update).
* All: All updates will be installed.
* Patches only:
✅ From 2022.11.0 to 2022.11.3 will be updated (patches).
❌ From 2022.11.x to 2022.12.x will be ignored (minor update).
❌ From 2022.12.x to 2023.1.x will be ignored (major update).
* Don't update: Ignore any update.
# * Major & minor only:
# ❌ From 2022.11.0 to 2022.11.3 will be ignored (patches).
# ✅ From 2022.11.x to 2022.12.x will be updated (minor update).
# ✅ From 2022.12.x to 2023.1.x will be updated (major update).
default: "all"
selector:
select:
multiple: false
options:
- label: All
value: "all"
- label: Patches only
value: "patches"
- label: Don't update
value: "ignore"
# - label: Major & minor updates only
# value: "major_and_minor"
general_update_mode:
name: Update mode for general updates
description: >
Please select the update mode for everything that is not a device's firmware or a core component of Home Assistant.
This includes add-ons, HACS componentes, custom cards, etc.
* All: All updates will be installed.
* Patches only:
✅ From 2022.11.0 to 2022.11.3 will be updated (patches).
❌ From 2022.11.x to 2022.12.x will be ignored (minor update).
❌ From 2022.12.x to 2023.1.x will be ignored (major update).
* Don't update: Ignore any update.
# * Major & minor only:
# ❌ From 2022.11.0 to 2022.11.3 will be ignored (patches).
# ✅ From 2022.11.x to 2022.12.x will be updated (minor update).
# ✅ From 2022.12.x to 2023.1.x will be updated (major update).
default: "all"
selector:
select:
multiple: false
options:
- label: All
value: "all"
- label: Patches only
value: "patches"
- label: Don't update
value: "ignore"
# - label: Major & minor updates only
# value: "major_and_minor"
update_exclusions:
name: (optional) Exclusions
description: 'Select the items that should NOT be included on the automated updates.
=> Use this if you want to keep some add-on on an specific version and avoid auto-updates to it.'
default: []
selector:
entity:
multiple: true
domain: update
actions_pre_update:
name: (optional) Pre-update actions
description: 'Actions to execute before the backup or any update starts.
You can use this to send notifications, turn on/off devices or activate scenes before starting the updates.
Note => Please be aware that all actions will run right before the update process, which can happens over-night. Take this in account when selecting your actions.
Note => The variable "\{\{ updates_list \}\}" is available for your actions and contains the list of pending updates.'
default: []
selector:
action: {}
actions_pre_restart:
name: (optional) Pre-restart actions
description: 'Actions to execute before the automation requests a restart.
You can use this to send notifications, turn on/off devices or stopping automations before restarting Home Assistant.
Note => Please be aware that all actions will run right before the restart process, which can happens over-night. Take this in account when selecting your actions.
Note => Note all the restarts will be controlled by this automation, like when a Core update is installed. These actions might not be executed in those cases.
Note => The variable "\{\{ updates_list \}\}" is available for your actions and contains the list of pending updates.'
default: []
selector:
action: {}
actions_pos_update:
name: (optional) Post-update actions
description: >
Actions to execute AFTER the update process finishes.
You can use this to send notifications, turn on/off devices or activate scenes after applying the updates.
Note => Please be aware that all actions will run right after the update process, which can happens over-night.
Take this in account when selecting your actions.
Note => The variable "\{\{ updates_list \}\}" is available for your actions and contains the list of pending updates.
**IMPORTANT** => Some updates will automatically restart Home Assistant, causing the automation to interrupt before finishing, preventing the pos-updates actions to be executed.
If you have critical actions to run after an update, consider including also in another automation based on Home Assistant start.
default: []
selector:
action: {}
pause_entities:
name: (Optional) Pause update entities
description: 'You can select one or more entities to pause the updates. If any of the selected entities is "On" or "True" the system won''t be updated on the schedule time.
You can use this to hold your updates when you have a party at home, or when you are on vacations and don''t want to be concerned about updates on Home Assistant.'
default: []
selector:
entity:
multiple: true
domain:
- input_boolean
- binary_sensor
- switch
mode: single
max_exceeded: warning
trigger_variables:
input_schedule_monthday: !input schedule_monthday
input_pause_entities: !input pause_entities
temp_input_update_exclusions: !input update_exclusions
input_update_exclusions: !input update_exclusions
trigger:
- id: HA Schedule based
platform: state
entity_id: !input schedule_entity
- id: HA Start
platform: homeassistant
event: start
- id: New update
platform: template
value_template: >
{{ states.update | default([]) | selectattr('state','eq','on') | rejectattr('entity_id', 'in', input_update_exclusions) | list | count | int(0) }}
- id: New day
platform: time
at: "00:00:01"
- id: Automations reloaded
platform: event
event_type: automation_reloaded
- id: Pause entities changed
platform: state
entity_id: !input pause_entities
condition:
- condition: template
value_template: >
{{ (states.update | default([]) | selectattr('state','eq','on') | rejectattr('entity_id', 'in', input_update_exclusions) | list | count | int(0)) > 0 }}
- condition: template
value_template: >
{{ now().day >= ((input_schedule_monthday) | int(0)) }}
- condition: state
entity_id: !input schedule_entity
state: "on"
- condition: or
conditions:
- "{{ input_pause_entities | default([]) | list | count | int(0) < 1 }}"
- condition: state
entity_id: !input pause_entities
state: 'off'
variables:
input_verbose_logging_bool: !input verbose_logging_bool
input_backup_bool: !input backup_bool
input_restart_type: !input restart_type
temp_max_backup_age: !input max_backup_age
input_max_backup_age_seconds: >
{{
timedelta(
days=temp_max_backup_age.days,
hours=temp_max_backup_age.hours,
minutes=temp_max_backup_age.minutes,
seconds=temp_max_backup_age.seconds
).total_seconds()
}}
input_schedule_monthday: !input schedule_monthday
input_core_os_update_mode: !input core_os_update_mode
input_firmware_update_mode: !input firmware_update_mode
input_general_update_mode: !input general_update_mode
input_pause_entities: !input pause_entities
action:
########## Refresh update list ##########
- &recalc-update-list
variables:
core_update_entity: >
{% for u in integration_entities('hassio') | select('search', '^update[.]')
if (device_attr(u, 'identifiers') | first)[1] == 'core' %}
{{ u }}
{% endfor %}
os_update_entity: >
{% for u in integration_entities('hassio') | select('search', '^update[.]')
if (device_attr(u, 'identifiers') | first)[1] == 'OS' %}
{{ u }}
{% endfor %}
supervisor_update_entity: >
{% for u in integration_entities('hassio') | select('search', '^update[.]')
if (device_attr(u, 'identifiers') | first)[1] == 'supervisor' %}
{{ u }}
{% endfor %}
firmware_update_entities: >
{{ states.update
| default([])
| selectattr('attributes.device_class', 'defined')
| selectattr('attributes.device_class', 'eq', 'firmware')
| map(attribute='entity_id')
| list
}}
general_update_entities: >
{{ states.update
| default([])
| rejectattr('entity_id', 'in', core_update_entity)
| rejectattr('entity_id', 'in', os_update_entity)
| rejectattr('entity_id', 'in', supervisor_update_entity)
| rejectattr('entity_id', 'in', firmware_update_entities)
| map(attribute='entity_id')
| list
}}
input_update_exclusions: >
{% set exclusions = temp_input_update_exclusions | default([]) %}
{% if input_core_os_update_mode == 'ignore' %}
{% set exclusions = exclusions + [core_update_entity | default(""), os_update_entity | default("")] %}
{% else %}
{% set core_installed_version = states.update | default([]) | selectattr('entity_id', 'in', core_update_entity | default("")) | map(attribute='attributes.installed_version') | list | first | default('') %}
{% set core_latest_version = states.update | default([]) | selectattr('entity_id', 'in', core_update_entity | default("")) | map(attribute='attributes.latest_version') | list | first | default('') %}
{% set core_version_change = version(core_latest_version) - version(core_installed_version) %}
{% set os_installed_version = states.update | default([]) | selectattr('entity_id', 'in', os_update_entity | default("")) | map(attribute='attributes.installed_version') | list | first | default('') %}
{% set os_latest_version = states.update | default([]) | selectattr('entity_id', 'in', os_update_entity | default("")) | map(attribute='attributes.latest_version') | list | first | default('') %}
{% set os_version_change = version(os_latest_version) - version(os_installed_version) %}
{% if input_core_os_update_mode == 'patches' %}
{% if core_version_change.major or core_version_change.minor or (not core_version_change.patch) %}
{% set exclusions = exclusions + [core_update_entity | default("")] %}
{% endif %}
{% if os_version_change.major or os_version_change.minor or (not os_version_change.patch) %}
{% set exclusions = exclusions + [os_update_entity | default("")] %}
{% endif %}
{% elif input_core_os_update_mode == 'major_and_minor' %}
{% if (not core_version_change.major) and (not core_version_change.minor) %}
{% set exclusions = exclusions + [core_update_entity | default("")] %}
{% endif %}
{% if (not os_version_change.major) and (not os_version_change.minor) %}
{% set exclusions = exclusions + [os_update_entity | default("")] %}
{% endif %}
{% endif %}
{% endif %}
{% if input_firmware_update_mode == 'ignore' %}
{% set exclusions = exclusions + [ firmware_update_entities ] %}
{% else %}
{% set ns = namespace(entities = []) %}
{% for entity in expand(firmware_update_entities) | rejectattr('entity_id', 'in', exclusions) | selectattr('state', 'eq', 'on') %}
{% set entity_version_change = version(entity.attributes.latest_version | default('')) - version(entity.attributes.installed_version | default('')) %}
{% if input_firmware_update_mode == 'patches' %}
{% if entity_version_change.major or entity_version_change.minor or (not entity_version_change.patch) %}
{% set ns.entities = ns.entities + [ entity.entity_id ] %}
{% endif %}
{% elif input_firmware_update_mode == 'major_and_minor' %}
{% if (not entity_version_change.major) and (not entity_version_change.minor) %}
{% set ns.entities = ns.entities + [ entity.entity_id ] %}
{% endif %}
{% endif %}
{% endfor %}
{% set exclusions = exclusions + [ ns.entities ] %}
{% endif %}
{% if input_general_update_mode == 'ignore' %}
{% set exclusions = exclusions + [ general_update_entities ] %}
{% else %}
{% set ns = namespace(entities = []) %}
{% for entity in expand(general_update_entities) | rejectattr('entity_id', 'in', exclusions) | selectattr('state', 'eq', 'on') %}
{% set entity_version_change = version(entity.attributes.latest_version | default('')) - version(entity.attributes.installed_version | default('')) %}
{% if input_general_update_mode == 'patches' %}
{% if entity_version_change.major or entity_version_change.minor or (not entity_version_change.patch) %}
{% set ns.entities = ns.entities + [ entity.entity_id ] %}
{% endif %}
{% elif input_general_update_mode == 'major_and_minor' %}
{% if (not entity_version_change.major) and (not entity_version_change.minor) %}
{% set ns.entities = ns.entities + [ entity.entity_id ] %}
{% endif %}
{% endif %}
{% endfor %}
{% set exclusions = exclusions + [ ns.entities ] %}
{% endif %}
{{ exclusions }}
updates_list: >
{{ states.update
| default([])
| selectattr('state','eq','on')
| rejectattr('entity_id', 'in', input_update_exclusions)
| map(attribute='entity_id')
| list
}}
- alias: "Refresh update list - update entities"
service: homeassistant.update_entity
data: {}
target:
entity_id: "{{ states.update | map(attribute='entity_id') | list }}"
continue_on_error: true
########## Check for skipping core/OS ##########
- alias: "Re-check conditions"
continue_on_error: true
if:
- "{{ (states.update | selectattr('state','eq','on') | selectattr('entity_id', 'in', updates_list) | rejectattr('entity_id', 'in', input_update_exclusions) | list | count | int(0)) < 1 }}"
then:
- stop: Nothing to update
else: []
########## Starting ##########
- &logbook-variables
if: "{{ input_verbose_logging_bool }}"
then:
- alias: Logbook - variables
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: >-
Variables:
input_backup_bool: {{ input_backup_bool }},
input_restart_type: {{ input_restart_type }},
input_verbose_logging_bool: {{ input_verbose_logging_bool }},
input_max_backup_age_seconds: {{ input_max_backup_age_seconds }},
input_schedule_monthday: {{ input_schedule_monthday }},
input_update_exclusions: {{ input_update_exclusions }},
input_core_os_update_mode: {{ input_core_os_update_mode }},
input_firmware_update_mode: {{ input_firmware_update_mode }},
input_general_update_mode: {{ input_general_update_mode }},
core_update_entity: {{ core_update_entity }},
os_update_entity: {{ os_update_entity }},
supervisor_update_entity: {{ supervisor_update_entity }},
firmware_update_entities: {{ firmware_update_entities }},
general_update_entities; {{ general_update_entities }},
updates_list: {{ updates_list }}
continue_on_error: true
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Logbook - A new update is available"
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
domain: update
message: A new update is available for Home Assistant.
- alias: "Logbook - List of updates"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
domain: update
message: >
List of updates:
- {{ states.update
| selectattr('state','eq','on')
| selectattr('entity_id', 'in', updates_list)
| rejectattr('entity_id', 'in', input_update_exclusions)
| map(attribute='name') | list | join('
- ') }}
- alias: "Logbook: Running pre-update actions"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: Running pre-update actions...
continue_on_error: true
- alias: "Run pre-update actions"
continue_on_error: true
choose:
- conditions:
- '{{ true }}'
sequence: !input actions_pre_update
default: []
########## Backup ##########
- alias: Check existing backups uploaded
continue_on_error: true
if:
- "{{ input_max_backup_age_seconds > 0 }}"
then:
- alias: Check if backup state is defined
if: >
{{
not states.sensor.backup_state.state is defined or
not states.sensor.backup_state.attributes.last_uploaded is defined
}}
then:
- stop: "Backup State sensor not found"
- alias: Check age of last uploaded backup
if: >-
{{ as_timestamp(now()) - as_timestamp(state_attr('sensor.backup_state', 'last_uploaded')) > input_max_backup_age_seconds }}
then:
- stop: "Last uploaded backup is too old"
- alias: "Backup"
continue_on_error: true
if:
- "{{ input_backup_bool }}"
# {{ ( input_backup_bool ) and ((as_timestamp(now()) - as_timestamp(state_attr('sensor.backup_state', 'last_backup'))) > 7200) }}
then:
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Logbook - Backing up"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: Backing up Home Assistant.
- alias: "Call backup service"
continue_on_error: true
service: hassio.backup_full
data:
compressed: true
# - wait_template: >
# {{ ((as_timestamp(now()) - as_timestamp(state_attr('sensor.backup_state', 'last_backup'))) <= 7200) }}
# continue_on_timeout: true
# timeout: '3600' #3600
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Backup triggered"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: Backup triggered.
- alias: "Give 1h for the backup" # There's no sensor for when the backup finishes
delay: 3600
else: []
########## Update add-ons (Standard) ##########
- *recalc-update-list
- *logbook-variables
- alias: "Update - Standard"
continue_on_error: true
repeat:
while:
- "{{ input_general_update_mode in ['patches', 'major_and_minor', 'all'] }}"
- condition: state
entity_id: !input schedule_entity
state: "on"
- condition: template
value_template: >
{{ ( states.update
| selectattr('state','eq','on')
| selectattr('entity_id', 'in', updates_list)
| rejectattr('entity_id', 'in', core_update_entity)
| rejectattr('entity_id', 'in', os_update_entity)
| rejectattr('entity_id', 'in', firmware_update_entities)
| rejectattr('entity_id', 'in', input_update_exclusions)
| map(attribute='entity_id')
| list | count | int(0) ) > 0
}}
sequence:
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Update - Standard - Logbook - Starting"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: "Starting sequence of standard updates..."
- variables:
pending_update_list: >
{{ states.update
| selectattr('state','eq','on')
| selectattr('entity_id', 'in', updates_list)
| rejectattr('entity_id', 'in', core_update_entity)
| rejectattr('entity_id', 'in', os_update_entity)
| rejectattr('entity_id', 'in', firmware_update_entities)
| rejectattr('entity_id', 'in', input_update_exclusions)
| map(attribute='entity_id')
| list
}}
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Update - Standard - Logbook - Updating"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: "Updating {{pending_update_list[0]}} of {{pending_update_list}} ..."
- alias: "Update - Standard - Install"
continue_on_error: true
service: update.install
data: {}
target:
entity_id: '{{ pending_update_list[0] }}'
- alias: "Update - Standard - wait"
continue_on_error: true
wait_template: "{{ is_state(pending_update_list[0], 'off') }}"
continue_on_timeout: true
timeout: '3600'
########## Update core items ##########
- *recalc-update-list
- *logbook-variables
- alias: "Update - Core"
continue_on_error: true
repeat:
while:
- "{{ input_core_os_update_mode in ['patches', 'major_and_minor', 'all'] }}"
- condition: state
entity_id: !input schedule_entity
state: "on"
- condition: template
value_template: >
{{ ( states.update
| selectattr('state','eq','on')
| selectattr('entity_id', 'in', updates_list)
| selectattr('entity_id', 'in', core_update_entity)
| rejectattr('entity_id', 'in', os_update_entity)
| rejectattr('entity_id', 'in', firmware_update_entities)
| rejectattr('entity_id', 'in', input_update_exclusions)
| map(attribute='entity_id')
| list | count | int(0) ) > 0
}}
sequence:
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Update - Core - Logbook - Starting"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: "Starting sequence of core items updates..."
- variables:
pending_update_list: >
{{ states.update
| selectattr('state','eq','on')
| selectattr('entity_id', 'in', updates_list)
| selectattr('entity_id', 'in', core_update_entity)
| rejectattr('entity_id', 'in', os_update_entity)
| rejectattr('entity_id', 'in', firmware_update_entities)
| rejectattr('entity_id', 'in', input_update_exclusions)
| map(attribute='entity_id')
| list
}}
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Update - Core - Logbook - Updating"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: "Updating {{pending_update_list[0]}} of {{pending_update_list}} ..."
- alias: "Update - Core - Install"
continue_on_error: true
service: update.install
data: {}
target:
entity_id: '{{ pending_update_list[0] }}'
- alias: "Update - Core - Wait"
continue_on_error: true
wait_template: "{{ is_state(pending_update_list[0], 'off') }}"
continue_on_timeout: true
timeout: '3600'
########## Update OS ##########
- *recalc-update-list
- *logbook-variables
- alias: "Update - OS"
continue_on_error: true
repeat:
while:
- "{{ input_core_os_update_mode in ['patches', 'major_and_minor', 'all'] }}"
- condition: state
entity_id: !input schedule_entity
state: "on"
- condition: template
value_template: >
{{ ( states.update
| selectattr('state','eq','on')
| selectattr('entity_id', 'in', updates_list)
| rejectattr('entity_id', 'in', core_update_entity)
| selectattr('entity_id', 'in', os_update_entity)
| rejectattr('entity_id', 'in', firmware_update_entities)
| rejectattr('entity_id', 'in', input_update_exclusions)
| map(attribute='entity_id')
| list | count | int(0) ) > 0
}}
sequence:
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Update - OS - Logbook - Starting"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: "Starting sequence of OS update..."
- variables:
pending_update_list: >
{{ states.update
| selectattr('state','eq','on')
| selectattr('entity_id', 'in', updates_list)
| rejectattr('entity_id', 'in', core_update_entity)
| selectattr('entity_id', 'in', os_update_entity)
| rejectattr('entity_id', 'in', firmware_update_entities)
| rejectattr('entity_id', 'in', input_update_exclusions)
| map(attribute='entity_id')
| list
}}
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Update - OS - Logbook - Updating"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: "Updating {{pending_update_list[0]}} of {{pending_update_list}} ..."
- alias: "Update - OS - Install"
continue_on_error: true
service: update.install
data: {}
target:
entity_id: '{{ pending_update_list[0] }}'
- alias: "Update - OS - Wait"
continue_on_error: true
wait_template: "{{ is_state(pending_update_list[0], 'off') }}"
continue_on_timeout: true
timeout: '3600'
########## Devices firmware ##########
- *recalc-update-list
- alias: "Update - Devices firmware"
continue_on_error: true
repeat:
while:
- "{{ input_firmware_update_mode in ['patches', 'major_and_minor', 'all'] }}"
- condition: state
entity_id: !input schedule_entity
state: "on"
- condition: template
value_template: >
{{ ( states.update
| selectattr('state','eq','on')
| selectattr('entity_id', 'in', updates_list)
| rejectattr('entity_id', 'in', core_update_entity)
| rejectattr('entity_id', 'in', os_update_entity)
| selectattr('entity_id', 'in', firmware_update_entities)
| rejectattr('entity_id', 'in', input_update_exclusions)
| map(attribute='entity_id')
| list | count | int(0) ) > 0
}}
sequence:
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Update - Devices firmware - Logbook - Starting"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: "Starting sequence of Devices firmware update..."
- variables:
pending_update_list: >
{{ states.update
| selectattr('state','eq','on')
| selectattr('entity_id', 'in', updates_list)
| rejectattr('entity_id', 'in', core_update_entity)
| rejectattr('entity_id', 'in', os_update_entity)
| selectattr('entity_id', 'in', firmware_update_entities)
| map(attribute='entity_id')
| list
}}
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Update - Devices firmware - Logbook - Updating"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: "Updating {{pending_update_list[0]}} of {{pending_update_list}} ..."
- alias: "Update - Devices firmware - Install"
continue_on_error: true
service: update.install
data: {}
target:
entity_id: '{{ pending_update_list[0] }}'
- alias: "Update - Devices firmware - Wait"
continue_on_error: true
wait_template: "{{ is_state(pending_update_list[0], 'off') }}"
continue_on_timeout: true
timeout: '3600'
########## Finishing ##########
- *recalc-update-list
- *logbook-variables
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Logbook - Updating"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: Finishing update process.
- alias: "Logbook - Remaining updates"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: >
Remaining updates:
- {{ states.update
| selectattr('state','eq','on')
| selectattr('entity_id', 'in', updates_list)
| rejectattr('entity_id', 'in', input_update_exclusions)
| map(attribute='name') | list | join('
- ') }}
########## Restart Home Assistant ##########
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Restart - Logbook"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: >
{{ states.update
| selectattr('attributes.release_summary', 'defined')
| selectattr('attributes.release_summary', 'search', "<ha-alert alert-type='error'>")
| map(attribute='entity_id')
| list
| count
| int(0) }} item(s) pending a restart:
- {{ states.update
| selectattr('attributes.release_summary', 'defined')
| selectattr('attributes.release_summary', 'search', "<ha-alert alert-type='error'>")
| map(attribute='entity_id')
| list
| join('
- ') }}
- alias: "Restart"
continue_on_error: true
if:
- >-
{{ input_restart_type != "no-restart" and (
(
states.update
| selectattr('attributes.release_summary', 'defined')
| selectattr('attributes.release_summary', 'search', "<ha-alert alert-type='error'>")
| map(attribute='entity_id')
| list | count | int(0)
) > 0)
}}
then:
- alias: "Restart - Check config"
continue_on_error: true
service: homeassistant.check_config
- if:
- "{{ states.persistent_notification.invalid_config.state | default('unavailable') == 'notifying' or states.persistent_notification.homeassistant_check_config.state | default('unavailable') == 'notifying' }}"
then:
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Logbook: Running pre-restart actions"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: Running pre-restart actions...
- alias: "Run pre-restart actions"
continue_on_error: true
choose:
- conditions:
- '{{ true }}'
sequence: !input actions_pre_restart
default: []
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Restart - Logbook - Skipping restart"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: >
Skipping restart process due to notifications of invalid configurations:
states.persistent_notification.invalid_config.state = {{ states.persistent_notification.invalid_config.state | default('unavailable') }},
states.persistent_notification.homeassistant_check_config.state = {{ states.persistent_notification.homeassistant_check_config.state | default('unavailable') }}
else:
- alias: "Restart - Logbook - Restarting"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: 'Restarting Home Assistant {{ input_restart_type }}...'
- alias: "Restart - Call reboot service"
continue_on_error: true
service: '{{ "hassio.host_reboot" if input_restart_type == "host" else "homeassistant.restart" }}'
########## Post-update actions ##########
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Logbook - Post-actions"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: Running post-update actions...
- alias: "Run post-update actions"
continue_on_error: true
choose:
- conditions:
- '{{ true }}'
sequence: !input actions_pos_update
default: []
########## Done! ##########
- if: "{{ input_verbose_logging_bool }}"
then:
- alias: "Logbook - Done"
continue_on_error: true
service: logbook.log
data:
name: Auto-update
entity_id: '{{ this.entity_id }}'
message: Done!