I’m trying to trigger an automation which turns on a switch when an email arrives with a specific text in the subject.
I’ve defined a sensor with a value_template in my config which seems to work fine:
sensor:
- platform: imap_email_content
server: imap.gmail.com
name: parking_emails
port: 993
username: [email protected]
password: mypassword
senders:
- [email protected]
- [email protected]
value_template: >-
{% if 'You have a new booking' in subject %}
parking_booking
{% elif 'you have a new JustPark booking' in subject %}
parking_booking
{% endif %}
When an email arrives with either of the above texts in the subject I can see the value of parking_emails change from “unknown” to “parking_booking” in the HA console.
Yes that part is correct - it’s a lower case “y”. That part of the logic is working fine - the sensor is being set to “parking_booking” - see here for the log which confirms this:
I restart the server between changes.
I just noticed that the automation is not listed at all under Developer Tools → States. So I restructured the syntax of the automation syntax to this:
…and now it’s working. I must confess I really struggle with yaml syntax, and really don’t understand what was wrong with the original syntax.
In any case, many thanks for leading me down the right path!