Vayain
(Vayain)
April 7, 2017, 9:36pm
21
Hi mplawner,
thanks a lot for looking back in you script, appreciate it!
I tried as you suggested - using “parseemail.sh TEST-BACKUP FAIL” manually works find and the sensor switches to “Failed”.
So - the automation rule it is…
I looked into the mails, “TEST-Backup FAIL” for example is placed in the mail body…but the trigger won’t act.
So the issue seems to be the missing value from the automation to the script - i understood.
Tried {{ states(‘sensor.emails’) }} too, sadly with the same result.
- alias: Email State Change - Parse
trigger:
- platform: state
entity_id: sensor.emails
action:
- service: shell_command.parseemail
data_template:
#value: "{{ state('sensor.emails') }}"
value: "{{ trigger.to_state.state }}"
So close
mplawner
(Michael Plawner)
April 8, 2017, 2:27pm
22
The script is case sensitive, so if you have “TEST-Backup FAIL” in the body, but TEST-BACKUP FAIL in the script, those two values won’t be equal.
Have you tried sending emails manually?
Vayain
(Vayain)
April 19, 2017, 8:08am
23
Thanks mplawner! Sorry for the delay, had to sort out some private stuff.
And guess what, with a fresh view, there is my ‘Ah Ha’ moment
Incoming mails are processed via imap_email_content, the content is shown in sensor.emails and your wonderful script parses the content according to the rules and feeds mqtt. Thanks again for sharing your work!
There seems to be a difference between “value: “{{ states (‘sensor.emails’) }}”” and “value: “{{ state (‘sensor.emails’) }}””, that did it for me.
shell_command.parseemail
parseemail: bash /home/homeassistant/.homeassistant/parseemail.sh {{value}}
parseemail.sh
#!/bin/sh
echo "****" >> /home/homeassistant/.homeassistant/parseemail.log
echo $1 >> /home/homeassistant/.homeassistant/parseemail.log
if [ $# -ne 1 ]; then
echo "Unknown"
else
# Backup Status Sycloud TEST 3
mosquitto_pub -h 127.0.0.1 -u <User> -P <PW> -r -t RaspHA/emails/`echo $1 | awk '/SyCloud/ {print "Backup_TEST3"}'` -m "SyCloud"
mosquitto_pub -h 127.0.0.1 -u <User> -P <PW> -r -t RaspHA/emails/`echo $1 | awk '/SxCloud/ {print "Backup_TEST3"}'` -m "SxCloud"
fi
################################################################
Automation - email_parse.yaml
- alias: Email State Change - Parse
trigger:
- platform: state
entity_id: sensor.emails
action:
- service: shell_command.parseemail
data_template:
value: "{{ states('sensor.emails') }}"
Sensor MQTT
- platform: mqtt
name: "MQTT Status Backup TEST3"
state_topic: "RaspHA/emails/Backup_TEST3"
mplawner
(Michael Plawner)
April 19, 2017, 1:56pm
24
Whew! Glad you got there @Vayain and all is working for you!
I’m still uncertain why
value: "{{ states('sensor.emails') }}"
works for you and
value: "{{ trigger.to_state.state }}"
doesn’t. They should be the same.
Nonetheless, glad you’re up and running!
Vayain
(Vayain)
April 19, 2017, 6:49pm
25
Thanks to you
Giving it another try with “trigger.to_state.state”, the result is the same…I’m wondering, where my first error was…
Now i recognized one last thing…seems like the parsing uses only the first word:
parseemail.log
TEST-BACKUP
****
Backup_SyCloud-2-WDextern
****
Backup_SyCloud-2-SGextern
****
TEST-BACKUP
For example the last entry should be “TEST-BACKUP FAILED”, the state of “sensor.email” is complete, seems like something got lost somewhere
mplawner
(Michael Plawner)
April 19, 2017, 9:39pm
26
Odd. My script does appear to be parsing the full message.
For example, from my log:
****
4/19 5:03 PM
Garage Door (Zone 12) changed to Open.
garagedooropen
****
4/19 5:04 PM
Garage Door (Zone 12) changed to Closed.
garagedoorclosed
Those entries were accurately captured by the following lines from the script:
# Garage Door
mosquitto_pub -h 127.0.0.1 -r -t home-assistant/emails/`echo $1 | awk '/garagedooropen/ {print "garagedoor"}'` -m "open"
mosquitto_pub -h 127.0.0.1 -r -t home-assistant/emails/`echo $1 | awk '/garagedoorclosed/ {print "garagedoor"}'` -m "closed"
I confirmed my current script is as described above.
mplawner
(Michael Plawner)
April 19, 2017, 9:42pm
27
I should also mention, I’m running Home Assistant 0.42.4 (current) on a Raspberry PI 3, pip install (no docker).