I have this email, that has this exact data I am trying to pull into sensors for energy use and cost:
Latest Meter Reading: Saturday, March 1, 2025, 5:00 AM
Yesterday
Energy usage: 43 kWh
Estimated cost: $7
Last 2 Days
Energy usage: 97 kWh
Estimated cost: $15
My code (which is basically the same code example in the IMAP docs) seems to work for each sensor in the regex101 tester, but I get Unknown in the sensors. The email is showing up in the imap sensor as it should, but the individual kWh and Cost sensors are showing up as Unknown:
Tracked down the error I am seeing now on the sensors…it says:
Error rendering state template for sensor.yesterday_energy_use: IndexError: list index out of range
Error rendering state template for sensor.yesterday_cost: IndexError: list index out of range
Error rendering state template for sensor.billing_cycle_energy_use: IndexError: list index out of range
Error rendering state template for sensor.billing_cycle_cost: IndexError: list index out of range
That’s what’s reported when regex_findall_index fails to find a match. In other words, the regex pattern you created isn’t finding a match in the received string.
Be advised that regex_findall_index is unforgiving. If the match fails by even just one character the result will be an error message (and no way to suppress it without additional checking).