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

* ✏️ Tweaks
This commit is contained in:
Sean Straus 2019-02-25 22:03:13 +01:00 committed by Franck Nijhof
parent db67c4db0b
commit d58dc3fdee

View File

@ -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.