core: New IMAP sensor not updating until template entities manually updated

The problem

After migrating to the new imap format, the sensor I have configured does not always get updated until I either restart Home Assistant or reload template entities in Developer Tools. The “generic” imap_content sensor I have created does show that the email I am looking for was received at some point. However, I have seen instances where this sensor also stops being updated until a restart of HA.

What version of Home Assistant Core has the issue?

2023.5.3

What was the last working version of Home Assistant Core?

2023.4.x

What type of installation are you running?

Home Assistant OS

Integration causing the issue

imap

Link to integration documentation on our website

https://www.home-assistant.io/integrations/imap/

Diagnostics information

No response

Example YAML snippet

template:
  - trigger:
      - platform: event      
        event_type: "imap_content"
        id: "custom_event"
        event_data:
          sender: "no-reply.notification@example.com"
    sensor:
      - name: Alarm Status
        state: >
          {% if 'Armed Away' in trigger.event.data["subject"] %}
            armed_away
          {% elif 'Armed Stay' in trigger.event.data["subject"] %}
            armed_stay
          {% elif 'Disarmed' in trigger.event.data["subject"] %}
            disarmed
          {% endif %}
          
  - trigger:
      - platform: event
        event_type: "imap_content"
        id: "custom_event"
    sensor:
      - name: imap_content
        state: "{{ trigger.event.data['subject'] }}"
        attributes:
          Message: "{{ trigger.event.data['text'] }}"
          Server: "{{ trigger.event.data['server'] }}"
          Username: "{{ trigger.event.data['username'] }}"
          Search: "{{ trigger.event.data['search'] }}"
          Folder: "{{ trigger.event.data['folder'] }}"
          Sender: "{{ trigger.event.data['sender'] }}"
          Date: "{{ trigger.event.data['date'] }}"
          Subject: "{{ trigger.event.data['subject'] }}"
          Return_Path: "{{ trigger.event.data['headers']['Return-Path'][0] }}"
          Received-first: "{{ trigger.event.data['headers']['Received'][0] }}"
          Received-last: "{{ trigger.event.data['headers']['Received'][-1] }}"

Anything in the logs that might be useful for us?

Nothing in the logs indicates a problem.

Additional information

This worked perfectly in previous versions of HA. Something with the new events is causing the inconsistency, or there’s something I’m missing in the migration that was suggested by HA.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 37 (16 by maintainers)

Most upvoted comments

I’ll write a fix for it.

You can delete the link. (I have it downloaded) Your email is exposed in it as it was sent to your.

OK, done. Let me know if you need anything else. I might try playing around with different emails to see if we can narrow down what makes it barf.

OK, will report back when it occurs again.