Using the IMAP integration to create a custom event from an email - HELP PLEASE!

There is a limit of the size of the event, so it’s best to not include the message headers if you don’t need them.

You’re going to need to look at the actual value held by the text variable. You can get it directly by using the Events tool or add a sensor to your configuration that gets the value.

      - name: Security Email Body Text
        state: "{{ trigger.event.data['text'] }}"

Once you get the value you can use the Template editor tool to figure out if the template works.

hi, i have test now (holiday)
the problem is email text. (allarm send a text but on HA i can’t filtrer)
i resolve with a single trigger inserimento e disinserimento for each person.
when person start allarm or stop allarm arrive a email on gmail . gmail filtred the email and HA control singol different folder on gmail.
i need help fo 2 problems:

1 - the email counter check email but i need to now how and when is the last email
2 - there is a way for see on HA entire email Object?

template:

  • trigger:
    • platform: event
      event_type: “imap_content”
      id: disinserimento
      event_data:
      folder: Alarm
      search: UnDeleted X-GM-RAW “disinserimento”
    • platform: event
      event_type: “imap_content”
      id: inserimento
      event_data:
      folder: Alarm
      search: UnDeleted X-GM-RAW “inserimento”
    • platform: event
      id: sirena
      event_type: “imap_content”
      event_data:
      folder: Alarm
      search: UnDeleted X-GM-RAW “c/o Abitazione:Allarme”
    • platform: event
      id: Alice ins
      event_type: “imap_content”
      event_data:
      folder: Alice
      search: UnDeleted X-GM-RAW “c/o Abitazione:inserimento”
    • platform: event
      id: Alice dis
      event_type: “imap_content”
      event_data:
      folder: Alice
      search: UnDeleted X-GM-RAW “c/o Abitazione:disinserimento”
    • platform: event
      id: Vale ins
      event_type: “imap_content”
      event_data:
      folder: Vale
      search: UnDeleted X-GM-RAW “c/o Abitazione:inserimento”
    • platform: event
      id: Vale dis
      event_type: “imap_content”
      event_data:
      folder: Vale
      search: UnDeleted X-GM-RAW “c/o Abitazione:disinserimento”
    • platform: event
      id: Ilaria ins
      event_type: “imap_content”
      event_data:
      folder: Ilaria
      search: UnDeleted X-GM-RAW “c/o Abitazione:inserimento”
    • platform: event
      id: Ilaria dis
      event_type: “imap_content”
      event_data:
      folder: Ilaria
      search: UnDeleted X-GM-RAW “c/o Abitazione:disinserimento”
    • platform: event
      id: Nicola ins
      event_type: “imap_content”
      event_data:
      folder: Nicola
      search: UnDeleted X-GM-RAW “c/o Abitazione:inserimento”
    • platform: event
      id: Nicola dis
      event_type: “imap_content”
      event_data:
      folder: Nicola
      search: UnDeleted X-GM-RAW “c/o Abitazione:disinserimento”
      sensor:
    • name: zTest IMAP Folder Content 2
      state: |-
      {% set current = this.state | default(“Error”)%}
      {{ trigger.id if
      trigger.event.data[‘date’] > now() - timedelta(minutes=1)
      else current}}

- name: zTest IMAP Folder Content 1

state: |-

{{ trigger.event.data[‘object’]

| regex_findall(find=“inserimento”, ignorecase=true)

#    | first | default("Errore") }}
# - name: Security Person
#   state: |-
    #   {{ trigger.event.data['text'] 
    #   | regex_findall(find="Nicola|Alice|Vale|Ilaria", ignorecase=true)
    #   | first | default("Errore") }}

sorry for caos

image

I suggest you figure out how to fix this. Some previous threads [1[2][3] using this technique have needed to have the body text decoded from base64.

AFAIK, the full contents of the event are not stored anywhere.

You can view the data from the imap_content event live, as they are received, using the “Listen for Events” function of the Events tool.

There is also an action imap.fetch which can be used to get the text, subject, sender contents of a message. However you must have extracted the uid from the event in order to use the action.