Hi Petro,
May I trouble you with one last thing… I’ve trying to get it to work with no luck after several trial, I guess I need to do some intensive reading about States and Attributes.
What if instead of last changed attribute (which changes after each restart, I want to use an input_datetime helper to make it persistant over re-start… how can I insert this in your code.
It keeps giving me error either no attribute or can’t use < between strings and datetime.
States are always strings, so you will need to convert the state of the Input datetime helper to a offset-aware datetime object by replacing the first line of the template:
{% set last_changed = states('input_datetime.XXXX') | as_datetime | as_local %}
Thank you big time. I can now see what I did wrong… I had the as_local filter before the | as_datetime… makes perfect sense now and works flawlessly.
Much appreciated
RS
Which gives me 31d Dech 12m off an epoch of ~9000 which should be more like 0d 2h 30m. What’s the proper syntax to depict elapsed time from 0 instead of the start of the epoch?
Just so you know, most languages don’t have this. I was surprised when I found out that C# does have it, but the implementation is terrible in comparison to the strftime equivalent.
I use this on my “Router” uptime sensor , sure i didn’t bother about showing D/H/M, as i have a “personal perspective” of the word “UserFriendly” … it’s my system, only i need to understand
Thanks. It doesn’t work for me. I get 00:00:00 using the whole thing. What type and format does your sensor output and what does the output of that template look like?
{% set s = states('sensor.uptime')| int(3) %}
{{'%02d:%02d:%02d' % ((s/86400)|int(3),((s%86400) / 3600)|int(3),(s%3600) / 60) }}
{{ s }}
{{ states('sensor.uptime') }}
I made the template easily expandable for people who don’t understand code. They can copy the template and remove lines that they don’t want. This could be much shorter and custom, but why bother when this works for all needs/wants