Mail and Packages: Custom component for UPS, FEDEX, and USPS

I also see that international dates not supports.

[custom_components.mail_and_packages.helpers] Arrive Date: > Tuesday, January
2022-01-12 14:00:39 INFO (SyncWorker_1) [custom_components.mail_and_packages.helpers] International dates not supported. (time data ‘> Tuesday, January’ does not match format ‘%A, %B %d’)
2022-01-12 14:00:39 DEBUG (SyncWorker_1) [custom_components.mail_and_packages.helpers] Arrive Date: > Tuesday, January
2022-01-12 14:00:39 INFO (SyncWorker_1) [custom_components.mail_and_packages.helpers] International dates not supported. (time data ‘> Tuesday, January’ does not match format ‘%A, %B %d’)
2022-01-12 14:00:39 DEBUG (SyncWorker_1) [custom_components.mail_and_packages.helpers] Arrive Date: > Tuesday, January
2022-01-12 14:00:39 INFO (SyncWorker_1) [custom_components.mail_and_packages.helpers] International dates not supported. (time data ‘> Tuesday, January’ does not match format ‘%A, %B %d’)

This is just a warning I think from my reading

After this line it should give you a email_search value: what does that say?

This might be part of the issue, the email is getting a > prefixed to the line.

DEBUG email_s[custom_components.mail_and_packages.helpers] Amazon email search address: [email protected]
2022-01-12 14:16:19 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] DEBUG imap_search: (FROM “[email protected]” SINCE “09-Jan-2022”)
2022-01-12 14:16:20 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] DEBUG email_search value: (‘OK’, [b’396 398 399 400 401’])
2022-01-12 14:16:20 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Amazon emails found: 5
2022-01-12 14:16:20 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Email Multipart: True
2022-01-12 14:16:20 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Content Type: multipart/alternative
2022-01-12 14:16:20 DEBUG (SyncWorker_5)

Says it found 5??

1 Like

Correct, I’ll have to look into filtering out the > character.

Do you think that is from my Apple email forwarding?

I also have 5 USPS mail piece for today. That seems to be correct on the card…

The amazon sensor filters thru looking for the time stamp they add to determine when you’re package counter should tick up 1 for the day, the extra > is throwing it off, so I just need to filter that out.

Keep an eye out for another beta :slight_smile:

That for all your help and great work. Really appreciate it.

Would you be able to provided one of your forwarded emails with any private info redacted for testing?
Just replace your email address with “[email protected]” and fill in the order like #123-45678-901

Instructions on how to do that for gmail are in this issue comment.

You can attach the .eml file to the PR:

Ok I am on a mac so I just downloaded (dragged) it to my desktop and edited with textedit.
Changed my from email to… [email protected]
Changed my To: email to…gmail email to [email protected]
I also changed the Order number to 123-45678-901

Let me know if that works as a test file

link to file: Dropbox - Fwd_ Your Amazon.com order #123-45678-901.eml - Simplify your life

Excellent, this will help me test to make sure the code works as planned.

Great. Let me know how else I can help

What card is that?
Looks great

default card… with on mod.
I used this one for the top:

type: picture-elements
elements:
  - type: image
    entity: null
    camera_image: camera.mail_usps
    camera_view: live
    style:
      top: 50%
      left: 50%
      width: 100%
  - type: image
    entity: null
    image: local/mail_and_packages/overlay.png
    style:
      top: 50%
      left: 50%
      width: 100%
  - type: image
    entity: camera.mail_usps
    image: local/mail_and_packages/vignette.png
    style:
      top: 50%
      left: 50%
      width: 100%
image: local/mail_and_packages/white.png
entity: camera.mail_usps
tap_action:
  action: more_info
hold_action:
  action: none

and then used the default card that is on the Beta Mail/Pkgs card… but disabled
USPS camera

Sorry to butt in here, but I have a question about a problem I am seeing.

All of my mail & packages sensors have values of “Unknown”.

I’ve tried reinstalling the integration several times, but I always get this result. Interestingly, after checking the debug logs, the integration seems to be correctly finding the emails. Here’s a little snippet of it finding my USPS Informed Delivery email (I think):

2022-01-13 16:06:24 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] DEBUG email_search value: ('OK', [b''])
2022-01-13 16:06:24 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Searching for (Your item is out for delivery) in (1) emails
2022-01-13 16:06:24 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Search for (Your item is out for delivery) count results: 0
2022-01-13 16:06:24 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Search for (['[email protected]']) with subject (Expected Delivery on) results: b'' count: 0
2022-01-13 16:06:24 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Attempting to find mail from (['[email protected]']) with subject (Out for Delivery)
2022-01-13 16:06:24 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] DEBUG imap_search: (FROM "[email protected]" SUBJECT "Out for Delivery" SINCE "13-Jan-2022")
2022-01-13 16:06:24 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] DEBUG email_search value: ('OK', [b''])
2022-01-13 16:06:24 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Searching for (Your item is out for delivery) in (1) emails
2022-01-13 16:06:24 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Search for (Your item is out for delivery) count results: 0
2022-01-13 16:06:24 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Search for (['[email protected]']) with subject (Out for Delivery) results: b'' count: 0
2022-01-13 16:06:24 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Sensor: usps_delivering Count: 0
2022-01-13 16:06:24 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Attempting to find Informed Delivery mail
2022-01-13 16:06:24 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Informed delivery search date: 13-Jan-2022
2022-01-13 16:06:24 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] DEBUG imap_search: (OR OR FROM "[email protected]" FROM "[email protected]" FROM "[email protected]" SUBJECT "Your Daily Digest" SINCE "13-Jan-2022")
2022-01-13 16:06:25 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] DEBUG email_search value: ('OK', [b'1 '])
2022-01-13 16:06:25 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Cleaning up image directory: /config/custom_components/mail_and_packages/images/
2022-01-13 16:06:25 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Checking for overlay files in: /config/custom_components/mail_and_packages/images/
2022-01-13 16:06:25 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Copying file to: /config/custom_components/mail_and_packages/images/overlay.png
2022-01-13 16:06:25 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Copying file to: /config/custom_components/mail_and_packages/images/vignette.png
2022-01-13 16:06:25 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Copying file to: /config/custom_components/mail_and_packages/images/white.png
2022-01-13 16:06:25 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Informed Delivery email found processing...
2022-01-13 16:06:25 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Extracting image from email
2022-01-13 16:06:25 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Removing duplicate images.
2022-01-13 16:06:25 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Removing USPS announcement images.
2022-01-13 16:06:25 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Image Count: 1
2022-01-13 16:06:25 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Resizing images to 724x320...
2022-01-13 16:06:25 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Creating array of image files...
2022-01-13 16:06:25 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Generating animated GIF
2022-01-13 16:06:25 INFO (SyncWorker_5) [custom_components.mail_and_packages.helpers] Mail image generated.
2022-01-13 16:06:25 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Sensor: usps_mail Count: 1
2022-01-13 16:06:25 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Sensor: usps_packages Count: 0
2022-01-13 16:06:25 DEBUG (SyncWorker_5) [custom_components.mail_and_packages.helpers] Sensor: zpackages_delivered Count: 0
2022-01-13 16:06:25 DEBUG (MainThread) [custom_components.mail_and_packages] Finished fetching Mail and Packages (imap.mail.yahoo.com) data in 11.730 seconds

Anyone else seen this? Let me know if I can provide any other information. Thanks!

Not sure I have everything set up the right way or understand how it should tally the mail in transit etc.

My amazon emails now show up in the debug log (see file link) but nothing changes in the In transit numbers etc

Also attached is a UPS email (link to file below) and I would have thought that it showed up in the logs?

UPS email


file link: Dropbox - UPS Ship Notification, Tracking Number 1Z378V1WYWxxxxxxxx.eml - Simplify your life

Link to log file: Dropbox - Logfile-mailandpkges.rtf - Simplify your life

Any I doing something wrong?

Remember it’s the day of delivery emails we’re utilizing, not “estimated” delivery date ones.

Unknown sensor status occurs when there is an error hit while processing your emails, review all the debug info for problems.

I updated the template for “Deliveries Summary” example so that it only displays if mail or a package is expected. The text was way too long for me, and I didn’t need to know that I’m expecting zero Amazon packages. Planning to display this message on my dashboard. HTH!

sensors:
    mail_deliveries_message:
      friendly_name: "Deliveries Summary"
      value_template: > 
        {# Deliveries Sentence #}
            {% macro deliveries_sentence() -%}
        {%- if states("sensor.mail_usps_mail")|int(0) > 0 -%}
          {{states("sensor.mail_usps_mail")|int(0)}}{{' '}} 
            {%- if states("sensor.mail_usps_mail")|int(0) <= 1 -%}
              pieces of mail
            {%- else -%}
              pieces of mail
            {%- endif -%}
          {{' '}}will be delivered.{{' '}} 
        {%- endif -%}
        {%- if states("sensor.mail_usps_delivering")|int(0) > 0 -%}
            {{states("sensor.mail_usps_delivering")|int(0)}}{{' '}}
          {%- if states("sensor.mail_usps_delivering")|int(0) == 1 -%}
            USPS package is
          {%- else -%}
            USPS packages are
          {%- endif -%}
        {{' '}}in transit.{{' '}}
        {%- endif -%}
        {%- if states("sensor.mail_fedex_delivering")|int(0) > 0 -%}
            {{states("sensor.mail_fedex_delivering")|int(0)}}{{' '}}
          {%- if states("sensor.mail_fedex_delivering")|int(0) == 1 -%}
            FedEx package is
          {%- else -%}
            FedEx packages are
          {%- endif -%}
        {{' '}}in transit.{{' '}}
        {%- endif -%}
        {%- if states("sensor.mail_ups_delivering")|int(0) > 0 -%}
            {{states("sensor.mail_ups_delivering")|int(0)}}{{' '}}
          {%- if states("sensor.mail_ups_delivering")|int(0) == 1 -%}
            UPS package is
          {%- else -%}
            UPS packages are
          {%- endif -%}
        {{' '}}in transit.{{' '}}
        {%- endif -%}
        {%- if states("sensor.mail_amazon_packages")|int(0) > 0 -%}
            {{states("sensor.mail_amazon_packages")|int(0)}}{{' '}}
          {%- if states("sensor.mail_amazon_packages")|int(0) == 1 -%}
            Amazon package is
          {%- else -%}
            Amazon packages are
          {%- endif -%}
        {{' '}}in transit.{{' '}}
        {%- endif -%}
        {%- endmacro %}
        {{deliveries_sentence()}}
2 Likes

I’ve noticed that after a restart of HA, Mail and Packages doesn’t pick anything up for that day any longer, so there’s no data until the following day. Presumably this is because it only looks at unread messages? If I log into the mailbox I’m using and mark the messages unread, it will then pick up the data.

Wondering if there’s a way to force it to re-read today’s messages after a restart, or alternately, to store the data locally for the current day so that it persists across reboots?

This is indeed not how it works. We are not searching for unread message at anytime.

What email provider are you using?