Scan mail for upcoming delivery and show a blinking box

I made a little automation that shows a blinking box when a delivery is upcoming TODAY and it’s not 4pm yet.

image

You need the custom card-mod. It also requires the date in the mail itself.

Howto: first create a filter on your mail inbox (e.g. gmail) that caches all mails that announces an incoming delivery and add a label for it (here it’s named HAupcoming). I just selected the sender and 2 words for the subject. (For more security I made a new gmail account and forwarded all these mails first.)

Then adjust the platform config below and adjust your date format (here its 13.02.2021) if it’s different. It uses that to search the mail. My configuration is also set to only show before 16:00, as deliveries are never later than that.

configuration.yaml:

sensor:
  - platform: imap_email_content
      server: imap.gmail.com
      name: delivery_upcoming
      port: 993
      username: xxxxxxx
      password: xxxxxxxx
      folder: HAupcoming
      senders:
        - [email protected]
      value_template: >-
        {% if (as_timestamp(now()) | timestamp_custom('%d.%m.%Y')) in body %}
          incoming
        {% else %}
          idle  
        {% endif %}

lovelace:

- type: markdown
    content: |
      # <center>{% if is_state('sensor.delivery_upcoming', 'incoming') and ( now().hour | int) < 16 %}  <br>Incoming Delivery Today<br><br> {% else %} My awesome Home {% endif %}</center>
    style: |
      {% if is_state('sensor.delivery_upcoming', 'incoming') and ( now().hour | int) < 16 %} 
        @keyframes blink {
          50% {
            background: #966C28;
          }
        }
        ha-card {
          animation: blink 2s linear infinite;
        }        
      {% endif %}

Plain and simple. Will give this a try.