-
is it possible to have a (custom) label which returns a text that displays the last_changed attribute in a nice way (eg: 12 minutes ago) |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
You can build it yourself using javascript (with I could however maybe provide some helper functions which would be available in javascript templates to do that instead of writing your own "formatter" |
Beta Was this translation helpful? Give feedback.
-
As I have written code to accomplish the 'nice way' formatting in the past I know it can be quite cumbersome and prone to errors. But the MomentJS library has this built-in fortunately, is it possible to use that? |
Beta Was this translation helpful? Give feedback.
-
I wonder if it's possible to add MomentJS as a resource (in UI: configuration => lovelace => resources) and then use it in the javascript templates? |
Beta Was this translation helpful? Give feedback.
-
Responding to my own question, I couldn't get it to work. The libraries don't appear to load correctly when added as a resource. There may be another way to do it, or I've overlooked something. |
Beta Was this translation helpful? Give feedback.
-
You can use type: custom:button-card
variables:
testDate: |
[[[
return "2025-08-23 13:12:00"
]]]
styles:
grid:
- grid-template-areas: "\"n\" \"l\""
name: Relative Time
show_label: true
label: |
[[[ return helpers.relativeTime(variables.testDate) ]]] |
Beta Was this translation helpful? Give feedback.
You can use
helpers.relativeTime()