PostNL Integration

This is not PostNL related, but since we discussed DHL earlier I thought I should share some findings here.
Long story short, I got my DHL packages which are on the way available within Home Assistant through the multiscrape component.

So far it has been running for almost 24 hours and I haven’t seen any issues yet. As my package meanwhile got delivered, I can’t garantuee that it works flawlessly though.
The only issue that is present is whenever you (re)start home assistant, the sensor might be unavailable, but becomes available after reloading the multiscrape configuration.

This is my multiscrape setup. Replace YOUR EMAIL and YOUR PASSWORD with your credentials.
It might also work with the default rest integration. Haven’t tried that.

multiscrape:
  - resource: "https://my.dhlecommerce.nl/api/user/login"
    scan_interval: 3600
    method: "post"
    headers:
      Content-Type: "application/json"
    payload: '{"email":"YOUR EMAIL","password":"YOUR PASSWORD"}'
  - resource: "https://my.dhlecommerce.nl/receiver-parcel-api/parcels"
    scan_interval: 3600
    method: "get"
    headers:
      Content-Type: "application/json"
    sensor:
      - unique_id: dhl_packages
        name: DHL Pakketten
        value_template: "{{ value_json.parcels | selectattr('category', 'search', '(PROBLEM|CUSTOMS|DATA_RECEIVED|EXCEPTION|INTERVENTION|IN_DELIVERY|LEG|UNDERWAY|UNKNOWN)') | list | count }}"
        attributes:
          - name: parcels
            value_template: "{{ value_json.parcels | selectattr('category', 'search', '(PROBLEM|CUSTOMS|DATA_RECEIVED|EXCEPTION|INTERVENTION|IN_DELIVERY|LEG|UNDERWAY|UNKNOWN)') | list }}"

And this is my lovelace configuration for displaying a table of all packages on the way from either PostNL or DHL:

      - type: conditional
        conditions:
          - condition: or
            conditions:
              - condition: "numeric_state"
                entity: sensor.postnl_delivery
                above: 0
              - condition: "numeric_state"
                entity: sensor.dhl_packages
                above: 0
        card:
          type: markdown
          card_mod:
            style:
              ha-markdown$: |
                table {
                  width: 100%;
                }
                thead {
                  font-weight: bold;
                }
          content: |
              <table>
              <thead>
                <tr>
                  <td>Bezorger</td>
                  <td>Pakket</td>
                  <td>Datum</td>
                  <td>Tijd</td>
                </tr>
              </thead>
              <tbody>
              {% for package in state_attr('sensor.postnl_delivery', 'enroute') %}
                {% if package.planned_date is not none %}
                <tr>
                  <td>PostNL</td>
                  <td>{{ package.name }}</td>
                  <td>{{ as_timestamp(package.planned_date) | timestamp_custom('%-d %b') }}</td>
                  <td>{{ as_timestamp(package.planned_from) | timestamp_custom('%H:%M') }} - {{ as_timestamp(package.planned_to) | timestamp_custom('%H:%M') }}</td>
                </tr>
                {% endif %}
              {%- endfor %}


              {% for package in state_attr('sensor.dhl_packages', 'parcels') %}
                {% if package.receivingTimeIndication is not none %}
                <tr>
                  <td>DHL</td>
                  <td>{{ package.sender.name }}</td>
                  <td>{{ as_timestamp(package.receivingTimeIndication.start) | timestamp_custom('%-d %b') }}</td>
                  <td>{{ as_timestamp(package.receivingTimeIndication.start) | timestamp_custom('%H:%M') }} - {{ as_timestamp(package.receivingTimeIndication.end) | timestamp_custom('%H:%M') }}</td>
                </tr>
                {% endif %}
              {%- endfor %}
              </tbody>
              </table>
8 Likes