Hello all, I created a “messaging” script. Basically I have a helper that I can turn critical alerts for certain messages on or off. Instead of writing the if / then / else script in every automation, I figure i’d create a script that the automation can call. Here is the code of the script:
alias: SendNotification
description: Sends notifications to groups, checks if critical nor not
fields:
title:
description: Title of notification
MessageToSend:
description: Actual message
group:
description: What messaging group
sequence:
- if:
- condition: state
entity_id: input_boolean.critical_alerts
state: "on"
then:
- service: "{{ group }}"
data:
message: "{{ message }}"
title: "{{ title }}"
data:
push:
sound:
name: default
critical: 1
volume: 1
else:
- service: "{{ group }}"
data:
message: "{{ message }}"
title: "{{ title }}"
mode: parallel
max: 10
This is one of my automations:
alias: Home Assistant Start Notification
description: ""
trigger:
- platform: homeassistant
event: start
condition:
- condition: state
entity_id: input_boolean.critical_alerts
state: "on"
action:
- service: script.sendnotification
data:
title: Malta
MessageToSend: Home assistant has started and running stable!
group: notify.critical_notification_group
mode: single
It’s sending the critical alert correctly when the helper is on, but the “message” isn’t showing up. The alert comes up with the title but blank message. I think it’s because the string for {MessageToSend} should be in quotes in the automation. I do that, and after I save it, the quotes are automatically removed. Am I missing something?
Thanks!