Struggling with imap integration with Home assistant

I want to use the imap integration with Home Assistant but am struggling to get this configured right. Here is my usecase:

I get a daily email at 7am each morning from my utility company about my water consumption from the day before. The sender is [email protected]
Subject is ‘Gallon Alert for Meter id XXXXXXXX WA Meter’
Messge content is:
Hello,

You requested the Town notify you when your water usage exceeded 0.0 gallons per day for Meter #: XXXXXXXX - WA. Yesterday, your actual usage was 340.00 gallons. </END of message>

I want to be able to listen for this email arrival event, parse it and extract the ‘340.00’ gallons to display on my dashboard. Ideally I want this number to be appended daily/contiguously so that I can use it as a Utility Meter and display charts etc for daily/monthly etc.

What I have done so far is configured the HA Imap integration with my mailbox

I can see the sensor.imap_myemailaccount_messages has ~7500 message

Next I added the following to the configuration.yaml file:

template:
  - trigger:
    - platform: event
      event_type: "imap_content"
      id: "my_mail_eventid"
      event_data:
        search: UnDeleted X-GM-RAW "Gallon Alert"
        initial: true
  - sensor:
    - name: water_email_sensor
      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'] }}"

Rebooted everything. Wait for the utility water usage email to hit the mail box.
However, my sensor ‘water_email_sensor’ shows as unavailable when I check its value in Developer tools > States.

I know I might be missing something more fundamental here but I have been spinning on this since the last few days and am seeking help from someone who has successfully used imap with HA.

Please help!

The search specified in the event trigger’s data… UnDeleted X-GM-RAW "Gallon Alert"
… does not match what you are using in the IMAP sensor config’s “IMAP Search” field i.e. UnSeen UnDeleted; so no events match your trigger’s requirements. Any values you are trying to use as selection criteria in event_data need to match exactly. I would suggest not trying to make the trigger super selective since conditions are now supported for trigger-based template sensors. Definitely include initial and 1-2 other stable criteria like sender in the trigger, but move the search of the subject and any other complex/variable discriminating factors to Template conditions.

Also, your trigger and sensor are configured as two separate list items, so the trigger isn’t even affecting the sensor…

template:
  - trigger:
      - platform: event
        event_type: "imap_content"
        id: "my_mail_eventid"
        event_data:
          initial: true
          sender: [email protected]
    condition:
      - alias: Check subject for "gallon alert"
        condition: template
        value_template: "{{ trigger.event.data['subject'] | lower is search('gallon alert') }}"
    sensor:
      - name: water_email_sensor
        state: |
          {{ trigger.event.data["text"] 
          | regex_findall(find="(?:/* your actual usage was )(\d{1,4}\.\d{1,2})(?: gallons*)" )
          | first | round(2) }}
        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'] }}"