Skip to content

Instantly share code, notes, and snippets.

@candyman2903
Forked from mdegat01/update_notifications.yaml
Last active September 14, 2023 00:26
Show Gist options
  • Save candyman2903/a8af4ece5127f693b09c861651adbd44 to your computer and use it in GitHub Desktop.
Save candyman2903/a8af4ece5127f693b09c861651adbd44 to your computer and use it in GitHub Desktop.
Update Notifications Automation Blueprint
blueprint:
name: Update Benachrichtigung
description: Senden Sie Benachrichtigungen für neue Updates und installieren oder überspringen Sie eine Aktion
homeassistant:
min_version: '2022.4.0'
domain: automation
input:
update_entities:
name: Entitäten aktualisieren
description: >-
Liste der Update-Entitäten, die auf Updates achten und benachrichtigt werden, sobald eines verfügbar ist.
selector:
entity:
domain: update
multiple: true
mobile_app_device:
name: Mobiles App-Gerät
description: (Optional) Android, iPhone, Mac. Alles mit der Begleit-App
default: ''
selector:
device:
integration: mobile_app
mobile_app_device_2:
name: Mobiles App-Gerät 2
description: (Optional) Android, iPhone, Mac. Alles mit der Begleit-App
default: ''
selector:
device:
integration: mobile_app
send_to_ha:
name: An HA senden
description: Als dauerhafte Benachrichtigung an HA senden
default: false
selector:
boolean:
reminder_hours:
name: Erinnerungsstunden
description: >-
Sofern angegeben, werden alle x Stunden Erinnerungen für ausstehende Aktualisierungen gesendet.
HINWEIS: Dadurch werden Sie alle x Stunden an ausstehende Aktualisierungen erinnert, nicht nur an die
diejenigen, die in „update_entities“ aufgeführt sind. Auch wenn Sie nicht jede Update-Entität auflisten
Dort kann man nach einem Update immer noch recht zeitnah benachrichtigt werden.
default: '3'
selector:
select:
options: ['None', '1', '2', '3', '6', '12', '24']
take_backup:
name: Machen Sie Backup
description: Führen Sie nach Möglichkeit vor dem Update eine Teilsicherung durch
default: true
selector:
boolean:
run_config_check:
name: Führen Sie eine Konfigurationsprüfung durch
description: >-
Wenn „true“, startet diese Automatisierung das Add-on „Konfiguration prüfen“, wenn ein Kernupdate verfügbar ist.
In der Benachrichtigung wird zunächst angezeigt, dass die Konfigurationsprüfung ausgeführt wird, und nach Abschluss wird eine Aktualisierung durchgeführt. Klicken
Die Benachrichtigung öffnet die Protokolle dieses Add-ons, sodass Sie den Status überprüfen können.
WARNUNG: Sie müssen Ihre Update-Entität für Core in „update_entities“ auflisten, um diese Funktion nutzen zu können.
default: false
selector:
boolean:
changelog_urls:
name: Changelog-URLs
description: >-
Einige Update-Entitäten (z. B. die für Add-ons) haben keinen Link zum Änderungsprotokoll, weil dies nicht möglich ist.
Wenn Sie das stört, können Sie hier ein Wörterbuch bereitstellen. Jeder Schlüssel sollte eine Update-Entitäts-ID sein
und der Wert der URL zu seinem Änderungsprotokoll. Dies wird nur verwendet, wenn „release_url“ in der Update-Entität „null“ ist.
EX. `update.adguard_home_update: https://github.com/hassio-addons/addon-adguard-home/releases/latest` oder
`update.mariadb_update: https://github.com/home-assistant/addons/blob/master/mariadb/CHANGELOG.md`
default: 'none'
selector:
object:
only_after:
name: Nur nach
description: Senden Sie Benachrichtigungen erst nach dieser Zeit an mobile Geräte
default: '00:00:00'
selector:
time:
only_before:
name: Nur vorher
description: Senden Sie vor diesem Zeitpunkt nur Benachrichtigungen an mobile Geräte
default: '00:00:00'
selector:
time:
notification_channel:
name: Kanal/Gruppe
description: >-
Legt den [Kanal](https://companion.home-assistant.io/docs/notifications/notifications-basic#notification-channels) (Android) fest und
[Gruppe](https://companion.home-assistant.io/docs/notifications/notifications-basic#grouping) (ios) für Update-Benachrichtigungen
default: Updates
selector:
text:
status_bar_icon:
name: Statusleisten-Symbol
description: >-
(Nur Android) Legt das [Statusleistensymbol] fest (https://companion.home-assistant.io/docs/notifications/notifications-basic/#notification-icon).
HINWEIS: Anders als das Symbol in der Benachrichtigung ist dieses immer auf das Entitätsbild des Updates eingestellt
Entität (sofern vorhanden).
default: mdi:package-up
selector:
icon:
placeholder: mdi:package-up
mode: parallel
max: 100
trigger_variables:
_reminder_hours: !input reminder_hours
reminder_hours: "{{ _reminder_hours | default(0) | int(0) }}"
run_config_check: !input run_config_check
update_entities: !input update_entities
trigger:
- id: new
platform: state
entity_id: !input update_entities
to: 'on'
- id: started
platform: state
entity_id: !input update_entities
attribute: in_progress
from: false
to: true
- id: done
platform: state
entity_id: !input update_entities
from: 'on'
to: 'off'
- id: install
platform: event
event_type: mobile_app_notification_action
event_data:
action: install-update
- id: install_ios
platform: event
event_type: mobile_app_notification_action
event_data:
actionName: install-update
- id: skip
platform: event
event_type: mobile_app_notification_action
event_data:
action: skip-update
- id: skip_ios
platform: event
event_type: mobile_app_notification_action
event_data:
actionName: skip-update
- id: core_check
platform: template
value_template: &core-check-complete >-
{% set ns = namespace(core=none) %}
{% for u in integration_entities('hassio') | select('in', update_entities)
if (device_attr(u, 'identifiers') | first)[1] == 'core' %}
{% set ns.core = u %}
{% endfor %}
{% if run_config_check and ns.core is string and expand(ns.core) | first | attr('state') == 'on' %}
{% for e in expand(integration_entities('hassio')) | selectattr('attributes.device_class', 'eq', 'running')
if (device_attr(e.entity_id, 'identifiers') | first)[1] == 'core_check_config' %}
{{ e.state == 'off' and e.last_changed > expand(ns.core) | first | attr('last_changed') }}
{% endfor %}
{% else %}
{{ false }}
{% endif %}
- id: ha_start
platform: homeassistant
event: start
- platform: template
value_template: >-
{{ states.update | selectattr('state', 'eq', 'on') | list | count > 0
and reminder_hours > 0 and now().hour % reminder_hours == 0
and now().minute == 0 and now().second == 0 }}
- id: sticky_ios
platform: event
event_type: mobile_app_notification_action
event_data:
action: URI
variables:
mobile_app_device: !input mobile_app_device
_mobile_app_device_2: !input mobile_app_device_2
mobile_app_device_2: "{{ _mobile_app_device_2 if _mobile_app_device_2 != mobile_app_device }}"
send_to_ha: !input send_to_ha
_changelog_urls: !input changelog_urls
changelog_urls: "{{ _changelog_urls if _changelog_urls is mapping else {} }}"
take_backup: !input take_backup
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 %}
skip_action:
action: skip-update
title: Überspringen
destructive: true
authenticationRequired: true
update_action:
action: install-update
title: Aktualisieren
destructive: true
authenticationRequired: true
action:
choose:
- alias: Update-Aktion installieren
conditions: "{{ trigger.id in ['install', 'install_ios'] }}"
sequence:
- variables:
entity_id: &tag-to-entity >-
update.{{ trigger.event.data.tag
if trigger.event.data.tag is string and trigger.event.data.tag != ''
else trigger.event.data.action_data.tag }}
- service: update.install
data:
entity_id: "{{ entity_id }}"
backup: >-
{% set ids = device_attr(entity_id, 'identifiers') | first %}
{{ take_backup and ids[0] == 'hassio' and ids[1] not in ['supervisor', 'OS'] }}
- alias: Aktualisierungsaktion überspringen
conditions: "{{ trigger.id in ['skip', 'skip_ios'] }}"
sequence:
service: update.skip
data:
entity_id: *tag-to-entity
- alias: Update abgeschlossen
conditions: "{{ trigger.id == 'done' }}"
sequence:
- &id-from-state-trigger
variables:
entity_id: "{{ trigger.entity_id }}"
- &dismiss-variables
variables:
message: clear_notification
data:
tag: &tag-from-entity "{{ entity_id[7:] }}"
- &send-to-mobile-devices
choose: []
default:
- variables:
data: "{{ dict(data, action_data={'tag': data.tag}) }}"
- choose:
alias: Falls angegeben, an das erste Mobilgerät senden
conditions: "{{ not not mobile_app_device }}"
sequence:
device_id: !input mobile_app_device
domain: mobile_app
type: notify
title: "{{ title | default('') }}"
message: >-
{{ message if device_attr(mobile_app_device, 'manufacturer') != 'Apple'
else message | replace('<br>', '\n') }}
data: >-
{{ data if
device_attr(mobile_app_device, 'manufacturer') != 'Apple' or data.icon_url is not string
else dict(data, image=data.icon_url) }}
- choose:
alias: Falls angegeben, an zweites Mobilgerät senden
conditions: "{{ not not mobile_app_device_2 }}"
sequence:
device_id: !input mobile_app_device_2
domain: mobile_app
type: notify
title: "{{ title | default('') }}"
message: >-
{{ message if device_attr(mobile_app_device_2, 'manufacturer') != 'Apple'
else message | replace('<br>', '\n') }}
data: >-
{{ data if
device_attr(mobile_app_device_2, 'manufacturer') != 'Apple' or data.icon_url is not string
else dict(data, image=data.icon_url) }}
- &dismiss-from-ha
alias: Bei Replikation dort aus HA verwerfen
choose:
conditions: "{{ send_to_ha }}"
sequence:
service: persistent_notification.dismiss
data:
notification_id: *tag-from-entity
- alias: Verwerfen Sie beim Start Kern- und Betriebssystembenachrichtigungen, da sie im ausgeschalteten Zustand auftraten
conditions: "{{ trigger.id == 'ha_start' }}"
sequence:
- alias: Benachrichtigung über Kernaktualisierungen verwerfen, wenn diese Option deaktiviert ist
choose:
conditions: "{{ core_update_entity != '' and expand(core_update_entity) | first | attr('state') == 'off' }}"
sequence:
- variables:
entity_id: "{{ core_update_entity }}"
- *dismiss-variables
- *send-to-mobile-devices
- *dismiss-from-ha
- alias: Benachrichtigung über Betriebssystemaktualisierungen verwerfen, wenn deaktiviert
choose:
conditions: "{{ os_update_entity != '' and expand(os_update_entity) | first | attr('state') == 'off' }}"
sequence:
- variables:
entity_id: "{{ os_update_entity }}"
- *dismiss-variables
- *send-to-mobile-devices
- *dismiss-from-ha
- alias: Neues Update verfügbar
conditions: "{{ trigger.id == 'new' }}"
sequence:
- *id-from-state-trigger
- &update-variables
variables:
ids: "{{ device_attr(entity_id, 'identifiers') | first }}"
changelog_action:
action: URI
title: Änderungsprotokoll
uri: >-
{% set version = state_attr(entity_id, 'latest_version') %}
{{ state_attr(entity_id, 'release_url')
| default(changelog_urls[entity_id] | default(''), true)
| regex_replace('(/CHANGELOG.md)$', '\\1#' ~ version | regex_replace('[^-\\w]'))
| default(None, true) }}
include_core_check: "{{ run_config_check and ids[0] == 'hassio' and ids[1] == 'core' }}"
core_check_complete: *core-check-complete
title: "{{ state_attr(entity_id, 'friendly_name') }}"
message: >-
{% set summary = state_attr(entity_id, 'release_summary') %}
Die neueste Version ist {{ state_attr(entity_id, 'latest_version') }}<br>
Installierte Version ist {{ state_attr(entity_id, 'installed_version') }}
{% if include_core_check %}
<br>Konfigurationsprüfung ist {{ 'abgeschlossen, überprüfen Sie die Add-on-Protokolle auf ihren Status.'
if core_check_complete else 'begonnen, sollte bald erledigt sein.' }}
{% endif %}
{{ '<br>' ~ summary if summary is string }}
url: >-
{% set url = device_attr(entity_id, 'configuration_url') %}
{% set ids = device_attr(entity_id, 'identifiers') | first %}
{% if url is string %}
{{ url | regex_replace('^homeassistant://') }}
{% elif ids[0] == 'hassio' and ids[1] in ['supervisor', 'OS'] %}
/hassio/system
{% elif run_config_check and ids[0] == 'hassio' and ids[1] == 'core' %}
/hassio/addon/core_check_config/logs
{% else %}
/config
{% endif %}
data:
tag: *tag-from-entity
channel: !input notification_channel
group: !input notification_channel
notification_icon: !input status_bar_icon
icon_url: "{{ state_attr(entity_id, 'entity_picture') | default('', true) }}"
url: "{{ url }}"
clickAction: "{{ url }}"
sticky: 'true'
actions: >-
{{ ([changelog_action] if changelog_action.uri is string else []) + [update_action] +
([] if ids[0] == 'hassio' and ids[1] == 'supervisor' else [skip_action]) }}
- &send-to-mobile-devices-time-check
choose:
alias: Nur innerhalb des angegebenen Zeitraums an mobile Geräte senden
conditions:
condition: time
after: !input only_after
before: !input only_before
sequence: *send-to-mobile-devices
- &send-to-ha
alias: Bei Replikation dort an HA senden
choose:
conditions: "{{ send_to_ha }}"
sequence:
service: persistent_notification.create
data:
notification_id: *tag-from-entity
title: "{{ title }}"
message: >-
{{ '%s\n\n### Mehr Info\n- [Öffnen](%s)' % (message | replace('<br>', '\n'), data.url) ~
('\n- [Änderungsprotokoll](%s)' % changelog_action.uri if changelog_action.uri is string else '') }}
- alias: Stoppen Sie, wenn dies nicht zum Kerngeschäft gehört oder wir keine Konfigurationsprüfung durchführen
condition: "{{ include_core_check }}"
- alias: Starten Sie das Config-Check-Addon
service: hassio.addon_start
data:
addon: core_check_config
- alias: Emulieren Sie Sticky unter IOS, indem Sie die Benachrichtigung neu erstellen
conditions:
- "{{ trigger.id == 'sticky_ios' }}"
- "{{ trigger.event.data.action_data is mapping and trigger.event.data.action_data.tag is string }}"
- "{{ is_state('update.' ~ trigger.event.data.action_data.tag, 'on') }}"
sequence:
- variables:
entity_id: *tag-to-entity
- *update-variables
- *send-to-mobile-devices
- *send-to-ha
- alias: Kernprüfungs-Add-on abgeschlossen
conditions: "{{ trigger.id == 'core_check' }}"
sequence:
- variables:
entity_id: "{{ core_update_entity }}"
- *update-variables
- *send-to-mobile-devices-time-check
- *send-to-ha
- alias: Update gestartet
conditions: "{{ trigger.id == 'started' }}"
sequence:
- *id-from-state-trigger
- *update-variables
- variables:
message: Aktualisierung...
data: >-
{{ dict(data, actions=[changelog_action] if changelog_action.uri is string else []) }}
- *send-to-mobile-devices-time-check
- *send-to-ha
- alias: Senden Sie Erinnerungen, falls aktiviert
conditions: "{{ reminder_hours > 0 }}"
sequence:
- alias: Erhalten Sie alle ausstehenden, nicht gestarteten Updates
variables:
updates: >-
{{ states.update
| selectattr('state', 'eq', 'on')
| rejectattr('attributes.in_progress', 'true')
| map(attribute='entity_id') | list }}
- alias: Durchlaufen Sie Aktualisierungen und senden Sie eine Erinnerung
repeat:
count: "{{ updates | count }}"
sequence:
- variables:
entity_id: "{{ updates[repeat.index - 1] }}"
- *update-variables
- *send-to-mobile-devices-time-check
- *send-to-ha
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment