This integration shows the timestamp in exactly the same format regardless of whether I use {{ package.timestamp }} or {{ package.timestamp | timestamp_custom("%d-%m-%y") }}
to display it. It’s crazy!
Thanks @parautenbach and @petro . Unfortunately neither of these syntaxes worked - the entire card output disappears as it can’t be rendered correctly.
The log says:
Template warning: ‘timestamp_custom’ got invalid input ‘2022-01-07 09:43:00+00:00’ when rendering template '{% for package in states.sensor.seventeentrack_packages_expired.attributes.packages %} - Timestamp: {{ package.timestamp | timestamp_custom("%d-%m-%y") }}. {% endfor %} ’ but no default was specified. Currently ‘timestamp_custom’ will return ‘2022-01-07 09:43:00+00:00’, however this template will fail to render in Home Assistant core 2022.1
The last sentence is interesting: timestamp-custom will return a value but it’s not the value that was specified.
What should I try next?
Still not successfully working. Stepping through this: package.timestamp returns 2022-01-07 09:43:00+00:00
piping only to as_timestamp returns 1641548580.0
piping only to as_datetime fails to return a value
piping to as_timestamp | as_datetime does return 2022-01-07 09:43:00+00:00
piping to as_timestamp | as_datetime | as_local does return 2022-01-07 22:43:00+13:00 ← progress!
piping to as_timestamp | as_datetime | as_local | timestamp_custom("%a") however only gives me 2022-01-07 22:43:00+13:00.
This worked:
piping to package.timestamp | as_timestamp | timestamp_custom("%A %D %z %Z") gives me Friday 01/07/22 +1300 NZDT which is correct, and in a format I can work with.
So, for this timestamp, it’s pretty resistant to being worked with as a datetime, but I can apply a custom format if I leave it as a timestamp.
Thanks for helping me work this out!
but you didn’t try it, you skipped over it and reversed the as_timestamp to the front.
timestamp_custom requires a timestamp to precede it. Admittedly, I forgot as_timestamp can convert a string to an timestamp. Regardless, both of these will work
Sorry, but this one definitely did not work. I tried it early on as it was already suggested earlier in the thread.
Unfortunately this one didn’t work for me either.
There is nothing special about my 17track card here, so I am unsure why these work for you and not me. Regardless, using as_timestamp | timestamp_custom(... worked well so I’m glad to have this working now. Thanks for the help!
I’m trying them in my live setup so I am reporting real-world status of “works/doesn’t work”. And yes, I am using the latest version of HA, always! Thanks.
Hi,
I am not very familiar with Jinja templates, mostly get syntax from all awesome guys posting in this community. however I couldn’t find what I am searching for.
I need to show the last changed time as follows:
If less than 24hrs to show ‘15 hours ago’ or ‘Today at 16:25’
If more between 24-48hrs to show ‘Yesterday at 16:25’
If more than 48hrs to show ‘Tuesday at 16:25’
I really appreciate any advice
Thanks in advance
RS