Send notification when sensor value changes

I’m trying to make HA send me an notification as soon as a specific sensor value changes.

The sensor I’m using is the IMAP Email Content sensor.

So I would like to send an HTML5 notification as soon as the state changes (new email arrives), and the notification should include
Subject
state (body from email)
Date

I tried building an automation based on state_changed event, but it wont pass config check

- id: automation 66
  alias: 'New Email'
  trigger:
    platform: event
    event_type: state_changed
    entity_id: 'sensor.martikainen87gmailcom'
  action:
    service: notify.html5
    data:
      message: 'New email:  Subject, body, date ata bla bla'
      target: 'mattias'

Of course this automation needs some data_template fix, but the big issue is finding out how i can trigger an automation as soon as the sensor updates it’s values, on regular notifications i can always use the change state from “on” to “off” etc, but this state is always different since it contains the body from the email.

Seems like I got it working, but there are some issues with the imap sensor, it looks like it will read through my entire gmail inbox as soon as i restart HA.

this is the automation that worked, seems like I didnt need the state_changed parameter.

- id: automation 67
  alias: "New Email"
  trigger:
  - platform: state
    entity_id: sensor.martikainen87gmailcom
  action:
    service: notify.html5
    data_template:
      message: '{{ states.sensor.martikainen87gmailcom.state }}'
      target: mattias

So far I’m only getting the body, but thats fine for now. Need to see if I can get it to not read all emails, since I only want to know what the latest email is.
And if you wonder why I’m not just using the email for notifications, I use it for a device within my home automation and want to gather everything in HA :slight_smile: Might need to trigger other stuff than notifications in the future for this one.