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

Feature requests are fine, I’ve put an issue in for it for tracking.

@ZombiEd Could you please rummage around Amazon and see if there are notification options? The detail you gave in your last post was perfect and exactly what we need to understand your issue and propose solutions.

The language provided in the example summary statement is not completely accurate after you understand how the Amazon portion currently works. It should be more or less “You should expect 2 Amazon deliveries within the next few days.” Maybe something to edit, along with maybe hiding carriers that don’t have anything to report.

If the Amazon sensor continues to sweep 3 days of emails to get the count and we included the delivery emails from their contractors, it still isn’t 1 to 1 which is why I stuck to only the activity the day of delivery for the other package carriers. The missing piece for amazon which the other carriers have is the email that says they will be delivering it today.

Keeping a tracking number inventory, which @firstof9 has the beginnings of, would be the key to make sure the sensor is telling the truth.

I have a package that just shipped from Amazon today so excited to see if it comes up in the alerts. Comes from [email protected].

So if HA checks for new emails and finds the Amazon one before the one from the USPS comes in, will I get two alerts? I have it set to check every 60 minutes but that doesn’t mean USPS will show before the next check.

That depends on the automation setup, but if you’re using some of the examples from the wiki, yes you’d get an alert because the “in transit” sensor will have ticked +1 packages. (For USPS not Amazon)

I’m not sure there’s a good solution for this, but both me and my wife maintain separate Amazon accounts, which means she gets all the email notifications for packages ordered from her account. There are a couple options that might work, none of them great IMO.

  1. If Amazon had a notification option to send shipment notifications to multiple email accounts, I think this would be the solution and the best for my use-case
  2. I could set a filter rule on my wife’s email that forwarded all Amazon shipment emails to me, but then the integration would still not see them because it would come from her email, rather than Amazon directly
  3. The integration could log in to both accounts to look for email messages, then combine the totals for the sensors
  4. We could share the same account, but that option is not viable for us, so that’s a non-starter for me.

Has this already been discussed, and does anyone see any other alternatives?

1 Like

2 or 3 would be your best bet.

2 would require you to modify the code to add her email address and a sender for the amazon sensor to pick up. Heavy lift and hard to maintain through upgrades.

3 you can have more than one instance of the integration. Have her create a second instance with her email credentials. You will have duplicate sensors but you don’t have to have them displayed. You can then create a home assistant sensor template to add the two amazon sensors together and use this sensor as your official amazon count.

Thanks. It didn’t even occur to me that I could do the addition on my own, although that means I wouldn’t be able to use the Custom Lovelace Card, right? It assumes certain sensors for its values?

Thanks, so right now I’m using your wiki automation. I received an email from Amazon that a package is on it’s way, but hours later no alert. So far today haven’t gotten any emails from USPS so not sure still if it needs something from the USPS to trigger or not.

Though I see you must have tweaked your value_templates beyond dealing with the midnight thing as mine just has entries for usps and usps delivereing in it.

EDIT: Updated the automation with your updates and nothing triggered.

Since it’s just an example, you could add a trigger for the amazon sensor(s) :wink:

Quick example (sensor names could be wrong):

  trigger:
  #Trigger if mail or packages get updated
    - platform: state
      entity_id: sensor.mail_usps_mail
    - platform: state
      entity_id: sensor.mail_usps_delivering
    - platform: state
      entity_id: sensor.mail_amazon_packages
  #send only if mail or packages are more than 0
  condition:
    - condition: or
      conditions:
        - condition: template
          value_template: "{{ ((as_timestamp(now()) - as_timestamp(states.sensor.mail_usps_mail.last_changed)) < 15 and sensor.mail_usps_mail > 0) }}"
        - condition: template
          value_template: "{{ ((as_timestamp(now()) - as_timestamp(states.sensor.mail_packages_in_transit.last_changed)) < 15 and sensor.mail_packages_in_transit > 0) }}"
        - condition: template
          value_template: "{{ ((as_timestamp(now()) - as_timestamp(states.sensor.mail_amazon_packages.last_changed)) < 15 and sensor.mail_amazon_packages > 0) }}"
...

Thanks. Yeah that’s what I was just reading about, difference between triggers and conditions and wondering if this thing would trigger for Amazon packages.

By the way, the way the sample automation is written, the Amazon package won’t trigger anymore for the existing package due to the date last changed no?

The card allows you place any sensor the predefined areas (USPS Mail, USPS Packages, UPS, FedEx, Mail Summary) using the visual editor or the code editor. I have not added a placeholder for the Amazon sensor for all of the reason stated recently in this thread. I have kept Amazon out of the card and totals due to the inaccuracy of the current methods.

There is a place for the delivery summary text sensor and Amazon is in the example provided. You would just need to modify the Amazon portion of the template to the new sensor template you created that is adding your two Mail and Packages Amazon sensors together.

If your Amazon sensor already has the value for today, that value doesn’t change, and you updated your automation, the Amazon sensor won’t trigger the action.

You can manually change the Amazon sensor state to 0 in the developer tools section by clicking on the name of the sensor and going to the top of the page, enter 0 for state and clicking ‘set state’. The next time Mail and Packages checks email it will pick up the Amazon emails again and trigger, or you can manually set it back to a value greater than 0 and it will also trigger the automation.

Thanks. But wouldn’t I have to change like states.sensor.mail_amazon_packages.last_changed as I’m making the assumption it won’t look at mail older than the date it last checked? Not sure how I manually change the states value as I can only select the sensor itself in the developer tools and set it to zero from what I can see.

All the triggers are an or function, so if any of them change the actions will trigger.

Right but since the trigger failed to happen due to the original automation code, and now it was tweaked, are you saying it should still pick up the Amazon shipping email? I figured it would check the inbox of my email account and only look at items since the last time the sensor was updated. So because it’s like 6 hours since I got the Amazon email and now in theory have added it to the automation would it find it again as it’s not right now.

From what I was able to figure out today is that Amazon will send you notifications if shipped by Amazon. I did see somewhere that shipped by UPS, FedEx, etc, the delivery notifications will come from the carrier. I can’t remember where I saw it, but experience for has been that is the norm.

The big issue is that it looks like Amazon may be moving to text messaging for notifications. All searches for notifications took me to text notification subscription screen. I could not find anywhere where you can opt in or out of email messages. So if they are now active by default, the link where I turned email alerts on is no longer available under the your account options. I’m assuming that if I subscribe to text notification, I will no longer get email notifications but I can’t confirm. You can also turn on delivery notifications in the Amazon app though like text messages, I’m not sure how you can gain access to that info for HA.

You’d have to wait for it to tick +1 again.

0.2.2-b11

:sparkles:Changes :sparkles:

  • Add Amazon Delivered Sensor
  • Amazon delivered image now downloads into the image directory

This will download the image Amazon takes when they deliver your package to your door/porch/etc and place it in the images directory with the USPS mail (if applicable).

Remember to reconfigure via Options to enable the Amazon Delivered sensor.

The last changed attribute is managed by the system. So by you manually updating the state (the value) the system considers that a change and automatically updates the last changed attribute.

Also, all the other sensors looks at all email that matches for the current day each time it scans. It does not remember which it found previously, no need to. If the numbers are the same, the sensors are not considered to have been updated, the state did not change, so the attribute of last changed is not updated by home assistant. In your case, if the amazon sensor already shows 1 six hours ago and you changed the automation and did not receive new email the state is still 1 and your last changed would still be 6 hours ago and the automation would not continue past the conditions. Now, if you manipulate the state like I suggested, that would prompt home assistant to change last changed attribute because you changed the state manually.

1 Like