Using a Script to Send Notifications

As I am relativly new to Home Assistant, I use notification to my phone through the companion app to notify me when events happen, eg. the time and light level when my smart blids closes, time and temp when my heating turns on and turns off etc. This means I have a number of notifications calls across numerous automations, some times I may use a common notification for multiple automations. If I change have to change a common messge I have to make the change in numerous automations.

I have been experimenting with a script which contains all the different messages, and each automation calls the script, passing a variable to define which message to use. The scipt is being called but I get no notification. My code is:

Automation that calls the script

alias: heating_set-default-temp2
description: ""
triggers: null
actions:
  - data:
      entity_id: climate.thermostat_thermostat
      temperature: 5
    action: climate.set_temperature
  - data:
      variables:
        message_type: heating_default
    action: script.notifications_send_message

Called Script

alias: notifications_send-message
sequence:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ message_type == 'heating_default' }}"
        sequence:
          - data:
              message: >
                Current thermostat temperature is {{
                state_attr('climate.thermostat_thermostat',
                'current_temperature') }}°C. Heating turned on at {{
                now().strftime('%H:%M') }} and set to default temp
            action: notify.mobile_app_ my_phone
          - data:
              message: test message
            action: notify.mobile_app_my_phone
description: ""

As i say I new to Home assistant so my code maybe incorrect, but would appreciate some pointers if someone could help.

Thanks in advance
Adrian

Look at the trace output of both your automation and your script. It should give you useful info.

@jeffcrum Thanks for the reply, I will investigate post for review what i find

1 Like