core: New IMAP sensor integration intermittent

The problem

I migrated my existing IMAP sensor to the new IMAP format, during which data from my existing sensor was incorporated in the newly created sensor. I have eventually managed to rewrite both the configuration entry and the automation that I previously used but the reponse/trigger from the new sensor setup is intermittent. The new sensor does not update reliably to reflect UnSeen/UnRead status, depending on the unread number of emails in the inbox at any given time. It can be remedied, albeit briefly, by reloading the template entity in Developer Tools or reloading the integration.

What version of Home Assistant Core has the issue?

2023.5.3

What was the last working version of Home Assistant Core?

pre 2023.5.2

What type of installation are you running?

Home Assistant OS

Integration causing the issue

IMAP integration

Link to integration documentation on our website

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

Diagnostics information

No response

Example YAML snippet

template:
- sensor: 
  - name: alarmmail
    state: '{{ trigger.event.data["sender"] }}'  
  trigger:
  - event_data:
      sender:
      - sender1@domain.co.uk
      - sender2@domain.co.uk
      - sender3@domain.co.uk
    event_type: imap_content
    id: custom_event
    platform: event   

- id: '1619965086400'
  alias: Mail received
  trigger:
    - platform: event
      event_type: imap_content
  condition:
    - condition: template
      value_template: "{{ trigger.event.data['sender'].endswith('@domain.co.uk') }}"
  action:
    - service: media_player.volume_set
      data:
        entity_id: media_player.googlehome0867
        volume_level: 0.4
    - service: tts.google_cloud_say
      data:
        entity_id: media_player.googlehome0867
        message: Mail received
    - service: telegram_bot.send_message
      data:
        message: Mail received
  mode: restart

Anything in the logs that might be useful for us?

Nothing in the logs

Additional information

I have reverted to my previous setup in the interim but am willing to test to provide diagnostic data.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 32 (13 by maintainers)

Most upvoted comments

HA 2023.6.0 is planned to have an advanced option that allows to increase the max size of the message text to max 30000 bytes. But if the total event data exceeds the 32kB the event will fail. #93423 (not merged yet) will introduce a template that will be evaluated before the event is sent. Advantage is that you can render anything without the size limitation within the template and the result is passed to the event data. So it can be used to filter events or render and expose other info directly into the event data.

lol! you beat me to it 😃 I will add that

@Anto79-ops , thanks so much for this. I have reverted to my old sensor in the interim but I will hopefully get a chance to implement your solution on the weekend.

HA 2023.6.0 is planned to have an advanced option that allows to increase the max size of the message text to max 30000 bytes. But if the total event data exceeds the 32kB the event will fail. #93423 (not merged yet) will introduce a template that will be evaluated before the event is sent. Advantage is that you can render anything without the size limitation within the template and the result is passed to the event data. So it can be used to filter events or render and expose other info directly into the event data.

Thank you @jbouwh for your kind effort. As for now will maintain old imap_email_content until HA 2023.6.0 is ready…

Now I see it written down I can see my issue. It’s the multiple senders problem raised above. I will work around that. Sorry!!

Linked PR should adds a new advanced feature. It allows to configure a template for which the rendered value is added to the event data. In the linked docs PR an example is added how to use the new template feature to filter email addresses.