kalkih / mini-graph-card

Minimalistic graph card for Home Assistant Lovelace UI
MIT License
2.96k stars 232 forks source link

Feature request: Introduce a value_template to convert to more readable formats #892

Open h0jeZvgoxFepBQ2C opened 1 year ago

h0jeZvgoxFepBQ2C commented 1 year ago

Hi,

I'm using your mini-graph-card to calculate how many hours a sensor was on in my home. It works fine, but shows f.e. "0,05 hours" whereas it would be nice to show "0 Hours 3 Minutes" (since 0,05 hours translate to 3 minutes).

Any idea if this is possible to implement?

Bildschirm­foto 2022-12-19 um 15 16 03

ildar170975 commented 1 year ago

There plenty of possible desires like "convert my Celsius to Fahrenheits", "euros to dollars", "time to hh:mm:ss" ... It is not easy to define ALL of them.

Do you want is a possibility to define a format of the displayed state only - or for all displayed labels?

image

image including popup labels while hovering

h0jeZvgoxFepBQ2C commented 1 year ago

Oh this looks really nice, I guess for all labels it would be great then.

Maybe it's possible to provide a value_template function, so it could be open to the user what he wants to convert (like you mentioned, Celcius to Fahrenheit, EUR/USD,...)?

But if it's easier to implement just the hour formatting, I would prefer option two :D ❤️

ncrmnt commented 1 year ago

I would suggest to implement somthing like

value_template: |
  {% set duration = <some_value> * 60 %}
  {{ duration|int }}:{{ '{:02}'.format(((duration - duration|int) * 60) |int) }}

.. or it can be formatted depends on an entity attributes for example I have a sensor with attributes

state_class: measurement
unit_of_measurement: h
device_class: duration
icon: mdi:chart-line

and it shows like hh:mm:ss on tile card

image

it's the same values