I have an external application that sends a mail every x minutes. I have created some sensors inside the configuration.yaml file to capture their values, all perfect.
Now I have another application that sends me an email every 3 hours. When reading this other email, the values of the first sensors are deleted and the value of the new sensor appears.
I’ve been trying to prevent this from happening but I can’t.
It would be possible to include a conditional on the sensor value depending on the subject text of the email. I’ve seen some examples but they don’t work for me. I still don’t understand much about HA
value_template: >-
{% if "Reef1" in subject %}
"{{ (state_attr('sensor.reef_tunnel_raw','body') | regex_findall_index(find='([0-9].*h)', index=0))[:-1] }}"
{% endif %}
Switching to trigger-based template sensors will allow the values to remain stable even when a new email is received because they only update when the trigger template becomes true. (Although, it does make the name of your IMAP sensor a bit inaccurate)
I have tried your code and it captures nothing. I have modified mine and now it works almost fine.
It reads perfectly the mail that comes from one of the computers (Reef1) but the one that comes from the other does not (Reef2). I have created a shipment from the Reef1 team but putting Reef2 in the subject and it integrates perfectly.
If I send it from the other computer or even myself from a gmail account it doesn’t work either. I have also tried to send one from gmail with the subject Reef1 and it doesn’t read it either.
What can be? I see the emails perfectly in the inbox.