#IMAP trigger with binary_sensor

1 messages · Page 1 of 1 (latest)

real dune
#

I know I'm missing something. I followed the keyword spotting example on the IMAP integration documentation along with an example from the community for a binary sensor (this allowed for an auto off which is perfect for my use). I can watch the event happen with the developer tools but when I don't see the state getting updated. For context- I'm trying to monitor my email for a message from USPS that my mail has been delivered and flip the binary switch. (once that's working: I'll then check the switch from a MagicMirror module and display an icon showing it's been delivered).
Edited to format: Also adding that I'm putting this in the configuration.yaml (I'm not 100% sure that's the right spot).

template:
  - trigger:
      - trigger: event
        event_type: "imap_content"
        id: "custom_event"
        event_data:
           sender: "Someone@somewhere.com"
           initial: true
    binary_sensor:
      - name: mail_delivered
        auto_off: "08:00:00"
        state: >-
          {% set current = this.state|default('off', 1) %}
          {% if 'Mail Was Delivered' in trigger.event.data["subject"] %}
            on
          {% else %}
            {{ current }}
          {% endif %}
gusty kiln
#

Please format your code

rose lagoonBOT
#

To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.

gusty kiln
#

Can you share the actual event data?

real dune
#

This is the header info from my test email I'm sending as shown in the event listener and edited for privacy - ```
event_type: imap_content
data:
entry_id: 01JKH8T39V0NC2298ARG69854B
server: imap.gmail.com
username: myemail@mydomain.com
search: UnSeen UnDeleted
folder: INBOX
initial: true
date: "2025-03-13T11:10:46-04:00"
sender: someone@somewhere.com
subject: Mail Was Delivered
uid: "23275"
headers:
Delivered-To:
- myemail@mydomain.com
Received:

#

My expecatation is that when the imap_content event happens and there is a "subject" of "Mail Was Delivered" the state on the binary_sensor.mail_delivered would be set to "on" and then set to off 8 hours later.

#

(also coming from a specific sender)

#

Okay. Maybe it did work and I just didn't wait long enough for it to process.

#

🤦‍♂️

cold fiber
#

note that there is always a this.state value. It will be "unknown" on first creation of the template sensor. So your default filter is not doing anything useful there

real dune
#

Thanks. I was seeing that.

real dune
#

Okay, now I'm confused. It doesn't seem to be working if I try to use something other than "UnSeen UnDeleted" for the imap configuration. I was using X-GM-RAW "in:inbox newer_than:8h" and the message count was correct but the event wasn't getting triggered so that the binary sensor would change