IMAP Email Content


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.

Configuration

To enable this sensor, add the following lines to your configuration.yaml file:

# Example configuration.yaml entry
sensor:
  - platform: imap_email_content
    server: imap.gmail.com
    port: 993
    username: USERNAME
    password: PASSWORD
    folder: <Folder>
    senders:
      - [email protected]

Configuration Variables

server

(string)(Required)The IP address or hostname of the IMAP server.

port

(integer)(Optional)The port where the server is accessible.

Default value: 993

name

(string)(Optional)Name of the IMAP sensor.

username

(string)(Required)Username for the IMAP server.

password

(string)(Required)Password for the IMAP server.

folder

(string)(Optional)Folder to get mails from.

Default value: INBOX

senders

(string)(Required)A list of sender email addresses that are allowed to report state via email. Only emails received from these addresses will be processed.

value_template

(template)(Optional)If specified this template will be used to render the state of the sensor. If a template is not supplied the message subject will be used for the sensor value. The following attributes will be supplied to the template.

from

The from address of the email.

body

The body of the email.

subject

The subject of the email.

date

The date and time the email was sent.

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.

sensor:
  - platform: imap_email_content
    server: imap.gmail.com
    name: house_electricity
    port: 993
    username: MY_EMAIL_USERNAME
    password: MY_EMAIL_PASSWORD
    senders:
      - [email protected]
    value_template: >-
      {% if 'UPS On Battery' in subject %}
        power_out
      {% elif 'Power Restored' in subject %}
        power_on
      {% endif %}

The same template structure can scan the date, body, or sender for matching text before setting the state of the sensor.