Skip to content

[Bug]: expected_datetime earlier than planned_from is discarded by _delivery_window_start() #54

Done

Description

@misteriks

PostNL integration version

5.0.0

Home Assistant version

2026.11.2

What happened?

When a parcel is out_for_delivery, PostNL continuously updates routeInformation.expectedDeliveryTime (raw.expected_datetime) based on live courier progress, while keeping routeInformation.plannedDeliveryTimeWindow (raw.planned_from / raw.planned_to) fixed at the original 2-hour window.

When the courier runs ahead of schedule, expectedDeliveryTime legitimately moves earlier than plannedDeliveryTimeWindow.startDateTime. However, _delivery_window_start() in custom_components/postnl/parcels.py (lines 432–453) discards expected_datetime whenever it falls outside [start, end]:

if start is None or end is None or not start <= expected <= end:
    return planned_from
return parcel["expected_datetime"]

As a result, Home Assistant (planned_from, next_delivery, calendar, and cards like ha-parcel-card) stops updating and falls back to the stale original window start, even though the PostNL app and the raw API response already show the updated earlier ETA.

Observed live progression on the same parcel today (original window 18:25–20:25):

  • 13:19 — raw.expected_datetime was 18:37 (inside 18:25–20:25) → top-level planned_from & next_delivery updated to 18:37.
  • 14:06 — courier ran ahead of schedule; raw.expected_datetime moved to 18:15 (10 min before 18:25) → rejected by start <= expected <= end, so planned_from reverted to 18:25.
  • 14:16 (after pressing Refresh) — raw.expected_datetime moved further to 18:08 → still rejected; planned_from remains stuck at 18:25.

Expected behaviour:
expected_datetime should still be trusted when the courier runs ahead of schedule (or slightly past planned_to when delayed — note that if expected > planned_to, planned_window() would currently swap reversed bounds unless planned_to is adjusted accordingly).

Steps to reproduce

  1. Have an active incoming PostNL parcel with status out_for_delivery (J05) and a 2-hour plannedDeliveryTimeWindow (e.g. 18:25–20:25).
  2. Wait until the courier runs ahead of schedule so PostNL returns routeInformation.expectedDeliveryTime earlier than plannedDeliveryTimeWindow.startDateTime (e.g. 18:15 or 18:08 while planned_from stays 18:25).
  3. Observe that raw.expected_datetime updates on every poll/refresh, while top-level planned_from and sensor.postnl_*_next_delivery revert to and stay stuck on 18:25.

Relevant logs

{
  "status": "out_for_delivery",
  "raw_status": "Bezorger is onderweg",
  "planned_from": "2026-11-24T18:25:00+01:00",
  "planned_to": "2026-11-24T20:25:00+01:00",
  "raw": {
    "status_message": "Bezorger is onderweg",
    "delivered": false,
    "delivery_address_type": "Recipient",
    "planned_date": "2026-11-24T19:25:00+01:00",
    "planned_from": "2026-11-24T18:25:00+01:00",
    "planned_to": "2026-11-24T20:25:00+01:00",
    "expected_datetime": "2026-11-24T18:08:00+01:00"
  }
}

Activity

  1. added
    bug
    on Nov 24, 2026
  2. peter-mdf commented on Nov 24, 2026

    @peter-mdf
    Collaborator

    Thanks again @misteriks ! Fixed in the next release :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions