Automation based on IMAP not triggering with subject condition

Hello,

I have a problem with the following automation. If i remove (disable) the condition, the automation works as expected, but if I enable it then it doesn’t work anymore.

(And I’m definitely putting the “LightOn” word in the email subject…)

Any ideas?

alias: Test IMAP
description: Test IMAP
trigger:
  - platform: event
    event_type: imap_content
    event_data:
      sender: [email protected]
condition:
  - condition: template
    value_template: "{{ 'LightOn' in trigger.event.data.subject }}"
    enabled: true
action:
  - service: light.toggle
    target:
      entity_id: light.tolomeo
    data: {}
mode: single

What is Traces showing if the template condition is enabled?

Maybe you want to try:

alias: Test IMAP
description: Test IMAP
trigger:
  - platform: event
    event_type: imap_content
    event_data:
      sender: [email protected]
condition:
  - condition: template
    value_template: "{{ trigger.event.data['subject'] == 'LightOn' }}"
action:
  - service: light.toggle
    target:
      entity_id: light.tolomeo
    data: {}
mode: single

It looks like the issue was not related to the condition after all: the (gmail) IMAP was not reliably pushing (?).

I disabled the push option in the integration config, and it seems to work now…

Is gmail push a known issue?

I have push enabled on all my GMail-based IMAP sensors and have never noticed it to be unreliable. IIRC, GMail rate limits push to 1/sec. If you have a particularly active inbox it is possible to miss individual messages.

1 Like

I do get many emails (which was the reasons why I was trying to automate / set up alerts for some of those), so that must be part of the reason.

Although having tested this for few days, even with the push option disabled not all emails are correctly caught by the automation (some are simply missed).

If push was working, you should turn it back on. Disabling it will only make the situation worse since the polling rate is slower than the push limit.

If the issue is the quantity of emails you are receiving, you should consider using some form of pre-sorting. There are a number of ways to accomplish this depending on your needs.

  1. GMail has built in functions to filter incoming messages and add tags or move them into folders. Then:
  2. Use a more specific search in your IMAP sensor configuration. This can be done in conjunction with GMail filtering or on its own to reduce the quantity of messages that reach HA.

OK, so in my case, instead of having:

  • UnDeleted” in the “IMAP search” config and
  • (for example) “LightOn” as a condition within the automation

…it’s better to have something like:

  • SUBJECT LightOn” in the “IMAP search” config and
  • no condition within the automation

as this would not (likely!) trigger the push limits…

I will try this, thanks.