Problem with IMAP after update to core-2022.3.5

Shortly after updating to core-2022.3.5, I am experiencing problems with an IMAP sensor. I only added this sensor ~5 days ago, but it’s been working fine until I updated HA & restarted the server…

Issue: my email sensor entity no longer exists (“entity not available”), looks like it doesn’t get created when HA starts up…

Searching the logs for “IMAP”, there is only one line: a warning, no error:

2022-03-16 16:10:09 WARNING (MainThread) [homeassistant.components.sensor] Platform imap not ready yet: None; Retrying in background in 30 seconds

the relevant section from configuration.yaml is:

sensor:

  • platform: imap
    name: emailsensor
    server: imap.gmail.com
    port: 993
    username: redacted
    password: redacted
    search:
    ‘X-GM-RAW “from:[email protected] newer_than:12h subject:Redacted Subject”’

I’m unsure what step to take next to troubleshoot this. Can anyone please advise?

1 Like

Its just a warning. Not an error.
It state it will retry, so have patience.

Thankyou. Though I am unsure that’s the case.

Normally, that sensor is available within a few minutes of rebooting, tops (I’ve actually never seen it unavailable before - I have a lovelace card that shows it’s status).

However, now it’s been 4 hours and counting. Surely that would be more than enough time? If not, how long would be a reasonable period to wait before considering it “broken”?

4 hours is too much, I would say.
Are there any other entries in the logs regarding the emailsensor?

No, nothing else in the logs at all (searching for “imap” or “emailsensor”)

Only thing is the one warning (singluar) Platform imap not ready yet: None; Retrying in background in 30 seconds. This warning appears once, after a reboot.

I will try recreate this sensor from scratch now, including generating a new Google Account App Passport…

I deleted the old AppPassword in my Google Account Security Settings, and generated a new App Password.

The pasted the new IMAP App Password into configuration.yaml.

The emailsensor is now working again.

(I’ve checked all my email, searching for any e.g “security check” emails from google, or anything at all, to indicate any form of issue - nothing found. And no messages in the HA logs to indicate what the problem might have been. All I know is it happened just after I updated core to the latest version)

Google is using some fingerprinting tricks to identify a connecting application and thereby prevent unauthorized access. The update to HA might have triggered a different fingerprint.

Mine did the same. I restarted HA and the issue went away as mysteriously as it began :slight_smile:

Thanks Wally, that would make sense.

Just FYI my “emailsensor” entity still exists, unlike before (I am assuming it is working, but I haven’t had any emails yet that trigger it).

But, just FYI, I am now seeing this warning in the log:

Logger: homeassistant.components.imap.sensor
Source: components/imap/sensor.py:182
Integration: imap (documentation, issues)
First occurred: 12:01:49 PM (19 occurrences)
Last logged: 8:29:24 PM

Lost imap.gmail.com (will attempt to reconnect)

I looked up IMAP.gmail.com on a website earlier and noticed that it redirected to mail.google.com
I do not know if that is temporary or permanent, but maybe try putting mail.google.com in for now and see if that solves the error.
If it does then the add-on does not handle redirections correctly.

1 Like

Roger that, thanks for the suggestion/

Have just made that change and rebooted - will report back in a day or so.

Changing server to mail.google.com seems to cause immediate failure after a reboot, and the sensor entity never gets created (left it for about an hour). Log:

Logger: homeassistant.components.sensor
Source: /usr/local/lib/python3.9/asyncio/events.py:80
Integration: Sensor (documentation, issues)
First occurred: 8:59:26 PM (2 occurrences)
Last logged: 8:59:44 PM

Setup of sensor platform imap is taking over 10 seconds.

Reverted back to imap.gmail.com, and it appears to be working (the next trigger email is due tomorrow), however, I do see the following warnings in the log:

Logger: homeassistant.components.imap.sensor
Source: components/imap/sensor.py:182
Integration: imap (documentation, issues)
First occurred: 3:43:52 PM (11 occurrences)
Last logged: 8:34:37 PM

Lost imap.gmail.com (will attempt to reconnect)

The lost message might just be that googles server closed the connection due to no activity.
Its just a guess, but I know many servers operate like that to save resources.

Did you figure out the underlying cause? I’ve been seeing this error hundreds of times in the logs since upgrading to Home Assistant 2022.7.0 a few days ago. Running 2022.7.3 now, and the problem is still there.

I see the same - on two different post (IMAP) servers:

2022-07-12T07:03:57.417762950Z 2022-07-12 09:03:57 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform imap is taking over 10 seconds.

2022-07-12T07:03:57.421190052Z 2022-07-12 09:03:57 WARNING (MainThread) [homeassistant.components.sensor] Setup of sensor platform imap is taking over 10 seconds.

It came opgrading to (core) til 2022.7.2 (can remember from what version) and remains in 2022.7.3 - connection to port 993 on the servers work fine from the OS using telnet.

Both sensors just say: entity not available: sensor.xxxxx_gmail.com etc.

Restart does not solve the issue.

1 Like

It looks like a recent update caused some problems with the IMAP integration: https://github.com/home-assistant/core/issues/74487

(I found this by clicking the “View known issues” link on the IMAP integration page - very handy!)