Auto-updating ESPHome Devices with Home Assistant


ESPHome is a fantastic little project that enables easy integration of embedded sensoric devices into your home automation system, in particular also Home Assistant. When operating many of these devices, keeping them up-to-date with the latest version of ESPHome quickly becomes a hassle, as there are updates every other week. Here’s how to automate this.

An ESPHome-based sensor for presence detection (with PIR, temperature and humidity sensor).

I was happy to find the following automation that will automatically trigger updates whenever available. Head over to the automation UI, switch to YAML mode and insert this snippet:

alias: Auto-update ESPHome Devices
mode: single
trigger:
- platform: time_pattern
  hours: "3"
  minutes: "15"
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:
- condition: template
  value_template: "{{ outdated_esp_items | count > 0 }}"
action:
- service: update.install
  target:
    entity_id: "{{ outdated_esp_items }}"

This automation will select all ESPHome devices requiring a firmware update at 3:15am every night and automatically trigger the installation via Home Assistant’s built-in update service.

So far I never encountered issues with new ESPHome releases, and as long as you’re not using any kind of low-level operation (eg. via function Lambdas) it should work reliably.

#esphome #homeassistant #automation