Automation not triggering when using data_template

I setup HA automation to trigger when a ping binary sensor goes from On to Off. When I setup the automation.yaml with static text in the message field the trigger generates an e-mail.

This configuration works:

- alias: MonitorDevice
  trigger:
    - platform: state
    entity_id: binary_sensor.samsung_printer
    from: 'on'
    to: 'off'
  action:
    - service: notify.email_greg
    data:
      message: "Device"
      title: "Device"

When I change data to data_template so I can pass in the entity name, the e-mail fails to be sent

- alias: MonitorDevice
  trigger:
    - platform: state
    entity_id: binary_sensor.samsung_printer
    from: 'on'
    to: 'off'
  action:
    - service: notify.email_greg
    data_template:
      message: "{{ trigger.entity_id }}"
      title: "Device"

This error is in the log:

Invalid service data for notify.email_greg: required key not provided @ data['message']. Got None

Any ideas? I’m running HA 0.62.1 on a Pi3 using raspbian

- alias: MonitorDevice
  trigger:
    - platform: state
    entity_id: binary_sensor.samsung_printer
    from: 'on'
    to: 'off'
  action:
    - service: notify.email_greg
    data_template: "{{ {'message': trigger.entity_id, 'title':'Device'} }}"

The whole template needs to be a dictionary.

Actually, I might be wrong. Your method should work. It’s possible that the trigger does not contain an entity_id, and it is returning None.

Also, your spacing is odd, it should look more like this:

- alias: MonitorDevice
  trigger:
    - platform: state
      entity_id: binary_sensor.samsung_printer
      from: 'on'
      to: 'off'
  action:
    - service: notify.email_greg
      data_template:
        message: "{{ trigger.entity_id }}"
        title: "Device"

+1 for @petro solution. Starting from data_template down, add two extra spaces