Gmail/IMAP sensor stopped triggering

I have a sensor defined which uses the IMAP integration. It triggers an automation when an email arrives from specific senders which has specified text in the Subject. It’s been working fine for many months, but for some reason the automation has not been triggered in the last day, despite at least two qualifying emails arriving.
The parking_emails sensor (as defined below) currently has a state of parking_booking, and I can see the content of the most recent qualifying email in the attributes, so the emails are clearly being retrieved correctly.
Any idea why the automation has suddenly stopped triggering?


  - platform: imap_email_content
    server: imap.gmail.com
    name: parking_emails
    port: 993
    username: [email protected]
    password: googleapppassword
    senders:
      - [email protected]
      - [email protected]
    value_template: >-
      {% if 'You have a new booking' in subject %}
        parking_booking
      {% elif 'you have a new JustPark booking' in subject %}
        parking_booking
      {% elif 'Booking received' in subject %}
        parking_booking
      {% endif %}

The automation is defined like this:

alias: Parking booking email arrives
trigger:
  - platform: state
    entity_id: sensor.parking_emails
    to: parking_booking
action:
  - service: media_player.play_media
    entity_id:
      - media_player.googlehome4117
      - media_player.lounge_speaker
      - media_player.bedroom
      - media_player.nesthubmax9047_5
    data:
      media_content_id: /local/parking-booking.mp3
      media_content_type: audio/mp3

Maybe related:

Yes it could be. Until now I have not needed to take any action to reset the sensor (I haven’t even been deleting the emails). Maybe something changed with a recent HA release? (I upgraded from 2023.2 to 2023.5 this week).
I’ll try explicitly resetting the sensor at the end of the automation, to see if that resolves things.
…except I don’t actually know how to do that…is there a service which can be scripted to reset a sensor?

Did you find a solution?
It stopped working for me too with the update and I can’t reconfigure it correctly

I did have a solution - as per below, using the IMAP integration - but for some reason it has stopped triggering today (I have received 2 emails today which were not detected. The last time it triggered correctly was yesterday. I’m not sure why it has suddenly stopped working, as I’ve made no changes since it last triggered correctly.

template:
  - trigger:
      - platform: event
        event_type: "imap_content"
        event_data:
          sender: "[email protected]"
      - platform: event
        event_type: "imap_content"
        event_data:
          sender: "[email protected]"
      - platform: event
        event_type: "imap_content"
        event_data:
          sender: "[email protected]"
      - platform: event
        event_type: "imap_content"
        event_data:
          sender: "[email protected]"
    binary_sensor:
      - name: Parking Booking
        auto_off: "00:02:00"
        state: >
          {% set current = this.state|default('off', 1) %}
          {% if trigger.event.data['subject'] is match
          "You have a new booking|Booking received|JustPark booking|Booking request for My Road"
          %}
            true
          {% else %}
            {{ current }}
          {% endif %}

your code is in configuation.yalm or it is a automation ?

It’s in configuration.yaml

FYI I just restarted the HA server and it is now detecting my emails again using the above code.

I am having the same issue where it will be working and then will stop working until I restart Home Assistant. This behavior just started for me in 2023.5.2 after migrating to the new sensor. Until then the sensor worked perfectly.

Yes my problems started when I upgraded from 2023.2 to 2023.5. Looks like something got broken somewhere between the two releases

It doesn’t work for me, I don’t understand anything

Well, purely anecdotal but since I updated to 2023.5.3 two days ago my imap sensor has stayed up and emails are being scanned. I created just a generic imap_content sensor from the integration description to see if the emails are still being processed and they are. So there’s that.
YMMV.

Spoke too soon. Sure enough, the generic imap sensor shows that I got an email with the subject line I’m looking for but my sensor based on the content of the subject didn’t trigger…until I manually reloaded template entities.
There’s definitely a problem here.

Seems like this all might be https://github.com/home-assistant/core/issues/93092 and is slated to be fixed.