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

After updating .0.110 and updating Mail_and_packages, I now have sensor.mail_fedex_delivered_2, sensor.mail_fedex_delivering_2, and sensor.mail_fedex_packages_2

The original entities were showing as unavailable, and restored in Configuration>entities so I deleted them (right click, delete in Configuration>entites page) and restarted thinking (perhaps foolishly) that would fix my issue, however it did not. I am on the most recent version of HA, Mail and Packages, and HACS.

I remember last time I had an issue, you needed to see my system health page, so here it is.

Delete the sensors that are broken, and rename the working ones.

oh duh. thanks!

Running HA 110.3. Installed the Mail & Packages repository via HACS. Restarted HA. Went to Configuration/Integrations, clicked +, Mail & Packages is not listed. Verified that files are present in /custom_components/mail_and_packages/

Am I missing something?

I’ve seen this happen before when there’s an issue with the language selected in Home Assistant, click your profile in Home Assistant and set the language.

Step 1 (click the circle):
image

Step 2:
image

Very odd. I changed from English to another language then back to English. Checked Configuration/Integrations and “Mail and Packages” is now there. Thanks

In my case mine was set to something like “default” then I went to “English” and all the stuff populated.

Modified the “arriving today” sensor template so it will only display a message about a package being delivered if there actually is a package being delivered. If no packages are being delivered the message will be “No package will be delivered today.”

  - platform: template
    sensors:
      mail_deliveries_message:
        friendly_name: "Deliveries Summary"
        entity_id: 
          - sensor.mail_usps_mail
          - sensor.mail_usps_delivering
          - sensor.mail_fedex_delivering
          - sensor.mail_ups_delivering
          - sensor.mail_amazon_packages
        value_template: > 
          {# Deliveries Sentence #}
            {% macro deliveries_sentence() -%}
                  {%- if states("sensor.mail_usps_mail")|int == 0 -%}
                    No
                  {%- else -%}
                    {{states("sensor.mail_usps_mail")|int}}
                  {%- endif -%}
                {{' '}} 
                  {%- if states("sensor.mail_usps_mail")|int <= 1 -%}
                    mail
                  {%- else -%}
                    pieces of mail
                  {%- endif -%}
                {{' '}}will be delivered today.{{' '}}
                {%- if states("sensor.mail_usps_delivering")|int == 0 and states("sensor.mail_fedex_delivering")|int == 0 and states("sensor.mail_ups_delivering")|int == 0 and states("sensor.mail_amazon_packages")|int == 0 -%}
                  No packages will be delivered today.
                {%- else -%}
                  {%- if states("sensor.mail_usps_delivering")|int > 0 -%}
                      {{states("sensor.mail_usps_delivering")|int}}{{' '}}
                      {%- if states("sensor.mail_usps_delivering")|int == 1 -%}
                          USPS package
                        {%- else -%}
                          USPS packages
                        {%- endif -%}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- if states("sensor.mail_fedex_delivering")|int > 0 or states("sensor.mail_ups_delivering")|int > 0 or states("sensor.mail_amazon_packages")|int > 0-%}
                      {{' and '}}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- if states("sensor.mail_fedex_delivering")|int > 0 -%}
                      {{states("sensor.mail_fedex_delivering")|int}}{{' '}}
                      {%- if states("sensor.mail_fedex_delivering")|int == 1 -%}
                          FedEx package
                        {%- else -%}
                          FedEx packages
                        {%- endif -%}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- if states("sensor.mail_ups_delivering")|int > 0 or states("sensor.mail_amazon_packages")|int > 0 -%}
                      {{' and '}}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- if states("sensor.mail_ups_delivering")|int > 0 -%}
                      {{states("sensor.mail_ups_delivering")|int}}{{' '}}
                      {%- if states("sensor.mail_ups_delivering")|int == 1 -%}
                          UPS package
                        {%- else -%}
                          UPS packages
                        {%- endif -%}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- if states("sensor.mail_amazon_packages")|int > 0 -%}
                      {{' and '}}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- if states("sensor.mail_amazon_packages")|int > 0 -%}
                      {{states("sensor.mail_amazon_packages")|int}}{{' '}}
                      {%- if states("sensor.mail_amazon_packages")|int == 1 -%}
                          Amazon package
                        {%- else -%}
                          Amazon packages
                        {%- endif -%}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- endif -%}
                {{' '}}will be delivered.
            {%- endmacro %}
          {{deliveries_sentence()}}
1 Like

2 tweaks to the above as I caught two two things. First change adjusts the mail delivery message so it’s now “no mail” “1 piece of mail” and “x pieces of mail” instead of “no mail” “1 mail” and “x pieces of mail” (just better grammatically). Second there was an extra “will be delivered” because of a bad endif at the end of the code block. @firstof9 can you update the wiki?

  - platform: template
    sensors:
      mail_deliveries_message:
        friendly_name: "Deliveries Summary"
        entity_id: 
          - sensor.mail_usps_mail
          - sensor.mail_usps_delivering
          - sensor.mail_fedex_delivering
          - sensor.mail_ups_delivering
          - sensor.mail_amazon_packages
        value_template: > 
          {# Deliveries Sentence #}
            {% macro deliveries_sentence() -%}
                  {%- if states("sensor.mail_usps_mail")|int == 0 -%}
                    No mail
                  {%- elif states("sensor.mail_usps_mail")|int == 1 -%}
                    1 piece of mail
                  {%- elif states("sensor.mail_usps_mail")|int > 1 -%}
                    {{states("sensor.mail_usps_mail")|int}} pieces of mail
                  {%- endif -%}
                {{' '}}will be delivered today.{{' '}}
                {%- if states("sensor.mail_usps_delivering")|int == 0 and states("sensor.mail_fedex_delivering")|int == 0 and states("sensor.mail_ups_delivering")|int == 0 and states("sensor.mail_amazon_packages")|int == 0 -%}
                  No packages will be delivered today.
                {%- else -%}
                  {%- if states("sensor.mail_usps_delivering")|int > 0 -%}
                      {{states("sensor.mail_usps_delivering")|int}}{{' '}}
                      {%- if states("sensor.mail_usps_delivering")|int == 1 -%}
                          USPS package
                        {%- else -%}
                          USPS packages
                        {%- endif -%}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- if states("sensor.mail_fedex_delivering")|int > 0 or states("sensor.mail_ups_delivering")|int > 0 or states("sensor.mail_amazon_packages")|int > 0-%}
                      {{' and '}}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- if states("sensor.mail_fedex_delivering")|int > 0 -%}
                      {{states("sensor.mail_fedex_delivering")|int}}{{' '}}
                      {%- if states("sensor.mail_fedex_delivering")|int == 1 -%}
                          FedEx package
                        {%- else -%}
                          FedEx packages
                        {%- endif -%}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- if states("sensor.mail_ups_delivering")|int > 0 or states("sensor.mail_amazon_packages")|int > 0 -%}
                      {{' and '}}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- if states("sensor.mail_ups_delivering")|int > 0 -%}
                      {{states("sensor.mail_ups_delivering")|int}}{{' '}}
                      {%- if states("sensor.mail_ups_delivering")|int == 1 -%}
                          UPS package
                        {%- else -%}
                          UPS packages
                        {%- endif -%}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- if states("sensor.mail_amazon_packages")|int > 0 -%}
                      {{' and '}}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- if states("sensor.mail_amazon_packages")|int > 0 -%}
                      {{states("sensor.mail_amazon_packages")|int}}{{' '}}
                      {%- if states("sensor.mail_amazon_packages")|int == 1 -%}
                          Amazon package
                        {%- else -%}
                          Amazon packages
                        {%- endif -%}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                {{' '}}will be delivered.
                {%- endif -%}
            {%- endmacro %}
          {{deliveries_sentence()}}

Sure thing.

1 Like

Thought i’d debugged this more carefully but over the weekend ran into another bug with extra "and"s being appended. This one seems to be working:

  - platform: template
    sensors:
      mail_deliveries_message:
        friendly_name: "Deliveries Summary"
        entity_id: 
          - sensor.mail_usps_mail
          - sensor.mail_usps_delivering
          - sensor.mail_fedex_delivering
          - sensor.mail_ups_delivering
          - sensor.mail_amazon_packages
        value_template: > 
          {# Deliveries Sentence #}
            {% macro deliveries_sentence() -%}
                  {%- if states("sensor.mail_usps_mail")|int == 0 -%}
                    No mail
                  {%- elif states("sensor.mail_usps_mail")|int == 1 -%}
                    1 piece of mail
                  {%- elif states("sensor.mail_usps_mail")|int > 1 -%}
                    {{states("sensor.mail_usps_mail")|int}} pieces of mail
                  {%- endif -%}
                {{' '}}will be delivered today.{{' '}}
                {%- if states("sensor.mail_usps_delivering")|int == 0 and states("sensor.mail_fedex_delivering")|int == 0 and states("sensor.mail_ups_delivering")|int == 0 -%}
                  No packages will be delivered today.
                {%- else -%}
                  {%- if states("sensor.mail_usps_delivering")|int > 0 -%}
                      {{states("sensor.mail_usps_delivering")|int}}{{' '}}
                      {%- if states("sensor.mail_usps_delivering")|int == 1 -%}
                          USPS package
                        {%- else -%}
                          USPS packages
                        {%- endif -%}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- if states("sensor.mail_usps_delivering")|int > 0 and states("sensor.mail_fedex_delivering")|int > 0 -%}
                      {{' and '}}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- if states("sensor.mail_fedex_delivering")|int > 0 -%}
                      {{states("sensor.mail_fedex_delivering")|int}}{{' '}}
                      {%- if states("sensor.mail_fedex_delivering")|int == 1 -%}
                          FedEx package
                        {%- else -%}
                          FedEx packages
                        {%- endif -%}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- if (states("sensor.mail_usps_delivering")|int > 0 or states("sensor.mail_fedex_delivering")|int > 0) and states("sensor.mail_ups_delivering")|int > 0 -%}
                      {{' and '}}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- if states("sensor.mail_ups_delivering")|int > 0 -%}
                      {{states("sensor.mail_ups_delivering")|int}}{{' '}}
                      {%- if states("sensor.mail_ups_delivering")|int == 1 -%}
                          UPS package
                        {%- else -%}
                          UPS packages
                        {%- endif -%}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- if (states("sensor.mail_usps_delivering")|int > 0 or states("sensor.mail_fedex_delivering")|int > 0 or states("sensor.mail_ups_delivering")|int > 0) and states("sensor.mail_amazon_packages")|int > 0 -%}
                      {{' and '}}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                  {%- if states("sensor.mail_amazon_packages")|int > 0 -%}
                      {{states("sensor.mail_amazon_packages")|int}}{{' '}}
                      {%- if states("sensor.mail_amazon_packages")|int == 1 -%}
                          Amazon package
                        {%- else -%}
                          Amazon packages
                        {%- endif -%}
                    {%- else -%}
                        {{''}}
                    {%- endif -%}
                {{' '}}will be delivered.
                {%- endif -%}
            {%- endmacro %}
          {{deliveries_sentence()}}
1 Like

I’ll update the wiki :slight_smile:

1 Like

Hey everyone thought I’d share this here. Not sure if anyone else is doing this but I discovered it is possible to send the mail.today.gif file as an attachment in an ios notification. The initial notification displays the image as a small thumbnail but a long press on it pulls up a full size view of the image.

I was only getting 1 piece of mail today so I am not sure if it will cycle through multiple images yet. I wrote up an automation to send the mail.today.gif every morning. From looking back my email usually arrives between 7-8:30am so I set the trigger as 9am to make sure the email is actually there. I’ll see how it goes tomorrow. I included the action part of the automation below in case anyone is interested.

data:
  message: Today's Mail
  data:
    attachment:
      content-type: gif
      url: /local/mail_and_packages/mail_today.gif
service: notify.mobile_your_mobile_app

If this is how you are doing your notifications, highly recommend changing the directory to /images/mail_and_packages/mail_today.gif the /local/ directory does not have any authentication and is exposed to the public.

Thanks for the tip I will try that. I don’t currently have an images folder so I try setting it up>

If you hit Options on the integration and type in /config/images/mail_and_packages/ for the image path it should attempt to create the directory for you.

Indeed it did!

1 Like

For the HASS mobile app the notification attachments are required to be accessible from the internet for Android and iOS.

However, work has started to add a camera component that points to an mp4 version of the gif that may be able to be pushed using the dynamic notification in iOS and the standard attachments pagedescribes how to use the a camera component with Android in the first section.

I believe, if I remember some past setups with security clips correctly, the video files does not need to be in the www folder because it used the HASS stream.

Testers Needed
In the mail and packages custom card, I added the option of using a camera entity (if you set one up for the mail gif) to display the mail image instead of a URL to the gif.

1 Like

Going with the Notification Automation from here, it appears to be spamming me every five minutes even though nothing changes. Is there something wrong with the code in the link or did I mess it up on my end some how? I’ve turned the automation off for now to stop it.

Will the docs be updated for Amazon soon? If not, has anyone posted the info somewhere else?

EDIT: Looks like that’s in a beta from March, and is not in the current non-beta version.