Passing variable variable to a script

Hello,

I’m trying to pass the friendly name of a trigger to a script to use it in a pushbullet notification like this:

Automation:

  • alias: ‘Motion volledig’
    hide_entity: True
    trigger:
    • platform: state
      entity_id:
      • sensor.living_burglar_2_10
      • sensor.salon_burglar_6_10
      • sensor.keuken_burglar_7_10
      • sensor.overloop_burglar_5_10
        state: ‘8’
        condition:
    • condition: state
      entity_id: input_boolean.alarm_state
      state: ‘on’
      action:
    • service: script.alarm_lights_script
      data:
      title: “!! ALARM !!”
      message: “{{ trigger.to_state.attributes.friendly_name }}”

Script:

alarm_lights_script:
alias: Alarm TEST
sequence:
- service: homeassistant.turn_on
entity_id: switch.rf_1
- delay: 00:00:10
- condition: or
conditions:
- condition: state
entity_id: input_boolean.alarm_state
state: ‘on’
- condition: state
entity_id: input_boolean.alarm_thuis_state
state: ‘on’
- service: notify.notify_erik
data_template:
title: “{{ title }}”
message: “{{ message }}”

It look’s like it’s not working like this. It works if I do this but I like to know whitch sensor is triggering the alarm:

action:
- service: script.alarm_lights_script
data:
title: “!! ALARM !!”
message: “motion”

Is there an other way to do this?

thx

Erik

You want “data_template” to let HA know that there’s a template to render.

service: script.alarm_lights_script
  data_template:
  title: "!! ALARM !!"
  message: "{{ trigger.to_state.attributes.friendly_name }}"

Also - when posting YAML, always use preformatted text so that we can help debug formatting issues.

Thank you for the help and sorry about the text.

Erik