Trigger specific IMAP Email Content subject text?

Hey everyone. I got the IMAP email sensor working and triggering off of a email subject line currently. It works, I get my specific email, and it triggers my TTS and lights.

I’m now trying to get it to read only specific parts of that email subject line. Basically, I get sales online, and I want it to read the 5th word in the email subject line, through the text to speech saying the amount. Currently I can get it to read the entire subject line, but it also read the order number on the end and kind of ruins it. Also, I’d like to trigger specific subject text from another email so…

Here is what I got so far. Hopefully someone can push me in the right direction, I’m fairly new to it all.

platform: imap_email_content
port: 993
username: user
password: pass
- [email protected]
value_template: “{{ subject }}”
Which then triggers an automation

id: sale_test
platform: state
entity_id: sensor.bassnaha

  • service: tts.google_say
    entity_id: media_player.living_room_home
    message: >
    ‘{{ [""{{ states.sensor.bassnaha.state }}"] }}’
    cache: true

This is how I have it set up to read the subject line of the email on text to speech, which like I mentioned is cool, except I don’t want it reading the last ‘word’ of the subject. Any advice? Thanks

I’m afraid I can’t offer much help, but I do have a similar problem. Hopefully with both of us on here, we’ll be more likely to get a response.

I’m trying to pull in sensor info from a proprietary alarm system. No possibility for an MQTT solution, but will send text and email notification for all the sensor data with no more than a few seconds delay in most cases. For what I’m trying to do, that delay would not be a show stopper.

Since I had to remove most security other than username and password to use this, I set up a dedicated google apps email account just for this purpose. For test of concept, I tried to set up the downstairs motion sensor. My intent was to have the value_template look for the words “Downstairs Motio” (misspelled in the database and I haven’t corrected it) in the subject line. The problem is that it always comes through with a time stamp, so I have to look for “Downstairs Motio” within a bunch of other text that’s dynamic. Although it doesn’t error out in a configuration check, I’m getting nothing but “unknown” when I test.

I’m not married to using this methodology to get my sensor data out of If there’s a better way with Notifications, I’m up for that too.

Here’s my configuration.yaml:

# Downstairs hallway motion sensor triggered
  - platform: imap_email_content
    name: downstairs_motion
    port: 993
    username: !secret gmail_username
    password: !secret gmail_password
    senders: [email protected]
    value_template: >-
      {% if states.sensor.downstairs_motion %}
          {{ states.sensor.downstairs_motion.attributes.subject }}
      {% else %}
      {% endif %}

I also tried a variation of this with no luck either:

  value_template: >-
    {% if states.sensor.downstairs_motion.attributes.subject.find("Downstairs Motio") | int >= 0 %}
    {% else %}
    {% endif %}

try use something like this to show last 5 symbols from end {{ states.sensor.bassnaha.state[-5:] }} im sure you can omit what you don’t need and vice versa