custom-cards / button-card

❇️ Lovelace button-card for home assistant
MIT License
1.87k stars 229 forks source link

DateTime helpers do not accept additional characters or helpers #772

Open pedolsky opened 11 months ago

pedolsky commented 11 months ago

Checklist

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

IMG_0196

Expected behavior I expected/hoped that it is possible to use multiple helpers in one.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context Home Assistant Supervised core-2023.9.1

Grrzzz commented 7 months ago

bump Same issue as with latest version

En3myNightmare commented 7 months ago

+1

wynandtredoux commented 6 months ago

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.

mycroftsnm commented 3 months ago

+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)

swaggerino commented 3 days ago

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: image