I’ve never used this so I would be wildly guessing at the syntax, but I’m thinking something like this;
Your email subject is an attribute of the sensor and your message sent has the subject “tado status away” and then you use this as your trigger. The sensor setup would look something like this (again, my snesor name is probably wrong but you get the idea):
"{% if is_state('sensor.imap.subject', 'tado status is away') %}true{% endif %}"
I’ve tried all sorts of configurations. I just can’t figure out how to work this one. Can someone share an example of how they’ve implemented this sensor? Thanks,.
Sorry, I missed the senders value in my configuration.
I added 1 mail address to my configuration and tried 4 test emails, 2 from the address specified in the config and 2 from a different address.
Sensor is acting the same as without the senders value, unread email 4.
Will try with subject.
Sorry. Yes - it just started working after an upgrade. Currently works straight out of the box on version 0.31.1. I’ll share my configuration later on today in case that will help anyone.
yes i noticed that where before it always just said unknown, since update to 0.31.1 it does now show info from an email. i still can’t work out how to set the state from the subject line though
Edit: If I write this into the template editor in the home assistant frontend…
It now successfully sets the state of the sensor, but unfortunately it sets it to the previous email sent, not the current email.
So if I send an email with ‘test’ as subject, then an email with ‘test2’ as subject it will display ‘test’ as the state, then when I send a ‘test3’ email the state updates to ‘test2’
The way I set this up was to simply not use the value_template on the sensor configuration, parse full load via a shell script, and trigger events via MQTT. You could search on any word/s you require. Been years since I was scripting, so excuse my hack-y solution. Of course, if anyone wants to make suggestions on how to improve this, I’m not proud!
I have an automation that checks for email state change:
alias: 'Email State Change - Parse'
trigger:
platform: state
entity_id: sensor.emails
action:
- service: shell_command.parseemail
data_template:
value: "{{ trigger.to_state.state }}"
Calling a shell command:
'/home/pi/.homeassistant/parseemail.sh "{{ value }}"'
Hi! Whew, had to go back an reread what I did there, it has been a while!
If all you are seeing is the *****, and you see a number of them, then that would seem to suggest that the automation is being triggered, but that the value isn’t being passed.
First, I suggest trying this - run parseemail.sh manually to narrow down where the problem is (and rule out any issues upstream).
e.g.
./parseemail.sh “TEST-BACKUP FAIL”
If this works (and you see the line in the log, and your sensor switches to “Failed”), then you’ve narrowed down the problem to nothing being in the trigger.to_state.state portion of the automation.
To narrow it down further, send an email that would trigger the automation and check the sate in home assistant states <> page. If it isn’t empty (and says TEST-BACKUP FAIL or whatever you sent), then the problem seems to be in the automation and not in the sensor.
I’m not too strong on HA and the templates, but I would check carefully the yaml (it is real particular about spacing). I don’t know, but if the trigger is the problem, perhaps using something like {{ states(‘sensor.emails’) }} instead would work. But technically, I don’t see why the trigger wouldn’t work.
The state is the body of the email… not the subject line!
That’s pretty important to note.
So, make sure your email BODY includes the text you want to parse.
I’m kinda expecting an ‘Ah Ha’ moment from you.
Edit: Yeah, confirmed. That’s going to be your problem. Just tested it myself and got the same results you did. If you have TEST-BACKUP FAIL in the Subject, but not in the body, you’ll get ***** only (state is empty). Move TEST-BACKUP FAIL to the Body and you’ll be all set.