#Hello! I'm using the imap integration
1 messages · Page 1 of 1 (latest)
The docs example that describe multiple senders just assumes they're all coming from the same domain, which isn't the case for me. Might someone be able to point me in the right direction on how to specify multiple senders, or where in the docs that it might explain that?
Hmm, actually, I wonder - would this possibly work?
event_data: >-
{{ "@(domain1.com|domain2.com)" in sender }}
OK, , well it doesn't look like that would work - that just makes HA complain about improper syntax:
Invalid config for [template]: expected dict for dictionary value @ data['event_data']. Got None. (See ?, line ?).
I think the thing I'm getting hung up on is the (to me) incomplete example given for the "custom event data template". Where does the {{ "@example.com" in sender }} line go in the config?
The trigger is very literal, if you add event data it must match the data of the incoming event exactly. Since an email will never have multiple senders, you cannot set multiple senders in a single trigger. Event triggers only allow limited templates in certain places.
Between the IMAP integration and trigger-based content sensor there are 4 methods for filtering.
- Configuration of the IMAP integration Search.
- Configuration of the IMAP integration Custom Event Data. This is where the
{{ "@example.com" in sender }}you asked about earlier would go. - Setting multiple triggers with distinct criteria
- Through templating in the sensor block.
Awesome! Thanks so much for the help @gloomy yew ! I was able to find where the custom event data goes (in the integration config in the UI directly), and mashed together something that looks like it's working the way I want:
{{ "string" in subject|lower and sender|lower is search("email1@domain1.com|email2@domain2.com|email3@domain3.com") }}
Then I just configure the trigger and sensor in configuration.yaml
I suppose in a situation where one wanted/needed multiple custom events like this, they'd just have to configure multiple redundant imap integrations
Actually, no that wouldn't work, now that I think about it lol
For the purposes of content sensors, you don't need to use custom events at all, it's just an option and if you are monitioring more than one email or plan to have multiple search criterion or custom events, you will still need to use trigger and template design for your content sensors. For that reason, I keep my IMAP search very general for each of my email addresses and I don't bother with custom events. For the specificity of my content sensors I use trigger and template design.
So for your example above the content sensor could have a very general trigger and use more selective templating like:
- trigger:
- platform: event
event_type: "imap_content"
sensor:
- name: email content example
state: |
{% set current = this.state if this is defined else none %}
{% if "string" in trigger.event.data['subject']|lower and
trigger.event.data['sender']|lower in ['email1@domain1.com',
'email2@domain2.com','email3@domain3.com'] %}
{{ trigger.event.data['message'] }}
{% else %} {{ current }} {% endif %}
All those senders could also have been handle by having more selective triggers and slightly less selective templating... which is what I would normally do to avoid having the system render the template every time any IMAP sensor updates.
- trigger:
- platform: event
event_type: "imap_content"
event_data:
sender: email1@domain1.com
- platform: event
event_type: "imap_content"
event_data:
sender: email1@domain2.com
- platform: event
event_type: "imap_content"
event_data:
sender: email1@domain3.com
sensor:
- name: email content example
state: |
{% set current = this.state if this is defined else none %}
{% if "string" in trigger.event.data['subject']|lower %}
{{ trigger.event.data['message'] }}
{% else %} {{ current }} {% endif %}
Oh nice. Yeah, I was doing the custom event stuff to try and avoid triggering the...well, trigger, and clearing the current state if I didn't want to update the sensor (false alarm or something). But your example also shows how to basically set it back to its current