Hi,
I’m using the 17Track integration to tracks my parcels number, and wanted to have a notification every time it’s updated.
in the in transit
sensor, there is an attribute packages
which is an array of package object
packages:
- tracking_number: ABCDE
location: Germany
status: In Transit
timestamp: "2024-07-02T20:19:00+00:00"
info_text: >-
The international shipment has been processed in the parcel center of
origin
friendly_name: null
I have made this automation:
alias: Alert on Parcel
description: ""
trigger:
- platform: state
entity_id:
- sensor.17track_in_transit
attribute: packages
condition: []
action:
- variables:
parcels: >-
{% set parcel = state_attr("sensor.17track_in_transit", "packages") %}
{{parcel | list}}
- repeat:
for_each: "{{ parcels }}"
sequence:
- service: notify.mobile_app_***
metadata: {}
data:
message: "{{ repeat.item.info_text }}"
title: "{{ repeat.item.tracking_number }}"
mode: single
But when I run it, in the trace for the repeat
section, I have this error : Error: Repeat 'for_each' must be a list of items
.
If I go to the Changed Variables
section, the parcels
variable seems to be set correctly:
context:
id: ***
parent_id: ***
user_id: null
parcels: >-
[{'tracking_number': 'ABCDE', 'location': 'Germany', 'status': 'In
Transit', 'timestamp': datetime.datetime(2024, 7, 2, 20, 19, tzinfo=<UTC>),
'info_text': 'The international shipment has been processed in the parcel
center of origin', 'friendly_name': None}]
In the for_each
, I’ve tried multiple things:
{{ state_attr("sensor.17track_in_transit", "packages") | list }}
{% set parcel = state_attr("sensor.17track_in_transit", "packages") %} {{parcel | list}}
(without thevariable
section){{ (states.sensor | selectattr('entity_id', 'match', 'sensor.17track_in_transit') | map(attribute='attributes.packages') | list)[0] }}
If anyone have any idea to solve it, thanks in advance.