i read this integration but it is still confusing so it’s not working.
My Amcrest camera has AI human detection but has no HA integration, not even the Dahua HACS works on this ASH21. Luckily, it does have Email alerts!
this is the type of email i get whenever a person is detected:
so how do i change it to something useful like ON for entity AI_human when the email comes in?
i know how to flip the state to OFF via a python script.
ultimately, when it changes to ON, a light will turn on (that part i can do too).
i am happy to say this works but it keeps turning ON because it sees the old email. how do i turn to ON for only new emails? and force HA to ignore old email?
I think you should be able to use a time-based template which references the email’s date attribute to turn the state to “off” if the email is older than a given length of time… In the example below I have it set to change once the email is 1 minute old:
value_template: >-
{% if "Person Detected" in subject and (now() - (strptime(date, "%a, %d %b %Y %H:%M:%S %z")) <= timedelta(minutes=1)) %}
on
{% else %}
off
{% endif %}
Just an update for anyone struggling with this elegant solution to what is effectively like keeping your finger on a push button. The email date parsed with:
strptime(date, "%a, %d %b %Y %H:%M:%S %z")
will fail if your date includes an offset against UTC (identify this from email itself/Developer Tools/attributes etc.). Use the following:
strptime(date, "%a, %d %b %Y %H:%M:%S %z (%Z)")
where the (%Z) parses the (UTC) bit of the offset e.g. +0000 (UTC), the ()'s are required!