I’m expecting to get a custom_event as per the manual on IMAP - Home Assistant but it also keeps mentioning that advanced mode needs to be enabled (user settings) but then proceeds to not list anywhere on the page where user settings can be configured, unless i am seriously overlooking it.
I need to be able to specify a list of email addresses or use a @domain in one sensor. I tried both variants and without quotes but it’s not triggering the sensor (i created one coming from my own domain to test). IMAP sensor shows a count of email addresses so that’s working.
I’m testing it with just the sender option for one email address, but the sensor doesn’t seem to change state. Not sure what’s going on. The imap integration/sensor does change amount of emails.
The issue might be the lack of a default in your “reset” trigger… but I would expect there to be errors in the logs if that was causing the sensor setup to fail.
- platform: template
id: timeout
value_template: >
{% set last = states.sensor.tesco.last_changed | default( 0 | as_datetime) %}
{{ now() - last >= timedelta(minutes=5) }}
If you don’t absolutely need to have delay/no_delay as the output, I would use a binary sensor with a 5 minute auto_off instead.
# Tesco order delay
- trigger:
- platform: event
event_type: "imap_content"
binary_sensor:
- name: Tesco
auto_off: "00:05:00"
state: |
{% set email_test = trigger.event.data['sender'] is search('@example_domain') and
trigger.event.data['text'] | lower is search('late|delays') %}
{{ 'on' if email_test else 'off' }}
UnSeen Undeleted is not the same as “new”… You have 40K UnSeen Undeleted emails. If you delete or read the newer emails but the most recent “old” UnSeen Undeleted matches the template criteria the sensor will turn on again. You could add another condition to the state template to filter by the datetime the email was sent…
...
state: |
{% set email_test = trigger.event.data['sender'] is search('@example_domain') and
trigger.event.data['text'] | lower is search('late|delays') and
trigger.event.data['date'] >= now() - timedelta(minutes=5) %}
{{ 'on' if email_test else 'off' }}
One final question if you don’t mind… i also have an email from dominos that is getting sent in base64. Do i need to apply the base64 conversion to all fields in the event or is it sufficient to just apply it to the body of the email. I’m thinking only the body as when i view it raw only the content of the email is base64.
e.g.
{% set email_test = trigger.event.data['sender'] is search('@dominos.co.uk') and
trigger.event.data['text'] | base64_decode | lower is search('sorting') and
trigger.event.data['date'] >= now() - timedelta(minutes=5) %}
{{ 'on' if email_test else 'off' }}