notify.SMTP service data set based on trigger

Hey all,

I set up the following “Vacation Mode” automation. It works to send me an email:

# Vacation Mode
# Send an alert (currently email) on the state change of any of the following:
# Garage door, front door, front deadbolt.
- id: 'vacation_mode'
  alias: Notifications for door activity
  trigger: 
    - platform: state
      entity_id: lock.schlage_be469_touchscreen_deadbolt_locked
    - platform: state
      entity_id: binary_sensor.neo_coolcam_doorwindow_detector_sensor
    - platform: state
      entity_id: sensor.garage_door_status
  condition:
  - condition: state
    entity_id: input_boolean.vacation_mode
    state: 'on'
  action:
  - alias: 'Send an email'
    service: notify.gmail
    data: 
      title: '[Home Assistant] Vacation Mode Alert!'
      message: 'One of the following changed state: garage door, front door lock, front door.'

I would like to dynamically change the title and message attributes of the data sent to notify.gmail service based on the trigger. So for example, if sensor.garage_door_status changed from Open to Closed, I would like the title to read “[Home Assistant] Vacation Mode Alert: Garage Door” and the message to read “Garage door changed state from Closed to Open”

Is that possible?
How?

Thanks in advance!

I believe that the following should do this:

# Vacation Mode
# Send an alert (currently email) on the state change of any of the following:
# Garage door, front door, front deadbolt.
id: 'vacation_mode'
  alias: Notifications for door activity
  trigger: 
    - platform: state
      entity_id: lock.schlage_be469_touchscreen_deadbolt_locked
    - platform: state
      entity_id: binary_sensor.neo_coolcam_doorwindow_detector_sensor
    - platform: state
      entity_id: sensor.garage_door_status
  condition:
  - condition: state
    entity_id: input_boolean.vacation_mode
    state: 'on'
  action:
  - alias: 'Send an email'
    service: notify.gmail
    data_template: 
      title: '[Home Assistant] Vacation Mode Alert!: "{{ trigger.from_state.name }}"'
      message: '"{{ trigger.from_state.name }}" changed state from "{{ trigger.from_state.state }}" to "{{ trigger.to_state.state }}".' 

Also see:

and

1 Like

So simple! Thank you. And thank you for the link to Automation Templating – that looks like a big piece I was missing.