Help with imap template please

YAML & templating does take a while to get one’s head around. But eventually they’ll sink in.

You can certainly use two sensors – one that provides all the data for the most recently received e-mail, and the other that extracts a useful tidbit from the detail. However, if that’s all you’ll ever want, then you can just do it in the one sensor. Depends on what you want to do. E.g., you could just do this:

sensor:
  - platform: imap_email_content
    server: mail.server
    port: 993
    username: [email protected]
    password: 12345678
    name: smarthours_price
    senders:
      - [email protected]
    value_template: "{{ body|regex_findall_index('(\d+)\s+cents') }}"

Thank you sir! This is what ended up working for me.

sensor:
  - platform: imap_email_content
    server: mail.server
    port: 993
    username: [email protected]
    password: 12345678
    name: Smarthours Email
    senders:
      - [email protected]
    value_template: >
     {{ body|regex_findall_index('(\d+)\s+cents') }}
2 Likes

I am stuck on something that is probably really simple too. I haven’t quite got my head around templates yet.

This always returns Unknown from voicemail_alert. Could anyone possibly nudge me in the right direction?

- platform: imap_email_content
  server: imap.gmail.com
  name: voicemail_alert
  port: 993
  scan_interval: 600
  folder: inbox
  username: !secret notify_google_user
  password: !secret notify_google_pass
  senders:
    - [email protected]
  value_template: >-
    {% if 'New voicemail from' in subject %}
      New Voicemail
    {% else %}
      You should not be seeing this
    {% endif %}

@Kayhold Are you using a Gmail sensor with the Here Comes the Bus app? If so would you be willing to PM me and share your code?

I’m also getting the same result, the sensor just returns unknown no data at all.
I think this integration maybe broken

   - platform: imap_email_content
     server: imap.gmail.com
     name: water_use
     port: 993
     username: !secret gmailusr
     password: !secret gmail
     senders:
       - [email protected]

Unless there is a way we can query other attributes of an entity other than the state.

Never mind its working now, it appears it wont scrape old emails only new ones

now i just need to figure out my regex

Email Body

SARATOGA SPRINGS CITY AN ALLOCATION ALERT has been triggered based on your preferences. You have reached 108.59% of your allocation for the month. The alert has now been deactivated. To configure this alert again, please log on to https://MYWATER.SARATOGASPRINGSCITY.COM. Thank you!

  - platform: template
    sensors:
      secondary_use:
        friendly_name: Secondary Water Use
        value_template: >
          {{ state_attr('sensor.water_use', 'body')
             |regex_findall_index("\d+([,.]\d{1,9})?[$%]") }}

email sensor data

from: [email protected]
subject: SARATOGA SPRINGS WATER ALERTS
date: Wed, 14 Jul 2021 10:30:07 -0600
body: “SARATOGA SPRINGS CITY AN ALLOCATION ALERT has been triggered bas=\r\ned on your preferences. You have reached 108.59% of your allocat=\r\nion for the month. The alert has now been deactivated. To config=\r\nure this alert again, please log on to https://MYWATER.SARATOGASP=\r\nRINGSCITY.COM. Thank you!\r\n\r\n”
friendly_name: water_use

the secondary water sensor only pulls the digits after the .
image