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

Fixed for me, thanks!

1 Like

Iā€™m running b21 (just updated), but my Amazon sensor is reporting 3 packages, even though I donā€™t have any emails out. (i do have 1 package en-route today, but I never received an email for it). Itā€™s been incorrectly reporting 3 Amazon packages for the last couple days

Logs at https://pastebin.com/bEYNBTKH

EDIT: When I review the sensor.mail_amazon_packages entity, it just shows 1 order, which was shipped and delivered on Dec 28 (i used overnight shipping). Maybe the entity got confused when a new package was shipped and delivered on the same day?

Looks like something happened with the amazon forwarding bit, Iā€™ll have a look.

Give b22 a shot. Based on my tests it should work properly now.

Iā€™m trying to track the total number of packages arriving by combining all the mail sensors. Iā€™m not very familiar with templates but this is what Iā€™ve come up with. It validates and currently shows ā€œ0ā€ (I donā€™t have any packages arriving).

Does this look right?

- platform: template
    sensors:
      packages_remaining:
        friendly_name: Remaining Deliveries Today
        icon_template: "mdi:package-variant-closed"
        value_template: >-
          {{ states.sensor.mail_amazon_packages.state | int - states.sensor.mail_amazon_packages_delivered.state | int +
          states.sensor.mail_ups_packages.state | int - states.sensor.mail_ups_delivered.state | int +
          states.sensor.mail_fedex_packages.state | int - states.sensor.mail_fedex_delivered.state | int +
          states.sensor.mail_usps_packages.state | int - states.sensor.mail_usps_delivered.state | int }}

b22 seems to have fixed the issue. thanks

:tada: :partying_face:

1 Like

Most of that logic is already in the ā€œIn Transitā€ sensor, the only thing youā€™d need to keep is the amazon stuff.

So how would I add the amazon stuff to the ā€œIn Transitā€ sensor?

My end goal is to add it to an Apple Watch complication. This is the example Iā€™m trying to reach. I figured it was easier to match this template with a single sensor (that collected all sensors) vs adding each individual sensor.

apple_watch_packages_progress:
  friendly_name: Apple Watch Packages Progress
  icon_template: "mdi:package-variant-closed"
  value_template: >- 
    {% if states.sensor.mail_amazon_packages.state | int == 0 %}
      1.0
    {% else %}
      {{ (states.sensor.mail_amazon_packages_delivered.state | float) / (states.sensor.mail_amazon_packages.state | float) }}
    {% endif %}

This should do it:

- platform: template
    sensors:
      packages_remaining:
        friendly_name: Remaining Deliveries Today
        icon_template: "mdi:package-variant-closed"
        value_template: "{{ states('sensor.mail_packages_in_transit') | int + (states('sensor.mail_amazon_packages') | int - states('sensor.mail_amazon_packages_delivered') | int) }}"

EDIT: added missing 's

Does the ā€œin transitā€ subtract the delivered or would I need make a template for delivered packages as well?

I want my watch to show how many are arriving with a graph indicating how many have already been delivered.

As ā€˜in transitā€™ goes down ā€˜deliveredā€™ goes up.

Great so using your code, I added a 2nd entity for my wifeā€™s amazon. Does this still look good?

- platform: template
    sensors:
      packages_remaining:
        friendly_name: Remaining Deliveries Today
        icon_template: "mdi:package-variant-closed"
        value_template: "{{ states.sensor.mail_packages_in_transit.state | int + states.sensor.mail_amazon_packages.state | int + states.sensor.mail_amazon_packages_2.state | int - states.sensor.mail_amazon_packages_delivered.state | int + states.sensor.mail_amazon_packages_delivered_2.state | int }}"

And how would I add your sensor template to this sensor for the watch?

apple_watch_packages_progress:
  friendly_name: Apple Watch Packages Progress
  icon_template: "mdi:package-variant-closed"
  value_template: >- 
    {% if states.sensor.mail_amazon_packages.state | int == 0 %}
      1.0
    {% else %}
      {{ (states.sensor.mail_amazon_packages_delivered.state | float) / (states.sensor.mail_amazon_packages.state | float) }}
    {% endif %}

Donā€™t use states.state use states().

EDIT: and using states() does not pass the template check. It results in an unavailable upon HA restart.

That covers the packages remaining sensor. What do I do about the delivered sensor?

Iā€™m trying to replace the below code with all of my packages in transit and all of my packages delivered.

{% if states.sensor.mail_amazon_packages.state | int == 0 %}
      1.0
    {% else %}
      {{ (states.sensor.mail_amazon_packages_delivered.state | float) / (states.sensor.mail_amazon_packages.state | float) }}
    {% endif %}

Thank you for a fantastic component! Iā€™m sure this info is out there somewhere, but I didnā€™t see it in the wiki and couldnā€™t easily find it in this forum post. Iā€™m looking for a summary of exactly what each sensor means. I feel like there is something incorrect with my setup, but want to make sure. For example, should mail_packages_in_transit show an aggregate count of all packages being delivered today? What is the difference between mail_ups_packages and mail_ups_delivering?

In my case, I have one package from UPS being delivered today, and the component has picked that up. But the only sensor that has been updated is mail_ups_delivering (set to 1). But mail_ups_packages is 0 and mail_packages_in_transit is 0. Should those sensors have been updated as well?

My lovelace card looks like:
image

In the logs I see this regarding the UPS emails:

2020-12-31 10:16:30 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] Attempting to find mail from (['[email protected]']) with subject (Your UPS Package was delivered)
2020-12-31 10:16:30 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] DEBUG imap_search: (FROM "[email protected]" SUBJECT "Your UPS Package was delivered" SINCE "31-Dec-2020")
2020-12-31 10:16:30 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] Searching for (['Tracking Number']) in (0) emails
2020-12-31 10:16:30 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] Search for (['Tracking Number']) count results: 0
2020-12-31 10:16:30 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] Search for (['[email protected]']) with subject (Your UPS Package was delivered) results: b'' count: 0
2020-12-31 10:16:30 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] Attempting to find mail from (['[email protected]']) with subject (Your UPS Packages were delivered)
2020-12-31 10:16:30 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] DEBUG imap_search: (FROM "[email protected]" SUBJECT "Your UPS Packages were delivered" SINCE "31-Dec-2020")
2020-12-31 10:16:30 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] Searching for (['Tracking Number']) in (0) emails
2020-12-31 10:16:30 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] Search for (['Tracking Number']) count results: 0
2020-12-31 10:16:30 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] Search for (['[email protected]']) with subject (Your UPS Packages were delivered) results: b'' count: 0
2020-12-31 10:16:30 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] Attempting to find mail from (['[email protected]']) with subject (UPS Update: Package Scheduled for Delivery Today)
2020-12-31 10:16:30 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] DEBUG imap_search: (FROM "[email protected]" SUBJECT "UPS Update: Package Scheduled for Delivery Today" SINCE "31-Dec-2020")
2020-12-31 10:16:30 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] Searching for (['Tracking Number']) in (0) emails
2020-12-31 10:16:30 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] Search for (['Tracking Number']) count results: 0
2020-12-31 10:16:30 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] Search for (['[email protected]']) with subject (UPS Update: Package Scheduled for Delivery Today) results: b'' count: 0
2020-12-31 10:16:30 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] Attempting to find mail from (['[email protected]']) with subject (UPS Update: Follow Your Delivery on a Live Map)
2020-12-31 10:16:30 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] DEBUG imap_search: (FROM "[email protected]" SUBJECT "UPS Update: Follow Your Delivery on a Live Map" SINCE "31-Dec-2020")
2020-12-31 10:16:30 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] Searching for (['Tracking Number']) in (3) emails
2020-12-31 10:16:31 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] Found (['Tracking Number']) in email
2020-12-31 10:16:31 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] Search for (['Tracking Number']) count results: 1
2020-12-31 10:16:31 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] Search for (['[email protected]']) with subject (UPS Update: Follow Your Delivery on a Live Map) results: b'255' count: 1
2020-12-31 10:16:31 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] Searching for tracking numbers...
2020-12-31 10:16:31 DEBUG (SyncWorker_11) [custom_components.mail_and_packages.helpers] No tracking numbers found

Thank you for any help!

Are you running the latest beta? b23 should be up.

I was running b23, but I updated after I saw this initial issue. So, I decided to uninstall and reinstall. But now, Iā€™m getting an error on step 2 of the configuration page. ā€œuser input malformedā€.

Please check the Home Assistant log for error messages.

EDIT: You might need to enter "" where the ā€œAmazon forwarded email addressesā€ field is, Iā€™ll have to take a look as to why itā€™s causing an error.

Yeah, that was in there originally and I tried removing it. I just tried completely removing the integration and re-adding it using the beta version from the start and Iā€™m still getting the ā€œuser input malformedā€ error. But no error message is getting logged.

I also tried setting the folder back to INBOX and tried changing the options selected in the ā€œsensors listā€ but I canā€™t get past this form.

Thanks so much.