Replies: 4 comments 1 reply
-
Hi DanDixon, did you find a solution to your issue? |
Beta Was this translation helpful? Give feedback.
-
Have the same sort question.
While
|
Beta Was this translation helpful? Give feedback.
-
But last_changed is for every state change, in your case also in case the door has opened... - type: custom:button-card
entity: light.ceiling_lights
name: Test Light
show_state: true
show_label: true
label: >
[[[
if (entity !== undefined) {
let timeAgo = states['light.ceiling_lights'].last_changed;
//console.log(timeAgo);
function timeSince(date) {
const now = new Date();
const secondsPast = (now - new Date(date)) / 1000;
if (secondsPast < 60) {
return `${Math.floor(secondsPast)} seconds`;
}
if (secondsPast < 3600) {
return `${Math.floor(secondsPast / 60)} minutes`;
}
if (secondsPast < 86400) {
return `${Math.floor(secondsPast / 3600)} hours`;
}
if (secondsPast < 2592000) {
return `${Math.floor(secondsPast / 86400)} days`;
}
if (secondsPast < 31536000) {
return `${Math.floor(secondsPast / 2592000)} months`;
}
return `${Math.floor(secondsPast / 31536000)} years`;
}
var timeAgoStr = timeSince(timeAgo);
return 'Light state changed ' + timeAgoStr + ' ago';
}
]]]
|
Beta Was this translation helpful? Give feedback.
-
But did you check the format helpers? There a quite a few of them and no need for the super complex templates at all. Most is simply built right in |
Beta Was this translation helpful? Give feedback.
-
I'd like to shorten the relativeTime output so it fits in a smaller space:
left = relativeTime
right = custom code that I was hoping relativeTime would replace
I'd like to do something like this:
But relativeTime:
And so you can't make any change to the text output of relativeTime apparently.
For example:
Shows this:
Any workarounds for this?
Beta Was this translation helpful? Give feedback.
All reactions