Auto-update ESPHome Devices via Automation

I double checked with the last update:
The esphome-addon will compile and update the devices one-by-one after the update-service ist called for the complete list of outdated esphomes.

So it should be fine to call the update once a night:

automation:
  - alias: Auto-update ESP devices
    trigger:
      - platform: time_pattern
        hours: "3"
        minutes: "15"
    action:
      - variables:
          outdated_esp_items: |-
            {{ states.update
                | selectattr('state', 'eq', 'on')
                | selectattr('attributes.title', 'match', 'ESPHome')
                | selectattr('attributes.device_class', 'eq', 'firmware')
                | selectattr('attributes.auto_update', 'eq', false)
                | selectattr('attributes.in_progress', 'eq', false)
                | sort(attribute='attributes.installed_version')
                | map(attribute='entity_id')
                | list }}
      - condition: template
        value_template: "{{ outdated_esp_items | count > 0 }}"
      - service: update.install
        target:
          entity_id: "{{ outdated_esp_items }}"
    mode: single

Edit: Better condition that shows up in the gui.
Edit 2: Select only “firmware” entities and leave the addon update to the addon manager
Edit 3: Delete duplicate condition

7 Likes