๐ฒ Centralized Notifications โ
A unified notification script for Home Assistant (mode: parallel) that routes messages to mobile push, persistent UI notifications, and Telegram, adapting Markdown formatting per channel.
โ๏ธ Parameters โ
| Field | Selector | Required | Default | Description |
|---|---|---|---|---|
canali_notifica | select | Yes | push, home_assistant | Delivery channels (push, home_assistant, telegram). |
tutti_i_dispositivi | boolean | No | true | When true, sends push via notify.notify; when false, uses selected devices. |
destinatari_specifici | entity | No | One or more notify entities to target when tutti_i_dispositivi is false. | |
title | text | Yes | Main title shown at the top of the notification. | |
message | text | Yes | Notification body text (supports Markdown). | |
notification_id | text | No | Optional persistent notification ID to overwrite earlier alerts of the same type. |
๐ How It Works โ
- Mobile Push (
push): strips Markdown syntax (**,*,_,#) before sending either globally vianotify.notifyor per device vianotify.mobile_app_<device>. - Home Assistant UI (
home_assistant): creates apersistent_notificationkeeping native Markdown intact, usingnotification_idonly when provided. - Telegram (
telegram): sends viatelegram_bot.send_messagewithparse_mode: markdownv2and automatic regex escaping of special characters.
๐งช Example Call โ
yaml
action: script.gestione_notifiche_centralizzata
data:
canali_notifica:
- push
- home_assistant
tutti_i_dispositivi: true
title: "โ ๏ธ Dishwasher Alert"
message: "The **salt** is empty!"
notification_id: dishwasher_status๐ Full Script YAML โ
Import in Home Assistant
Go to Settings -> Automations & Scenes -> Scripts -> Add Script -> Edit in YAML and paste the configuration below. Use the language selector to switch between English and Italian.
alias: ๐ฒ Centralized Notifications Manager
description: >-
### ๐ฒ Unified Notifications Script
Centralized script for sending notifications.
Handles global broadcasts or targeted delivery to dynamically filtered
devices, stripping Markdown formatting for mobile push notifications.
mode: parallel
fields:
canali_notifica:
name: ๐ Notification Channels
description: >-
๐ Select the channels to send the notification through (multiple
allowed).
required: true
default:
- push
- home_assistant
selector:
select:
multiple: true
options:
- label: ๐ฑ Push Notification (Mobile App)
value: push
- label: ๐ฅ๏ธ Persistent Notification (HA UI)
value: home_assistant
- label: โ๏ธ Telegram
value: telegram
tutti_i_dispositivi:
name: ๐ฅ Send to All Devices
description: >-
๐ฅ When enabled, push notifications are sent to all registered devices.
When disabled, uses the list below.
required: false
default: true
selector:
boolean: {}
destinatari_specifici:
name: ๐ฏ Specific Devices
description: >-
๐ฑ Select one or more smartphones/services to notify (only applies when
'Send to All Devices' is disabled).
required: false
selector:
entity:
domain: notify
multiple: true
title:
name: โจ Notification Title
description: โจ Main title shown at the top of the notification.
example: โ ๏ธ Dishwasher Alert
required: true
selector:
text: {}
message:
name: ๐ Notification Message
description: โจ Body text of the notification (may include Markdown).
example: The **salt** is empty!
required: true
selector:
text: {}
notification_id:
name: ๐ Persistent Notification ID
description: >-
๐ Unique ID for the persistent notification (optional). Useful for
overwriting previous notifications of the same type.
example: dishwasher_status
required: false
selector:
text: {}
sequence:
- alias: ๐ฑ Check and Send Push Notification
note: >-
Checks whether the 'push' channel is enabled before resolving delivery
targets.
if:
- condition: template
value_template: '{{ ''push'' in canali_notifica }}'
alias: '๐ Check channel: Push'
note: Checks the channels array for the 'push' value.
then:
- alias: ๐ Select Push Target
note: >-
Sends to all devices or iterates over the specified targets.
choose:
- alias: '๐ฅ Case 1: Global Broadcast'
note: >-
Sends a broadcast via notify.notify when the boolean is set to
true.
conditions:
- condition: template
value_template: '{{ tutti_i_dispositivi }}'
alias: 'Check: Send to all devices = True'
sequence:
- action: notify.notify
data:
title: >-
{{ title | regex_replace(find='\*\*|\*|_|###\s|##\s|#\s',
replace='', ignorecase=True) }}
message: >-
{{ message | regex_replace(find='\*\*|\*|_|###\s|##\s|#\s',
replace='', ignorecase=True) }}
alias: ๐ Send Group Push
note: >-
Immediately notifies all devices connected to the Home
Assistant hub.
- alias: '๐ฏ Case 2: Targeted Delivery'
note: >-
Loops through the specific notify services selected in the array.
conditions:
- condition: template
value_template: >-
{{ not tutti_i_dispositivi and destinatari_specifici is
defined and destinatari_specifici | length > 0 }}
alias: 'Check: Specific devices selected'
sequence:
- repeat:
for_each: '{{ destinatari_specifici }}'
sequence:
- action: notify.mobile_app_{{ repeat.item.split('.')[1] }}
data:
title: >-
{{ title |
regex_replace(find='\*\*|\*|_|###\s|##\s|#\s',
replace='', ignorecase=True) }}
message: >-
{{ message |
regex_replace(find='\*\*|\*|_|###\s|##\s|#\s',
replace='', ignorecase=True) }}
alias: ๐ Send Push to Single Target
note: >-
Dynamically builds the service name by prepending
mobile_app_ as required by the official Home Assistant
mobile app integration.
- alias: ๐ฅ๏ธ Check and Create Persistent Notification
note: >-
Checks whether the 'home_assistant' channel is enabled. The Home Assistant
UI supports Markdown natively.
if:
- condition: template
value_template: '{{ ''home_assistant'' in canali_notifica }}'
alias: '๐ Check channel: Home Assistant'
note: Checks the channels array for the 'home_assistant' value.
then:
- alias: ๐ Select Persistent Notification Payload
note: >-
Handles the presence or absence of the optional notification_id to
avoid dictionary key errors.
choose:
- alias: '๐ Case A: With Specified ID'
note: Runs when a notification ID has been provided.
conditions:
- condition: template
value_template: >-
{{ notification_id is defined and notification_id != '' and
notification_id != none }}
sequence:
- action: persistent_notification.create
data:
title: '{{ title }}'
message: '{{ message }}'
notification_id: '{{ notification_id }}'
alias: ๐ Create Notification with Static ID
- alias: '๐ฒ Case B: Without Specified ID'
note: >-
Runs when the ID field is empty, omitting the key from the data
payload.
conditions:
- condition: template
value_template: >-
{{ notification_id is not defined or notification_id == '' or
notification_id == none }}
sequence:
- action: persistent_notification.create
data:
title: '{{ title }}'
message: '{{ message }}'
alias: ๐ Create Notification with Random ID
- alias: โ๏ธ Check and Send Telegram Message
note: >-
Checks whether the 'telegram' channel is enabled and applies Telegram
MarkdownV2 escaping.
if:
- condition: template
value_template: '{{ ''telegram'' in canali_notifica }}'
alias: '๐ Check channel: Telegram'
note: Checks the channels array for the 'telegram' value.
then:
- alias: ๐ Send Telegram with Parser
note: >-
Sends the message to Telegram after escaping special characters for
MarkdownV2.
action: telegram_bot.send_message
data:
title: >-
{{ title |
regex_replace(find='([_\\*\\`\\[\\]\\(\\)\\~\\>\\#\\+\\-\\=\\|\\{\\}\\.\\!])',
replace='\\\\\\1', ignorecase=True) }}
message: >-
{{ message |
regex_replace(find='([_\\*\\`\\[\\]\\(\\)\\~\\>\\#\\+\\-\\=\\|\\{\\}\\.\\!])',
replace='\\\\\\1', ignorecase=True) }}
parse_mode: markdownv2