Aftership package tracking

I use the Aftership app on my phone to track all my incoming packages. It’s free, looks good and syncs with multiple devices via their cloud. I wanted to integrate the state of incoming packages into Hass but unfortunately there is no Aftership component and I know zero Python so I Macgyver’d it with a couple of Rest sensors!

First off, you’ll need a free Aftership account and grab your API-key (login on the site -> Settings -> API).

The following sensors will provide information on your last added shipment. You can duplicate this for more sensors and change the value template [0] to [1] and [-1] to [-2] for the second to last added shipment etc.

In your configuration.yaml add:

  - platform: rest
    name: Package Title
    resource: https://api.aftership.com/v4/trackings/
    value_template: '{{ value_json["data"]["trackings"][0]["title"] }}'
    headers:
      aftership-api-key: YOUR-API-KEY
      Content-Type: application/json
  - platform: rest
    name: Package Tracking Number
    resource: https://api.aftership.com/v4/trackings/
    value_template: '{{ value_json["data"]["trackings"][0]["tracking_number"] }}'
    headers:
      aftership-api-key: YOUR-API-KEY
      Content-Type: application/json
  - platform: rest
    name: Package Checkpoint
    resource: https://api.aftership.com/v4/trackings/
    value_template: '{{ value_json["data"]["trackings"][0]["checkpoints"][-1]["message"] }}'
    headers:
      aftership-api-key: YOUR-API-KEY
      Content-Type: application/json
  - platform: rest
    name: Package Status
    resource: https://api.aftership.com/v4/trackings/
    value_template: '{{ value_json["data"]["trackings"][0]["tag"]}}'
    headers:
      aftership-api-key: YOUR-API-KEY
      Content-Type: application/json

I used following mdi icons in customize.yaml: mdi:package mdi:routes mdi:account-card-details

6 Likes

So for a 2nd package it would be the following:

  - platform: rest
    name: Package Title
    resource: https://api.aftership.com/v4/trackings/
    value_template: '{{ value_json["data"]["trackings"][1]["title"] }}'
    headers:
      aftership-api-key: YOUR-API-KEY
      Content-Type: application/json
  - platform: rest
    name: Package Tracking Number
    resource: https://api.aftership.com/v4/trackings/
    value_template: '{{ value_json["data"]["trackings"][1]["tracking_number"] }}'
    headers:
      aftership-api-key: YOUR-API-KEY
      Content-Type: application/json
  - platform: rest
    name: Package Checkpoint
    resource: https://api.aftership.com/v4/trackings/
    value_template: '{{ value_json["data"]["trackings"][1]["checkpoints"][-2]["message"] }}'
    headers:
      aftership-api-key: YOUR-API-KEY
      Content-Type: application/json
  - platform: rest
    name: Package Status
    resource: https://api.aftership.com/v4/trackings/
    value_template: '{{ value_json["data"]["trackings"][1]["tag"]}}'
    headers:
      aftership-api-key: YOUR-API-KEY
      Content-Type: application/json
2 Likes

Yes, that should work. Make sure to give it a unique name like “Package Status 2” or something.

@capturingnoise

I am considering setting this up, but I have a few questions.

Imagine I set up 3+ addiional package listings ([1],[2],[3],etc).
Is there a way to hide them if they are empty/null?

I am trying to determine if this reasonable to use for a variable amount of tracked packages.

1 Like

would it be possible have a input_number to replace [0] [1] [2] and so on to show packages in order that you chose the package you want to see?
how to go about it?

1 Like

For those interested I created a simple state card to do just this. Initial idea came from this topic :slight_smile:

repo: https://github.com/tr1plus/ha-aftership

2 Likes

Well - I see somebody else is into planted freshwater tanks! :slight_smile: Me too!

1 Like

yup, most of my aquarium stuff is automated using hass :slight_smile:

@Triplus i have tryed and folowed instruction but all im getting is:

1

any toughts?

Hey, could you create an issue in the repo? Will make it a little easier to track this (as this isn’t the “official” space to do this")
Make sure authorizations of the files you copied is correct.

Well… that deserves a post…

May do that once my co2 equipment comes in. As I also be getting a solenoid to automate :wink:

I added a PR for true aftership platform - would love feedback if this works for you.

Pull-request is at https://github.com/home-assistant/home-assistant/pull/18034

1 Like

Great !
Can you add the Last checkpoint to the card as well ?
It would be very useful.