IMAP Email Content reading old emails?

I’m new to HA and even newer to the IMAP Email Content integration.

I got it working today, which is great, but it seems like it’s reading emails more than once and, thus, falsely changing a sensor state.

I’m currently testing the integration in order to more consistently use Simplisafe’s sensor information. I know there is a Simplisafe integration, but I got it working, and it’s really unreliable (Simplisafe’s fault). Instead, I’ve setup Simplisafe to email me every time a sensor is triggered, which it does reliably. My main Gmail account is then forwarding those emails to a dedicated Gmail address for security reasons. It’s this email address that I’ve configured IMAP Email Content with.

Since Simplisafe sends motion detection as an event, rather than a sensor state, I have also integrated the “Set State” Python script to automatically change the sensor status to “no_motion” after 10 seconds in the “motion” state, hopefully setting it up for the next email trigger.

Everything is working great, but the sensor status changes back to “motion” even when no new Simplisafe emails have arrived. It’s happening constantly. This is leading me to believe the IMAP Email Content integration is reading old emails and not merely as they come in, as it seems it should be doing. I do not have anything else setup that would change the sensor status from “no_motion” to “motion”.

Any ideas what might be going on and how I can correct it?

Thanks in advance.