Automation for converting dates from e-mail to calendar

Hi,

I want to build an automation for the trash collecting days in our village and add them to a calendar. Our village is using a separate app and e-mail messages to inform the people about the new dates and I want to use the e-mail newsletter to achieve my goal.

I´ve tried IMPA automation so far and I can react to an example subject.

template:
  - trigger:
      - platform: event
        event_type: "imap_content"
        id: "custom_event"
        event_data:
          sender: "..."
    sensor:
      - name: house_electricity
        state: >-
          {% if 'UPS On Battery' in trigger.event.data["subject"] %}
            power_out
          {% elif 'Power Restored' in trigger.event.data["subject"] %}
            power_on
          {% endif %}

How can I expand this template to transmit a notification to my Smartphone and add a date to my calendar? I would like to test this first before I start with the content filtering.

Thank you and have a nice day

Do you want a content sensor and an automation, or just the automation? What part of the email contains the information you are interested in?

Calendar: Create Event service

Mobile App: Notifications

Hi @Didgeridrew,

the information is stored in the body of the e-mail. I´m not sure which solution fits better into my problem (sensor or automation). From my initial point of view I would say that an automation is enough.

Hi @Didgeridrew,

thanks for the links. I will read them. I´m not sure (and a newbie) if I can add the IMAP content triggering as automation too, because the examples only show it as a template.

Or do I have to setup both? The template for the event trigger and the automation when the event gets triggered?

A trigger is a trigger no matter if you use it for an automation or a template sensor. Here’s an outline of what an automation might look like. This is about as general as it can be without getting into the process of extracting the dates and message from the body of the email.

alias: Trash Collection Notification and Calendar Event
trigger:
  - platform: event
    event_type: "imap_content"
    event_data:
      sender: "..."
conditon: []
action:
  - variables:
      body: "{{ trigger.event.data['text'] }}"
      start: #template to derive the start 
      end:  #template to derive the end
      message: #template to derive the notifcation message
  - service: notify.mobile_example
    data:
      message: "{{ message }}"
      title: Trash Collection
  - service: calendar.create_event
    target:
      entity_id: calendar.example
    data:
      summary: "Trash Collection"
      start_date: "{{ start }}"
      end_date: "{{ end }}"     

Hi @Didgeridrew,

thanks for the snipped. I took a quick look into it and it looks good. I try the rest on my own. Thanks for your support :slight_smile: