Scheduled auto-update for Home Assistant

I will take a look at that during the weekend…

1 Like

So, before I jump again in the code, I’ve moved it to Github, so please feel free to suggest changes directly in the code if you think you know the solution… :wink:

This is the link: https://github.com/edwardtfn/ha_auto_update_scheduled

1 Like

I want to manually check full releases and let the patch updates run on their own. This template checks that the new version is in the same month as your installed version. Could make it more fine grain if you really needed but it’s worked in my testing. I just put it under the “Update - Core” section.

- condition: template
     value_template: >-
        {{ int(state_attr(core_update_entity,
        'latest_version').split('.')[1]) ==
        int(state_attr(core_update_entity,
        'installed_version').split('.')[1]) }}

I’m now working in a version which will allow the users to select how to behave for Core and OS updates. It still pending tests, which can take a while as I have to wait until some updates are available, so I’m not updating the main blueprint yet, but I would appreciate if some brave people want to try it and give me some feedback.
The risks are minor, as in worse case it won’t update when you want it to update or will behave as the current blueprint.
You will find this dev/test version here: ha_auto_update_scheduled/auto_update_scheduled.yaml at dev · edwardtfn/ha_auto_update_scheduled (github.com)

1 Like

Installed:-) I chose “patch”, however think the choices are confusing.

  1. All: Like All

  2. Patches only: I read this as all non major versions.

  • Like install 2022.12.4 if current is e.g. 2022.12.1
  • Do not install 2022.12.0 or 2022.12.3 if current version version is 2022.11.x
  1. Major & Minor: Not sure how this is different from “All”

  2. Do nothing, understandable

Will let you know what happens

If it works, I believe it will remove the need for the “do not update the first x days in a month”

From To All Patches only Major & minor only Don’t update
2022.11.0 2022.11.3 :white_check_mark: :white_check_mark: :x: :x:
2022.11.x 2022.12.x :white_check_mark: :x: :white_check_mark: :x:
2022.12.x 2023.1.x :white_check_mark: :x: :white_check_mark: :x:

Right!

That’s also right!

This will only install major and minor, and will ignore patches.
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).

I will clarify this in the description… Later… :grinning:

Thank you very much!!

I agree that this option is kind of obsolete now, but I’m afraid that removing it now will break the logic for someone already using this or even someone who still want the major updates to come automatically, but not the first on in the month.
Let’s see if we get more feedback about this.

Thanks again!!!

Still waiting for a update…

You small table give a super overview. Raises the question of why ever have the “major and minor” selected, might just be me that do not see the need for this one:-)

I agree on the “do not update first xx days”. Much easier to let it continue, some people might have a different use case where it makes sence.

1 Like

Another good point… I’m not planning to use this option myself, as I don’t see the point, and if I will ever think about removing this it is better to do now than later when some people would have selected that option…
I will remove that and let’s see how long it will take for someone ask for that functionality, then I can ask for a use case.

There is a major update scheduled for Jan 4th.

Thanks for sharing this blueprint, Edward.

As @taw123 suggested, it would be really nice to use this script for firmware updates only. Maybe it would be possible to filter on the origin of updates.

E.g. atm I have 34 ZigBee bulbs to update through Z2M. This is rather laborious as each bulb should ideally be updated separately and each update takes at least 20 minutes.

Maybe the new patches only option would be close enough.

I’m about to release a new version where you can set a different behaviour for HA Core and OS. Maybe I should have another set for Add-ons and then everything else will respect the other filters…

I will think a little bit more about this and come back next week with something, but all ideas will be very welcome.

2 Likes

The new version did not work this night. There is a 2022.12.9 waiting, and it did never start the automation. I have this in the log, yesterday during a restart of HA (07.42), at this morning 03.00 and again at 03.30. This fits to my schedule, which is from 03.00-03.30.

Logger: homeassistant.components.automation.ha_update_test_blueprint
Source: components/automation/__init__.py:500
Integration: Automation (documentation, issues)
First occurred: January 3, 2023 at 07:42:01 (3 occurrences)
Last logged: 03:30:00

Error rendering variables: UndefinedError: 'core_version_change' is undefined

and this

Logger: homeassistant.helpers.template
Source: helpers/template.py:147
First occurred: January 3, 2023 at 07:42:01 (3 occurrences)
Last logged: 03:30:00

Template variable error: 'core_version_change' is undefined when rendering '{% set exclusions = temp_input_update_exclusions | default([]) %} {% if input_core_os_update_mode == 'ignore' %} {% set exclusions = exclusions + [core_update_entity, os_update_entity] %} {% elif 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] %} {% endif %} {% if os_version_change.major or os_version_change.minor or (not os_version_change.patch) %} {% set exclusions = exclusions + [os_update_entity] %} {% 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] %} {% endif %} {% if (not os_version_change.major) and (not os_version_change.minor) %} {% set exclusions = exclusions + [os_update_entity] %} {% endif %} {% endif %} {{ exclusions }}'

Thanks for sharing your logs. I already found the bug and will fix it very soon.

Fixed!!
You can find it in the same link as before.

Decided to make a change to my schedule, to trigger an update. It worked perfectly and updated to 2022.12.9 as expected. Nothing unusual in the logs:-)
Now I will wait for 2023.01.1, which it should not install as I have “patches only”. Will report back.

1 Like

During the night it did not 2023.01.0. So, “patches” version works as expected.

If I find the time during the weekend, I will test install of the major new version by choosing the “all”

1 Like

Great!
Thanks again for testing this. I’m also playing from my side and hopefully I will be able to make this the “main” blueprint earlier next week.

Got a information mail, one i have created, send by the blueprint when it updates something. I got the mail at 03.00, right on time. However,
I was not expecting anything to be updated (I only install patches, and not the major one waiting) and can not find anything actually being updated. Not sure what happpend.

I have this in the log, as the only thing happening at 03.00.


2023-01-06 03:00:00.036 WARNING (MainThread) [homeassistant.helpers.template] Template variable warning: 'input_pause_entities_selected' is undefined when rendering '{{ not input_pause_entities_selected }}'

Could you please take a look on your logbook for any entry from your automation (you can filter by the automation name) after 03:00?

Are you sure this was not caused by HA Core v2023.1.1 released a few hours ago?

I will review this part of the code, but I don’t think it has anything to do with the system installing an unexpected update.

By the way, as you have an action sending you an email, are you aware you can add the list of updates to your email?
You can use any of the variables available in the blueprint by that moment, and the list of updates is on the variable updates_list, so if you add {{ updates_list }} to your email body it will replace this by the list of updates.

This is how I have my notifications:

    actions_pre_update:
      - service: notify.signal_edward
        continue_on_error: true
        data:
          message: Starting Home Assistant update.
      - service: notify.signal_edward
        continue_on_error: true
        data:
          message: |-
            List of updates: - {{ updates_list | join(' 
            - ') }}

I’m also fixing some issues with the restart process (which is not working 100% of the time after I implemented this filter for core/OS updates) and will later add another option to run actions before restarting. This won’t support updates where the restart is automatically (like HA core), but will work for those requiring manually restart (which will be done by the blueprint).
I will let you know.

Nothing in main logbook, except the "autoupdate schedule helper, which goes on at 03.00 and off at 03.30.

In the automation trace from the run at 03.00 there are a number of informations. The logbook part.

HA, Update test blueprint triggered by state of Autoupdate Schedule Helper
03:00:00 - 15 hours ago
Auto-update Variables: input_backup_bool: False, input_restart_bool: False, input_schedule_monthday: 1, input_update_exclusions: [], input_core_os_update_mode: patches, updates_list: ['update.home_assistant_core_update'] triggered by automation HA, Update test blueprint triggered by state of Autoupdate Schedule Helper
03:00:00 - 15 hours ago
Auto-update A new update is available for Home Assistant. triggered by automation HA, Update test blueprint triggered by state of Autoupdate Schedule Helper
03:00:00 - 15 hours ago
Auto-update List of updates: - Home Assistant Core Update triggered by automation HA, Update test blueprint triggered by state of Autoupdate Schedule Helper
03:00:00 - 15 hours ago
Auto-update Running pre-update actions... triggered by automation HA, Update test blueprint triggered by state of Autoupdate Schedule Helper
03:00:00 - 15 hours ago
Auto-update Updating all remaining items (if any). triggered by automation HA, Update test blueprint triggered by state of Autoupdate Schedule Helper
03:00:00 - 15 hours ago
Auto-update Finishing update process. triggered by automation HA, Update test blueprint triggered by state of Autoupdate Schedule Helper
03:00:00 - 15 hours ago
Auto-update Remaining updates: - triggered by automation HA, Update test blueprint triggered by state of Autoupdate Schedule Helper
03:00:00 - 15 hours ago
Auto-update Running post-update actions... triggered by automation HA, Update test blueprint triggered by state of Autoupdate Schedule Helper
03:00:00 - 15 hours ago
Auto-update Done! triggered by automation HA, Update test blueprint triggered by state of Autoupdate Schedule Helper
03:00:00 - 15 hours ago

Also, if I look in the trace, it runs the part of sending the mail.

Executed: January 6, 2023 at 03:00:00
Result:
choice: 0

I have downloaded the trace og the run, however not sure it is usefull. At least I do not know how to read it. It is to biig to include here. If you would like it, I can send on a e-mail.

Im aware of the email part of getting the list of updates, have it in the original automation. Was lacy and did not include it in the test automation. Have updated now.