Skip to content

Instantly share code, notes, and snippets.

@RoboMagus
Created April 8, 2022 09:33
Show Gist options
  • Save RoboMagus/68c274eef16bf0033c3589f7e8f5cde3 to your computer and use it in GitHub Desktop.
Save RoboMagus/68c274eef16bf0033c3589f7e8f5cde3 to your computer and use it in GitHub Desktop.
HASS automation to forward persistent notifications to Phone
- id: 'forward_persistent_notifications'
alias: Forward persistent notifications to Admin
mode: parallel
max: 5
trigger:
- platform: event
id: 'create'
event_type: call_service
event_data:
domain: persistent_notification
service: create
- platform: state
id: 'invalid_config'
entity_id: persistent_notification.invalid_config
to: "notifying"
- platform: state
id: 'config_entry_reconfigure'
entity_id: persistent_notification.config_entry_reconfigure
to: "notifying"
- platform: state
id: 'config_entry_discovery'
entity_id: persistent_notification.config_entry_discovery
to: "notifying"
- platform: state
id: 'http_login'
entity_id: persistent_notification.http_login
to: "notifying"
condition: []
action:
- alias: "Set variables"
variables:
# Set data source for 'title' & 'message'
source: >
{%- if trigger.id == 'create' -%}
{{trigger.event.data.service_data}}
{%- else -%}
{{trigger.to_state.attributes}}
{%- endif -%}
notification_id: >
{%- if trigger.id == 'create' -%}
{{trigger.event.data.service_data.notification_id}}
{%- else -%}
{{trigger.id}}
{%- endif -%}
- service: script.notify_admin
data:
title: "Persistent: {{ source.title }}"
message: "{{ source.message }}"
data:
importance: high
priority: high
ttl: 0
sticky: 'true'
color: '#8a00e6'
persistent: true
channel: HASS_Persistent_Forward
tag: "persistent_{{notification_id}}"
actions:
- action: dismiss_persistent_notification
title: "DISMISS"
- id: 'forward_dismissed_persistent_notifications'
alias: Forward dismissed persistent notification
description: ''
mode: parallel
max: 5
trigger:
- platform: event
event_type: call_service
event_data:
domain: persistent_notification
service: dismiss
condition: []
action:
- service: script.notify_admin
data:
title: ""
message: "clear_notification"
data:
tag: "persistent_{{trigger.event.data.service_data.notification_id}}"
- id: 'forwarded_persistent_notifications_dismiss'
alias: Dismiss persistent notification from forward
description: ''
trigger:
- platform: event
event_type: mobile_app_notification_action
event_data:
action: dismiss_persistent_notification
condition: []
action:
- service: persistent_notification.dismiss
data:
notification_id: "{{ trigger.event.data.tag[11:] }}"
- service: script.notify_admin
data:
title: ""
message: "clear_notification"
data:
tag: "{{ trigger.event.data.tag }}"
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment