Help with automation.yaml basic configuration

Hi, I’m trying to get the correct way to indicate which sensors in a list are on. This is my current config, which works to notify me via text and email. However, it states now that water has been detected but not which sensor name. How do I get the sensor(s) name(s) listed on the message portion?

- id: '1593798226108'
  alias: WaterNotify
  description: Notifies via text and email of water detection
  trigger:
  - entity_id: sensor.1_MasterBedToilet
    from: 'off'
    platform: state
    to: 'on'
  - entity_id: sensor.2_MasterBedSink
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data:
      message: water detected!
    service: notify.floodalert

That’ll be with templating:

  action:
  - data_template:
      message: "water detected by {{ trigger.name }}!"
    service: notify.floodalert

wow, i knew it would be something easy. Very sorry, pretty newbie. However, I did manage to make my own water sensor (with the help of the internet) using an ESP8266 and MQTT so not so bad. THANK YOU SO MUCH.

I use

    action:
      - service: notify.email
        data_template:
          title: 'Water Alert!'
          message: 'Water detected by the {{ trigger.to_state.attributes.friendly_name }} sensor!'

but I wonder if trigger.name and the trigger to/from state’s attributes.friendly_name would be defined in all cases.

Ok, this one didn’t work. Sorry, should have tried it first. It says water detected by ! and no name comes up

This worked:

action:
  - data_template:
      message: "water detected by {{ trigger.entity_id }}!"
    service: notify.floodalert

Thanks for sharing!

Here’s a little hint for setting up these things and experimenting with the templates: Output a persistent notification until you’re satisfied, then change it to a real notification.
The benefit is you’ll only have to reload your automations and see the message immediately pop up within your HA’s “Notification” area!

Example:

    action:
      - service: persistent_notification.create
        data_template:
          title: 'Water Alert!'
          message: >
            trigger.from_state.attributes.friendly_name: {{ trigger.from_state.attributes.friendly_name ~ '\n' }}
            trigger.to_state.name: {{ trigger.to_state.name ~ '\n' }}
            trigger.to_state.attributes.friendly_name: {{ trigger.to_state.attributes.friendly_name ~ '\n' }}
            trigger.entity_id: {{ trigger.entity_id ~ '\n' }}
            {{ '\n' }}
            Alert! The {{ trigger.to_state.name }} triggered at {{ as_timestamp(trigger.to_state.last_changed) | timestamp_custom() }}!

This shows some of the trigger info you could use.

The added '\n' are just to force line breaks in the notification area.

The last line shows how to get the time when it was triggered (in UTC) and how to convert that to your local time.

Here’s how the above looks:
Screenshot_2020-07-04 Overview - Home Assistant