IMAP gmail reading sending me unknown value

Hi i followed a guide to setup a IMAP integration to read my gmail but it return unknown information and i don’t know what i did wrong in the config file, for the test i send myself a email so the sender is my email with energy: 80kWh in the body, so the code should return 80 but i got unknown value… I also already set my gmail with the APP password.

sensor:
- platform: imap_email_content
  server: imap.gmail.com
  name: energy_gmail
  port: 993
  username: myemail
  password: -------------
  senders: 
    - no-myemail
  value_template: body
  
template:
- sensor:
  - name: "Energy Use"
    unit_of_measurement: "kWh"
    state: >
       {{ state_attr('sensor.energy_gmail','body')
         | regex_findall_index("\*energy:\* ([0-9]+) kWh") }}
   

   


ENERGY USE

Thanks you very much!

What is the state and attributes of sensor.energy_gmail?
Open your Home Assistant instance and show your state developer tools.

Your regex will only match '*energy:* 123 kWh'. It wont match any of these:

energy: 123 kWh
*energy:*123 kWh
*energy:* 123kWh

i tried with ‘energy: 80 kWh’ with no succes :confused:

You are showing the state of the template sensor, not the original email content sensor.

Your regex won’t match energy: 80 kWh. You’ll need to modify it if you want to use that format:

template:
- sensor:
  - name: "Energy Use"
    unit_of_measurement: "kWh"
    state: >
       {{ state_attr('sensor.energy_gmail','body')
         | regex_findall_index("energy: ([0-9]+) kWh") }}

Ok i change the format to use my initial email content sensor but am missing something… it still doesn’t work …

sensor:
- platform: imap_email_content
  server: imap.gmail.com
  name: energy_gmail
  port: 993
  username: myemail
  password: -------------
  senders: 
    - no-myemail
  value_template: >
    {{ state_attr('sensor.energy_gmail','body')
     | regex_findall_index("energy: ([0-9]+) kWh") }}

I’m sorry, but I can’t help you debug your template if you don’t show me the state of sensor.energy_gmail, or at least it’s body attribute.
sensor.energy_use does not work, so it’s state is useless at this point.

this?

I only have: friendly_name: energy_gmail

Ok, so your template sensor might actually be working, but the imap_email_content sensor isn’t.

Your probably wanted

  value_template: '{{ body }}'

However, that most likely isn’t the cause of your problems.
Check your logs to see if there are any errors.
Make sure the address you set in senders: is the address from which the e-mail is sent.

1 Like

It did actually fix the problem! thanks you very much!!!