Ok, so the “funky 24 hour time shift” is because the timestamp_custom assumes local time until you convert it to UTC using “false”. Or you convert it to UTC some other way.
Kind of like you said above.
I get it now.
Thanks, again (and again, and again…just building up some additional thanks for the next inevitable time I ask for your help )
whispers…(but my way still works if you convert it to UTC…)…
Is it possible to use the state instead of last_changed?
I ask because, if I manually edit the value of the input_datetime sensor, to say a time that is 4 hours ago, the last_changed will be right now and not 4 hours ago.
Hi,
I have several sensor configured in configuration.yaml template. I don’t want to use the same code for each sensor. I there any way to use function in configuration.yaml with argument datetime, which will return for example 10 seconds, 1 minute, 5 hours, 3 days…?
I don’t understand this code. It seems to me, it is a part of sensor template? So I should repeat the same code for each sensor template?
I would like to define a function somewhere (configuration.yaml?) which will do the math and It will be possible to call it from each sensor template. Is it possible? Any example for beginner?
Yes, what you’d need to do is create macro’s that can be accessed in the jinja environment. It’s just that the macros wouldn’t always exist on startup causing a litany of errors.
It’s an old thread, but by modifying the last line into two lines of the template @petro provided (thanks, way above my skills), I managed to limit the result to the biggest two only :
{% set skip = -1 if (values|length) < 3 else 1-(values|length) %}
{{ values[:skip] | join(', ') ~ ' ' ~ word_for_and ~ ' ' ~ values[skip] if values | length > 1 else values | first | default }}
So it for example results in 3 hours and 13 minutes
Instead of: 3 hours, 13 minutes and 36 seconds
Hi @petro
Thanks for pointing out your great library!
A question though. I can’t figure out which macro does what I made above.
If I understand correctly, your macros require to provide weeks, hours, minutes and / or seconds to select the preferred detail.
But my modification will simply show up to two levels of detail, starting with the biggest available. So depending the timespan the result can be:
Weeks [and days]
Days [and hours]
Hours [and minutes]
Minutes [and seconds]
Between the brackets is only given if the value is not zero