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
sturgeo
(John)
August 11, 2017, 2:00pm
2
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.
Ruthalas
(Ruthalas)
June 15, 2018, 5:07pm
4
@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
vMeph
June 18, 2018, 11:44pm
5
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
Triplus
(Joren C)
June 27, 2018, 5:41am
6
For those interested I created a simple state card to do just this. Initial idea came from this topic
repo: https://github.com/tr1plus/ha-aftership
2 Likes
Well - I see somebody else is into planted freshwater tanks! Me too!
1 Like
Triplus
(Joren C)
June 28, 2018, 7:01am
8
yup, most of my aquarium stuff is automated using hass
vMeph
June 28, 2018, 6:23pm
9
@Triplus i have tryed and folowed instruction but all im getting is:
any toughts?
Triplus
(Joren C)
June 28, 2018, 6:45pm
10
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…
Triplus
(Joren C)
June 30, 2018, 10:42am
12
May do that once my co2 equipment comes in. As I also be getting a solenoid to automate
maxandersen
(Max Rydahl Andersen)
October 30, 2018, 11:34pm
13
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
Yoni_Almog
(Yoni Almog)
November 15, 2018, 7:01pm
14
Great !
Can you add the Last checkpoint to the card as well ?
It would be very useful.