Since the latest update and the depreciation of “unit_of_measurement” I seem to be being stupid and cannot get uptime to work.
I would like a simple counter for uptime to display on top of a picture elements card, ideally having days and hours but would also like to be able to have others if needed so another I would use would be days, hours and minutes
Anyone have these and able to share working code tested on latest home assistant?
?
(though neither of these auto-update in the template editor anymore since 2020.X, relative_time() doesn’t trigger an update, which feels like a bug, and I have reported it as that…)
relative time already does that. all you’d have to add is ‘ago’ after the template:
{{ relative_time(states.sensor.uptime.last_changed) }} ago
But you’d REALLY need to implement the availability_template to ensure it’s ‘unavailable’ when the calculation fails (So that it doesn’t read unavailable ago)
relative_time converts datetime object to its human-friendly “age” string. The age can be in second, minute, hour, day, month or year (but only the biggest unit is considered, e.g., if it’s 2 days and 3 hours, “2 days” will be returned).
so if you need the phrase, relative_time() isnt of much help
I have not updated yet, but use uptime in many of my automations as a condition to keep them from running during restart. To be honest I added these conditions years ago, and it’s just worked so I have not looked for better ways to do it. I dont care much about displaying the uptime, just want to keep automations from triggering during the first X minutes after a restart.
What is the recommended way to do that these days? Most of my automations with an uptime trigger are set to 1-2 minutes, and a few are set longer for devices that take a little longer to report status sometimes.
And with the old uptime sensor the state was just a numeric value… I’m not sure if it’d be easier to redo the whole restarted recently sensor, or just make another sensor that provides just the numeric number of minutes like it was before.