So I am just starting with Home Assistant and have a question about Setting up Imap Email Content Sensors
I have a sensor setup like the example on this page
My Issue is I have One email address sending info for 2 different sensors.
and can’t figure out how to split them up into 2 different sensors.
For example if you look at the example on the page I linked
Its Looking for ‘UPS On Battery’ OR ‘Power Restored’ from [email protected]
to set the sensor to either Power On or Off which works
But What I need to do is like this…
Look for ‘PC1 UPS On Battery’ or ‘PC1 UPS Power Restored’ from [email protected][dot]com To Set Sensor for PC1
And Look for ‘PC2 UPS On Battery’ or ‘PC2 UPS Power Restored’ from same email address [email protected][dot]com To set sensor for PC2
That’s what I thought at first but when I entered 2 versions of the sensor with different names I Don’t get info to both sensors every time one updates the other one blanks out
This is what I tried…
sensor:
- platform: imap_email_content
server: imap.gmail.com
name: pc1
port: 993
username: MY_EMAIL_USERNAME
password: MY_EMAIL_PASSWORD
senders:
- [email protected]
value_template: >-
{% if 'PC1 UPS On Battery' in subject %}
power_out
{% elif 'PC1 Power Restored' in subject %}
power_on
{% endif %}
- platform: imap_email_content
server: imap.gmail.com
name: pc2
port: 993
username: MY_EMAIL_USERNAME
password: MY_EMAIL_PASSWORD
senders:
- [email protected]
value_template: >-
{% if 'PC2 UPS On Battery' in subject %}
power_out
{% elif 'PC2 Power Restored' in subject %}
power_on
{% endif %}
That’s correct because, the information being received by the two sensors is, in effect, multiplexed. It contains information that is sometimes intended for one sensor and at other times it’s for the other sensor. So what should a sensor do if the received information doesn’t belong to it?
It should report it’s own current state. That will prevent the ‘blanking out’ you’ve noticed. All that’s needed is an else that handles the case when the received information belongs to the other sensor:
sensor:
- platform: imap_email_content
server: imap.gmail.com
name: pc1
port: 993
username: MY_EMAIL_USERNAME
password: MY_EMAIL_PASSWORD
senders:
- [email protected]
value_template: >-
{% if 'PC1 UPS On Battery' in subject %}
power_out
{% elif 'PC1 Power Restored' in subject %}
power_on
{% else %}
{{states('sensor.pc1')}}
{% endif %}
- platform: imap_email_content
server: imap.gmail.com
name: pc2
port: 993
username: MY_EMAIL_USERNAME
password: MY_EMAIL_PASSWORD
senders:
- [email protected]
value_template: >-
{% if 'PC2 UPS On Battery' in subject %}
power_out
{% elif 'PC2 Power Restored' in subject %}
power_on
{% else %}
{{states('sensor.pc2')}}
{% endif %}
Please mark my post with the Solution tag so other users, having a similar challenge, can find it easily. Only you the author of this topic can mark a post as the Solution. it will then appear as a link below your first post and a checkmark will appear next to the topic’s title.