Messaging script I created isn't working right. Help!

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!

1 Like

In the script you Define MessageToSend, and refer to it from the calling script - but I don’t see anywhere where you’re associating MessageToSend to Message - what you refer to in the rest of your script as the message body?

Darn, I can’t believe I missed that. Before, in the script, I had “MessageToSend” as just “Message” and it wasn’t working. I thought maybe the problem was that “message” is a system term or whatever, so I changed it to “MessageToSend” and forgot to do the change you were refering to.

Anyways fixed, and works! thank you.

1 Like