button-card
button-card copied to clipboard
DateTime helpers do not accept additional characters or helpers
Checklist
- [ x ] I updated the card to the latest version available
- [ x ] I cleared the cache of my browser
Describe the bug I can only use a single DateTime helper, the use of additional helpers or characters results in [object Object]
Version of the card Version: 4.1.1
To Reproduce This is the configuration I used:
type: custom:button-card
entity: input_datetime.datetime
show_icon: false
name: >
[[[ return helpers.formatDate(entity.state) + "<br>" +
helpers.relativeTime(entity.state); ]]]
show_label: true
label: >
[[[ return helpers.formatDate(entity.state) +
helpers.relativeTime(entity.state); ]]]
Screenshots
Expected behavior I expected/hoped that it is possible to use multiple helpers in one.
Desktop (please complete the following information):
- Browser [Safari 16.6.1]
Smartphone (please complete the following information):
- Device: [iPad Air 3]
- OS: [16.6.1]
- Browser [Safari]
- Version [16.6.1]
Additional context Home Assistant Supervised core-2023.9.1
bump Same issue as with latest version
+1
Same issue, but I found a workaround. The object returned by helpers.relativeTime()
has a values
array. The date string is stored the 2nd element that array. So if you want to add to the string you can do for example:
[[[ return "Relative Time:<br>" +
helpers.relativeTime(entity.state).values[1]; ]]]
But I'm not sure if the helpers.relativeTime(entity.state).values
array is always the same.
+1, the .values[1] workaround is pretty ugly. I would like to have "Mi custom text: 4 hours ago" with '4 hours ago' being the text displayed by helpers.relativeTime(entity.state)
I can't get helpers.relativeTime() to work at all.. can somebody give me a hint at what's wrong? As a test I try this simple card, current time is past 07:15
type: custom:button-card
custom_fields:
text: >
[[[
return 'Relative Time: ' +
helpers.relativeTime('2024-08-18T07:15:00+00:00').values[1]
]]]
But my output is this: