once again I have to give up …
How do I go about obtaining the locations from the individual sensor packages (sensor.seventeentrack_package_xxxxxxxx) and then inserting them in the payload?
payload_template: >
{% set ns = namespace(items = 'update on the packages you are waiting for: ') %}
{% for item in state_attr('sensor.seventeentrack_packages_in_transit', 'packages') %}
{% set ns.items = ns.items ~ 'the package with {}: is in {} at ######{LOCATION}#######, '.format(item.friendly_name, item.info_text, ???????) %}
{% endfor %}
{{ns.items}}
I know next to nothing about the seventeentrack integration and my answer was based solely on the sample data you provided in your post. You’ll have to help me understand where the location data exists because I don’t see it in the sample data.
The 17track sensors that I would like to edit are:
the main one, sensor.seventeentrack_packages_in_transit, which contains the attribute packages, with the attributes of the various packages in transit inside
and the sensors of the individual packages,(sensor.seventeentrack_package_xxxxxxxx) from which I should derive the attibuto location that is missing from the main sensor
Try this in the Template Editor (I don’t have the means to test it with your data):
{% set ns = namespace(items = '') %}
{% for item in state_attr('sensor.seventeentrack_packages_in_transit', 'packages') %}
{% set sensor = 'sensor.seventeentrack_package_' ~ item.tracking_number %}
{% set ns.items = ns.items ~ 'Name: {} Number: {} Location: {}, '.format(item.friendly_name, item.tracking_number, state_attr(sensor, 'location')) %}
{% endfor %}
{{ns.items}}
If it works you can easily modify the template to display the result the way you prefer. Should you also require it to display package_type (or other attribute) you can append state_attr(sensor, 'package_type') to the template’s format function.
You could do that. The Template sensor’s value_template would be the template I posted above. HOWEVER, an entity’s state is limited to storing 255 characters maximum. Given enough tracked packages, it’s possible that the template’s result can exceed 255 characters.
FWIW, an entity’s attributes are not limited to storing only 255 characters.
as you may have guessed they are right at the beginning … so the code to insert that value template in an entity attribute of a sensor would be there? what I would like to do in practice is to transform the tts message into a sign with the position of the packages on it
Hi! I was looking for such solution to list all my 17Track.net packages in one card. Mi question is how can I list all items in a card, each on a separate line? My template looks like this:
@petro Hi Petro! My markdown card looks really nice, but it shows only the “in transit” packages. Is there a way have listed also the “not found” packages? I would like to see all my packages from 17tracknet listed in the card, regardless of their “in transit” or “not found” status.