button-card icon indicating copy to clipboard operation
button-card copied to clipboard

DateTime helpers do not accept additional characters or helpers

Open pedolsky opened this issue 1 year ago • 6 comments

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

IMG_0196

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

pedolsky avatar Sep 12 '23 08:09 pedolsky

bump Same issue as with latest version

Grrzzz avatar Jan 02 '24 20:01 Grrzzz

+1

En3myNightmare avatar Jan 04 '24 12:01 En3myNightmare

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.

wynandtredoux avatar Feb 18 '24 20:02 wynandtredoux

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

mycroftsnm avatar May 05 '24 23:05 mycroftsnm

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

swaggerino avatar Aug 18 '24 11:08 swaggerino