Automation containing variable data

Hi all,
I am pretty new and am trying to customize an automation but would like a little guidance. I have a Konnected alarm system and would like to fire off one automation when any door or window is opened. Thats the part I know how to do. The difficult part for me is to fire off an email that contains variable data. So if Garage Door opens then the message should say Garage Door has been breached. If the Laundry room window is breached then the email should say Laundry Window has been breached. So what I am trying to figure out is in the “message:” section what should I have? Im thinking something like message: (@bianarysensor.open + “has been breached”) Im not a coder obviously but I think to those that are, you get my drift.
TIA,
Steve

Here’s the action portion of an automation that notifies me when my front door is unlocked. Perhaps this will help.

action:

  • service: notify.x_email
    data_template:
    title: Front Door
    message: ‘Front door unlocked by {{ states(’‘sensor.template_front_door_status’’)
    }} ’

So ill have to look into templates it seems, but to be clear, I am looking for the sensor that trips to be indicated in the message. Right now I have approximately 28 sensors. How many different states do you have? If its only 2 that might not be what I am looking for. Or am I missing something?
Thanks for the help,
Steve

In automations, the condition and action parts will have a variable automatically created named trigger that gives information about what actually triggered the automation. Look here.

So, e.g., you can do something like this:

automation:
  - alias: Example automation using trigger variable
    trigger:
      platform: state
      entity_id:
        - binary_sensor.door1
        - binary_sensor.door2
      to: 'on'
    action:
      service: notify.email
      data_template:
        message: "{{ state_attr(trigger.entity_id, 'friendly_name') }} was breached!"
1 Like

That did it! Thank you! I was banging my head there for a bit because a manual firing of the automation didnt work and yielded an error. After researching the error I found that a manual firing from the GUI would produce that error. I opened a door and viola! All is well.
Thanks again to both of you,
Steve

1 Like