PostNord delivery dates in Home Assistant
I live in Sweden, and the postal service PostNord only delivers post every other day or so. Instead of trying to learn the schedule or just checking PostNord’s website if I’m curious, we are going to poll their API and have a template sensor to automagically update itself depending on the API reply.
The API returns a strange date format in Swedish (“18 mars, 2024”, which is non-standard), and Home Assistant’s template engine runs in en_US so it can’t parse this date. Below hacks around it.
The snippet is stolen from this gist. Thank you tubalainen! (also, great name)
binary_sensor:
- platform: template
sensors:
post_i_dag:
friendly_name: "Kommer posten idag"
value_template: >-
{{ (state_attr('sensor.postnord_utdelning', 'delivery').split(' ')[0] | int) == now().day }}
sensor:
- platform: rest
name: "PostNord Utdelning"
scan_interval: 14400 # 4 hours
resource: https://portal.postnord.com/api/sendoutarrival/closest?postalCode=12345 # <-- change me!
value_template: "{{ value_json.delivery }}"
json_attributes:
- "delivery"
- "upcoming"
- "city"
- "postalCode"