現在使用esphome的裝置越來越多,home assistant 也把esphome 整合進去
每次esphome 更新後,都會提示esphome 的每個裝置都要更新
所以找了一下參考做一個自動更新esphome 的自動化
有需要的自行取用
每天半夜00:00 會自動檢查有沒有需要更新
alias: ESPHOME 裝置自動更新
description: >-
Automatically update ESPHome Devices at midnight, and notify when they are
updated.
trigger:
- platform: time
at: "00:00:00"
id: update_check
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)
| 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: notify.此處接你的通知service 看是要line還是手機
data:
title: ESPHome Devices
message: |-
你的ESPHOME裝置將從 {{
state_attr(outdated_esp_items[0],"installed_version") }} 更新到 {{
state_attr(outdated_esp_items[0],"latest_version") }}.
- repeat:
for_each: "{{outdated_esp_items}}"
sequence:
- service: update.install
target:
entity_id: "{{ repeat.item }}"
- wait_template: "{{ is_state(repeat.item, 'off') }}"
- service: notify.此處接你的通知service 看是要line還是手機
data:
title: ESPHome Devices
message: 更新完成
mode: single