i have successfully intergrated the imap e-mail integration.
But it seems the order for reading new messages is newest first, right?
The mailbox receives states from sensors. But if the automation reads the mails in the wrong order, the state is wrong. The automation deletes the message after reading, so the mailbox is always empty, but the messages from the sensors are sometimes coming only seconds between.
Instead of querying the state of the entity (which may have changed already), use the values available in the trigger variable:
{{ trigger.to_state.attributes.UID }}
Use queued as your mode so things are processed in the order they happen, make sure to set max to a reasonable value for the rate you receive emails… if you are unsure what that would be, there is a max_exceeded configuration variable you can set to get log messages.
You may also want to consider setting up a specific IMAP integration sensor for just these emails instead of using one generic sensor. Mail servers have different policies about how often they update IMAP search results, so a sensor based on a generic search may not post an event for every email if multiple emails are received in short order.
if i open the door for 5 seconds and close it.
the mails with open door and close door arrives in the correct order in the mailbox,
But the sensor ececutes the newer one (close door) first and after that the older one (open door).
Now my boolean sensor is in the state door open, and also the messages send to telegram are in the wrong order.
i think the imap integration prefers the newer push from the imap server and read the newer mail first.
You don’t need to make one for every subject or sender, even making the search criteria a little more specific to it’s end use purpose can make it significantly more reliable.
Since, you are really using any filtering for the template sensor, it would be more efficient to use the event trigger instead of relaying it through the IMAP sensor.
Make sure you fix the templates you are using for uid so they use the trigger variable, you can easily delete the wrong emails the way you have it currently configured.
Yes, the event data is always based on the newest message. Sometimes when you delete a message, there may be a new event for a message that was actually older. Using the value of the initial variable can help prevent those from affecting your sensor.
Just be aware that there are some combinations of cloud-based services and email providers that will never produce reliable and accurate results using the IMAP integration. It might be possible to force them to work if you use the fetch function… but I don’t think it would be worth the effort since all the time data for the end sensor would be inaccurate.
Relaying sensor data from your house, through a cloud service, then to your email, and then back to your house will always be less reliable, less timely, and less accurate than using sensors that connect directly to HA locally.
hm, i tried now everything, but the integration imap doesn’t work as i expect.
it always takes the newest mail and not the oldest mail, also if i disable push mail. That doesn’t makes sense if you want to track the state from a device, which only can send emails.
Is there any other mail intergration, which supports polling a mailbox and fetch mails in the order “oldest first” ?