#Render entity with device_class duration in human readable format
1 messages ยท Page 1 of 1 (latest)
you could template something in a helper to make something readable you could display on dashboard
hmm yeah that seems to be the solution though seems like an extra thing that I don't use often. I think I might try a combination of these two:
https://github.com/Petro31/easy-time-jinja
https://github.com/thomasloven/lovelace-template-entity-row
I was hoping there would have been just something I was missing to allow for a display/rendering formatter
(I'm aware of the irony of my proposed solution being even more complicated ๐ )
{% set minutes = ((time % 3600) / 60) | int %}
{% set hours = ((time % 86400) / 3600) | int %}
{% set days = (time / 86400) | int %}
{%- if time < 60 -%}
Less than a minute
{%- else -%}
{%- if days > 0 -%}
{%- if days == 1 -%}
1 day
{%- else -%}
{{ days }} days
{%- endif -%}
{%- endif -%}
{%- if hours > 0 -%}
{%- if days > 0 -%}
{{ ', ' }}
{%- endif -%}
{%- if hours == 1 -%}
1 hour
{%- else -%}
{{ hours }} hours
{%- endif -%}
{%- endif -%}
{%- if minutes > 0 -%}
{%- if days > 0 or hours > 0 -%}
{{ ', ' }}
{%- endif -%}
{%- if minutes == 1 -%}
1 minute
{%- else -%}
{{ minutes }} minutes
{%- endif -%}
{%- endif -%}
{%- endif -%}```
stick that into a template sensor obviously chaging the first line to point at the right entity
that and some other examples here
https://community.home-assistant.io/t/convert-seconds-to-days-hours-minutes/23152/7
binary_sensor: - platform: template sensors: breakfast_nook_window_time: friendly_name: Nook Window time value_template: '{{ as_timestamp(binary_sensor.breakfast_nook_window) }} | {{ as_timestamp(now()) - as_timestamp(binary_sensor.breakfast_nook_window.last_tripped_time) }}' Cannot read property โvโ of undefined We...
its not exactly elegent but will do for now i suspect
sounds good, I'll take a look. thanks
this is a bit more friendly
{{ timedelta(seconds = states('SENSOR.THAT_GIVES_YOU_SECONDS') ) }}
you got some options anyway ๐
I just skimmed over the thread and was going suggest Easy Time but the OP already mentioned it earlier.
I meant to check it out a couple of months ago but forgot about it. Just loaded it now.
I wish I would have tried this a long time ago. It would have caused so much less hassle.
I tried out a couple of examples in Developer Tools. ```javascript
{% from 'easy_time.jinja' import clock, clock_icon, easy_time %}
{{ clock() }}
{{ clock_icon(12) }}
{{ easy_time('input_datetime.automation_nighttime_motion_detection_start') }}
{% import 'easy_time.jinja' as et with context %}
{{ et.clock('24-hr') }}
{{ et.easy_time('input_datetime.automation_nighttime_motion_detection_start') }}
{{ et.easy_time('input_datetime.automation_nighttime_motion_detection_end') }}
{{ et.easy_time(states.sensor.s22_ultra_battery_level.last_updated, short=True)}}
{{ et.big_time(states.sensor.s22_ultra_battery_level.last_updated)}}
which returned
11:02 PM
mdi:clock-time-twelve
23 hours
23:02
23 hours
12 hours
45min
44 minutes and 54 seconds
Is just changing the unit to hours an option?
I think that's the current officially recommended way to get HH:MM display.
it's not since in my case the data just comes out of octoprint as seconds
what I ended up with for the record:
{% from 'easy_time.jinja' import big_time -%}
{{ big_time(now() + timedelta(seconds=states('sensor.octoprint_print_time_left') | int), short=True) }}```
it's not since in my case the data just comes out of octoprint as seconds
Whatever the integration provides, as the user you can change it in entity registry settings.
But if you're happy with the solution that works too ๐
oh I thought it was the same setting for underlying data and visual representation. at least when I tried setting it to h it was completely wrong
that's the crux of the bug I mentioned above at least: https://github.com/home-assistant/frontend/issues/23338
if there's an easier solution I'd definitely be open to trying it out