Hey all… I am setting up an automation that will automatically open a garage door if an email from a pre-approved sender is recieved in a special mailbox set up just for that purpose. I have setup the IMAP integration and the relevant template. I then created a sensor that changes if there is an email received that includes the subject line “open”.
That seems to be working fine… the question is this. I want to create an automation that opens the garage door for 5 minutes when this email is received, but the state of the sensor will stay as “open_recieved” until some other email is recieved that doesnt say “open” in the subject line. Since this email box will not be used for any other purpose I think the state will remain “open_recieved” indefinitely.
I would like the state to reset after a few minutes to “not_recieved” but cannot figure out how to do it.
Suggestions?
- trigger:
- platform: event
event_type: "imap_content"
id: "imap_content"
sensor:
- name: imap_content
state: "{{ trigger.event.data['subject'] }}"
attributes:
Entry: "{{ trigger.event.data['entry_id'] }}"
UID: "{{ trigger.event.data['uid'] }}"
Message: "{{ trigger.event.data['text'] }}"
Sender: "{{ trigger.event.data['sender'] }}"
Date: "{{ trigger.event.data['date'] }}"
Subject: "{{ trigger.event.data['subject'] }}"
Received-first: "{{ trigger.event.data['headers'].get('Received',['n/a'])[0] }}"
Received-last: "{{ trigger.event.data['headers'].get('Received',['n/a'])[-1] }}"
- trigger:
- platform: event
event_type: "imap_content"
id: "Open_Email"
event_data:
sender: "[email protected]"
initial: true
sensor:
- name: Email-Open-Garage
state: >-
{% if 'open' in trigger.event.data["subject"] %}
open_recieved
{% else %}
open_not_recieved
{% endif %}
Bonus second question: For this part:
event_data:
sender: "[email protected]"
initial: true
that checks against a specific email address, how do i check multiple email addresses? I have a list of 4 allowed emails.
Thanks!!