From d58dc3fdee8547d5faaf19e29ee892df74b959cd Mon Sep 17 00:00:00 2001 From: Sean Straus Date: Mon, 25 Feb 2019 22:03:13 +0100 Subject: [PATCH] Add an example with a template (#8712) * Add an example with a template I found it very hard to find an example template for IMAP email sensor, so I think it would be helpful to include a working one here. This one works correctly and has been tested extensively with a popular cloud service. * Update sensor.imap_email_content.markdown * :pencil2: Tweaks --- .../sensor.imap_email_content.markdown | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/source/_components/sensor.imap_email_content.markdown b/source/_components/sensor.imap_email_content.markdown index fcba5672ad3..6b198bb06ad 100644 --- a/source/_components/sensor.imap_email_content.markdown +++ b/source/_components/sensor.imap_email_content.markdown @@ -13,7 +13,6 @@ ha_iot_class: "Cloud Push" ha_release: 0.25 --- - The `imap_email_content` sensor platform will read emails from an IMAP email server and report them as a state change within Home Assistant. This is useful if you have a device that only reports its state via email. ## {% linkable_title Configuration %} @@ -78,3 +77,29 @@ value_template: date: description: The date and time the email was sent. {% endconfiguration %} + +## {% linkable_title Example %} + +The following example shows the usage of the IMAP email content sensor to scan the subject of an email for text, in this case, an email from the APC SmartConnect service which tells whether the UPS is running on battery or not. + +{% raw %} +```yaml +sensor: + - platform: imap_email_content + server: imap.gmail.com + name: house_electricity + port: 993 + username: MY_EMAIL_USERNAME + password: MY_EMAIL_PASSWORD + senders: + - no-reply@smartconnect.apc.com + value_template: >- + {% if 'UPS On Battery' in subject %} + power_out + {% elif 'Power Restored' in subject %} + power_on + {% endif %} +``` +{% endraw %} + +The same template structure can scan the date, body, or sender for matching text before setting the state of the sensor.