In diesem Video zeige ich dir, wie du Benachrichtigungen in Home Assistant deutlich einfacher verwalten kannst! Normalerweise muss man in jeder Automatisierung festlegen, wer welche Nachricht bekommt – sei es die Frau, die Kids oder man selbst. Dazu kommen noch kritische Benachrichtigungen, die extra Aufmerksamkeit erfordern. Ich habe eine Lösung entwickelt, mit der du das Ganze zentral steuern kannst. Selbst wenn sich Geräte ändern, musst du nicht stundenlang deine Automatisierungen anpassen.
Um das Skript einzufügen, begib dich zu Home Assistant Skripte , lege eine neues Skript an und wähle über die drei Punkte in der rechten oberen Ecke die YAML Bearbeitung aus. Dort kannst du das unten aufgeführte Skript dann einfügen. Wichtig ! Die Dienstnamen für die Benachrichtigungen der Alexa-Media Player Devices oder auch Mobile Geräte müssen in der Variable „targets“ angepasst werden.
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
sequence:
- variables:
push_data: |-
{% if critical %}{
"push": {
"sound": {
"name": "default",
"critical": 1,
"volume": 1.0
}
}
}{% else %}{}{% endif %}
alias: push_data Variable, um den Channel "Critical" beim Iphone zu abonnieren
- variables:
targets: |-
{% set t = [] %}
{% if group_admins %}
{% set t = t + ["notify.mobile_app_iphone_tobias"] %}
{% endif %}
{% if group_family %}
{% set t = t + ["notify.mobile_app_iphone_tobias", "notify.mobile_app_slerch","notify.alexa_media_bad_oben"] %}
{% endif %}
{% if alexa %}
{% set t = t + ["notify.alexa_media_keller"] %}
{% endif %}
{{ t | unique | list }}
alias: targets für alle gewünschten "notify" Dienste
- variables:
alexa_devices: "{{ targets | select('search', 'notify.alexa_media') | list }}"
alias: "alexa_devices : Filter um nur die alexa Devices für den Dienst zu filtern"
- variables:
media_players: >
{% set media_players = alexa_devices |map('replace',
'notify.alexa_media_', 'media_player.')| list %}{{ media_players }}
alias: >-
media_players: Aus dem Dienst werden automatisch alle Media_Player
Entitätsnamen abgeleitet.
- variables:
volume_level: |
{% if critical %}
0.8
{% else %}
0.2
{% endif %}
alias: >-
volume_level: Wenn critical aktiviert ist, wir eine andere Lautstärke
gewählt , anonsten default für die Ausgabe
- repeat:
for_each: "{{ media_players }}"
sequence:
- action: media_player.volume_set
metadata: {}
data:
volume_level: "{{ volume_level }}"
target:
entity_id: "{{ repeat.item }}"
enabled: true
- repeat:
sequence:
- action: "{{ repeat.item }}"
data:
title: "{{ title }}"
message: "{{ message }}"
data: "{{ push_data }}"
for_each: "{{ targets }}"
enabled: true
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- repeat:
for_each: "{{ media_players }}"
sequence:
- action: media_player.volume_set
metadata: {}
data:
volume_level: 0.1
target:
entity_id: "{{ repeat.item }}"
enabled: true
- action: persistent_notification.create
metadata: {}
data:
message: "{{ targets }}"
alias: Notify All V2
description: ""
fields:
message:
selector:
text:
multiline: true
name: message
title:
selector:
text: null
name: title
group_admins:
selector:
boolean: {}
name: group_admins
required: true
group_family:
selector:
boolean: {}
name: group_family
required: true
critical:
selector:
boolean: {}
name: critical
required: true
alexa:
selector:
boolean: {}
name: alexa
required: true
sequence:
- variables:
push_data: |-
{% if critical %} {
"push": {
"sound": {
"name": "default",
"critical": 1,
"volume": 1.0
}
}
} {% else %} {} {% endif %}
alias: push_data Variable, um den Channel "Critical" beim Iphone zu abonnieren
- variables:
targets: |-
{% set t = [] %}
{% if group_admins %}
{% set t = t + ["notify.mobile_app_iphone_tobias"] %}
{% endif %}
{% if group_family %}
{% set t = t + ["notify.mobile_app_iphone_tobias", "notify.mobile_app_slerch","notify.alexa_media_bad_oben"] %}
{% endif %}
{% if alexa %}
{% set t = t + ["notify.alexa_media_keller"] %}
{% endif %}
{{ t | unique | list }}
alias: targets für alle gewünschten "notify" Dienste
- variables:
alexa_devices: "{{ targets | select('search', 'notify.alexa_media') | list }}"
alias: "alexa_devices : Filter um nur die alexa Devices für den Dienst zu filtern"
- variables:
media_players: >
{% set media_players = alexa_devices | map('replace',
'notify.alexa_media_', 'media_player.') | list %} {{ media_players }}
alias: >-
media_players: Aus dem Dienst werden automatisch alle Media_Player
Entitätsnamen abgeleitet.
- variables:
volume_level: |
{% if critical %}
0.8
{% else %}
0.2
{% endif %}
alias: >-
volume_level: Wenn critical aktiviert ist, wir eine andere Lautstärke
gewählt , anonsten default für die Ausgabe
- repeat:
for_each: "{{ media_players }}"
sequence:
- action: media_player.volume_set
metadata: {}
data:
volume_level: "{{ volume_level }}"
target:
entity_id: "{{ repeat.item }}"
enabled: true
- repeat:
sequence:
- action: "{{ repeat.item }}"
data:
title: "{{ title }}"
message: "{{ message }}"
data: "{{ push_data }}"
for_each: "{{ targets }}"
enabled: true
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- repeat:
for_each: "{{ media_players }}"
sequence:
- action: media_player.volume_set
metadata: {}
data:
volume_level: 0.1
target:
entity_id: "{{ repeat.item }}"
enabled: true
- action: persistent_notification.create
metadata: {}
data:
message: "{{ targets }}"
alias: Notify All V2
description: ""
fields:
message:
selector:
text:
multiline: true
name: message
title:
selector:
text: null
name: title
group_admins:
selector:
boolean: {}
name: group_admins
required: true
group_family:
selector:
boolean: {}
name: group_family
required: true
critical:
selector:
boolean: {}
name: critical
required: true
alexa:
selector:
boolean: {}
name: alexa
required: true
sequence:
- variables:
push_data: |-
{% if critical %} {
"push": {
"sound": {
"name": "default",
"critical": 1,
"volume": 1.0
}
}
} {% else %} {} {% endif %}
alias: push_data Variable, um den Channel "Critical" beim Iphone zu abonnieren
- variables:
targets: |-
{% set t = [] %}
{% if group_admins %}
{% set t = t + ["notify.mobile_app_iphone_tobias"] %}
{% endif %}
{% if group_family %}
{% set t = t + ["notify.mobile_app_iphone_tobias", "notify.mobile_app_slerch","notify.alexa_media_bad_oben"] %}
{% endif %}
{% if alexa %}
{% set t = t + ["notify.alexa_media_keller"] %}
{% endif %}
{{ t | unique | list }}
alias: targets für alle gewünschten "notify" Dienste
- variables:
alexa_devices: "{{ targets | select('search', 'notify.alexa_media') | list }}"
alias: "alexa_devices : Filter um nur die alexa Devices für den Dienst zu filtern"
- variables:
media_players: >
{% set media_players = alexa_devices | map('replace',
'notify.alexa_media_', 'media_player.') | list %} {{ media_players }}
alias: >-
media_players: Aus dem Dienst werden automatisch alle Media_Player
Entitätsnamen abgeleitet.
- variables:
volume_level: |
{% if critical %}
0.8
{% else %}
0.2
{% endif %}
alias: >-
volume_level: Wenn critical aktiviert ist, wir eine andere Lautstärke
gewählt , anonsten default für die Ausgabe
- repeat:
for_each: "{{ media_players }}"
sequence:
- action: media_player.volume_set
metadata: {}
data:
volume_level: "{{ volume_level }}"
target:
entity_id: "{{ repeat.item }}"
enabled: true
- repeat:
sequence:
- action: "{{ repeat.item }}"
data:
title: "{{ title }}"
message: "{{ message }}"
data: "{{ push_data }}"
for_each: "{{ targets }}"
enabled: true
- delay:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- repeat:
for_each: "{{ media_players }}"
sequence:
- action: media_player.volume_set
metadata: {}
data:
volume_level: 0.1
target:
entity_id: "{{ repeat.item }}"
enabled: true
- action: persistent_notification.create
metadata: {}
data:
message: "{{ targets }}"
alias: Notify All V2
description: ""
fields:
message:
selector:
text:
multiline: true
name: message
title:
selector:
text: null
name: title
group_admins:
selector:
boolean: {}
name: group_admins
required: true
group_family:
selector:
boolean: {}
name: group_family
required: true
critical:
selector:
boolean: {}
name: critical
required: true
alexa:
selector:
boolean: {}
name: alexa
required: true
Folgende Videos kann ich dir als Grundlagenvideos zum Thema Notifications noch empfehlen.