Hi,
I customized the auto_entities template a bit. It includes the following new features:
- Shows the number of days until delivery instead of the date
- Shows the last event message for each parcel
- Corrected the display of the delivery date if already delivered (did not work for me in the original version)
But I also have an issue I cannot solve, maybe somebody has an idea? In the if block for the days calculation I'd like to have a greater than statement. But when I change it to the following code, it just does not work. I don't know how to debug/troubleshoot in Home Assistant, maybe somebody can help?
Here's the code snippet that I would like to use but doesn't work:
{% if days == 0 %}
{% set days = "today" %}
{% elif days == 1 %}
{% set days = "tomorrow" %}
{% elif days > 1 %}
{% set days = "in " + (days | string) + " days" %}
{% else %}
{% set days = "unknown" %}
{% endif %}
Here's the current complete code, containig a working version of the of block.:
`
type: custom:auto-entities
card:
type: entities
title: Pakete
filter:
template: >
{# Fetch parcel data from sensor #} {% set parcels =
state_attr('sensor.parcel_raw_shipment_data', 'deliveries') or [] %} {% set
enroute = namespace(list=[]) %} {% set delivered = namespace(list=[]) %}
{# Loop through each parcel #} {% for parcel in parcels %}
{% set statuscode = parcel.status_code | int %}
{% set carrier = parcel.carrier_code | upper %}
{% set name = parcel.description if parcel.description else 'Unknown sender' %}
{% set barcode = parcel.tracking_number %}
{# Format the expected delivery time #}
{% set lastmsg = parcel.events[0].event %}
{% if parcel.date_expected %}
{% set time = strptime(parcel.date_expected, '%Y-%m-%d %H:%M:%S') %}
{% set days = (((as_timestamp(time) - as_timestamp(now())) + 7200) | int /60/1440) | round(0) %}
{% if time.time()|string == '00:00:00' %}
{% set time = time.date() %}
{% endif %}
{% else %}
{% set time = parcel.events[0].date %}
{% endif %}
{% if days == 0 %}
{% set days = "today" %}
{% elif days == 1 %}
{% set days = "tomorrow" %}
{% else %}
{% set days = "in " + (days | string) + " days" %}
{% endif %}
{# Classify parcel based on status code #}
{% if statuscode in [2, 3, 4] %}
{% set row = {
'type': 'custom:template-entity-row',
'name': '[' ~ carrier ~ '] ' ~ name ~ ' - ' ~ barcode,
'state': '',
'secondary': 'Delivery ' ~ days ~ ' - ' ~ lastmsg,
} %}
{% set enroute.list = enroute.list + [row] %}
{% elif statuscode == 0 %}
{% set row = {
'type': 'custom:template-entity-row',
'name': '[' ~ carrier ~ '] ' ~ name ~ ' - ' ~ barcode,
'state': '',
'secondary': 'Zugestellt: ' ~ time ~ ' - ' ~ lastmsg
} %}
{% set delivered.list = delivered.list + [row] %}
{% endif %}
{% endfor %}
{# Build final list for card #} [
{% if enroute.list | count > 0 %}
{
"type": "section",
"label": "📦 Unterwegs"
},
{{ enroute.list | join(',') }},
{% endif %}
{% if delivered.list | count > 0 %}
{
"type": "section",
"label": "✅ Zugestellt"
},
{{ delivered.list | join(',') }}
{% endif %}
]
show_empty: true
grid_options:
columns: full
`
Hi,
I customized the auto_entities template a bit. It includes the following new features:
But I also have an issue I cannot solve, maybe somebody has an idea? In the if block for the days calculation I'd like to have a greater than statement. But when I change it to the following code, it just does not work. I don't know how to debug/troubleshoot in Home Assistant, maybe somebody can help?
Here's the code snippet that I would like to use but doesn't work:
{% if days == 0 %}
{% set days = "today" %}
{% elif days == 1 %}
{% set days = "tomorrow" %}
{% elif days > 1 %}
{% set days = "in " + (days | string) + " days" %}
{% else %}
{% set days = "unknown" %}
{% endif %}
Here's the current complete code, containig a working version of the of block.:
`
type: custom:auto-entities
card:
type: entities
title: Pakete
filter:
template: >
{# Fetch parcel data from sensor #} {% set parcels =
state_attr('sensor.parcel_raw_shipment_data', 'deliveries') or [] %} {% set
enroute = namespace(list=[]) %} {% set delivered = namespace(list=[]) %}
show_empty: true
grid_options:
columns: full
`