I did restart my instance, (not reboot the host), some 23 hours ago, and as such maybe the relative_time() to the last_boot sensor (which records the last boot of the host) was set ?
Never realized the relative_time() function was relative to the last restart of the instance too…
feels like a bug, when reading this:
relative_time converts datetime object to its human-friendly “age” string.
since the datetime object is correctly used in the other template posted above.
You’re comparing last_boot to uptime. Uptime is the time home assistant has been on, last_boot is how long your OS has been on. Not a bug, just different information.
Yes I understand that. But in all honesty I expected relative_time() on last_boot to use the recorded last_boot time, and not the uptime (of the restart).
relative_time accepts any datetime object… The context of the datetime object is meaningless. If anything, it proves that last_changed can’t be used for the last_boot sensor because it changed the state on restart and you have to use the method I posted above…
{# use now() to update every minute #}
{% set t = now() %}
{{ relative_time(strptime(states('sensor.uptime'), '%Y-%m-%dT%H:%M:%S.%f%z')) }}
Remember, states get globally set on restart so last_changed reflects that.
Not to be a drag but when I used your code, it wasnt usable as you said, I corrected the code and it worked for a while. And now I get a, in my opinion, a sad respons to my question.
If you know something that work please point me to that post. Since upgrading makes some solutions obsolete!
That ones been posted a few times in this thread already, including an updated version. This is why I asked him to read the other posts. I have no clue if he’s actually done that.
I understand but I think I am like him and just confused by the amount of different methods to do this and l expect he has ran into the same problems as me and that is that some of the methods posted here did not work for me. The above seems to work for me so far but if you have a better solution please post it and then I can mark that as being the solution to put this topic to a close and save confusion. Thank you for you knowledge and input
You’re the thread owner, I’ll gladly mark this as a solution as long as you’re ok with it. It’s the updated streamlined version of what you just posted.