custom-cards / button-card

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

show_last_updated #701

Closed Kedryn closed 1 year ago

Kedryn commented 1 year ago

Is your feature request related to a problem? Please describe. Missing a way to show the time from the last update to te displayed entity

Describe the solution you'd like a "show_last_updated" like the "show_last_changed" to display the time since last sensor update (expecially for button related to gps positions)

andyblac commented 1 year ago

and a show_last_actioned for when the last time a scene was run.

Mariusthvdb commented 1 year ago

did you try

      state_display: >
        [[[ return entity.last_updated; ]]]
      show_state: true

you might want to format that a bit, as indeed it is the raw last_updated returned form the state machine

@andyblac what is show_last_actioned ...... iow, how would you expect button_card to show a non existing state attribute?

andyblac commented 1 year ago

well, when I use show_last_changed: true for a scene button for example, it does not show the last time the scene was accually run, unlike the lovelace entity card. It just seems show the last time anything happened, i.e. if you restart HA the time just gets that time, or if you chnage the scene thats the time it shows. but it does also show the last action time IF nothing has touched the scene since it was last run.

what I am after is a NEW varible that is acutally linked to the state date time, but in human readable format.

Screenshot 2023-07-12 at 11 02 21

or is there another way I don't know about ????

RomRider commented 1 year ago

Will be possible with the next release with state_display: [[[ return formatDateTime(entity.state); ]]] for example in your case.

Mariusthvdb commented 1 year ago

this is in b7? I cant make it happen I am afraid.

RomRider commented 1 year ago

Not yet released. Fixing some bugs with other stuff.

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 4.0.0-dev.8 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

Mariusthvdb commented 1 year ago
Scherm­afbeelding 2023-07-24 om 23 15 02

beautiful!

type: custom:button-card
entity: script.aan_de_slag
show_state: true
state_display: |
  [[[ return formatDateTime(entity.attributes.last_triggered); ]]]
andyblac commented 1 year ago

@RomRider Thanks for the addition, would it be posible to add the ability the convert to relative time, i.e. 36 Seconds ago, 2 Minutes, 36 Seconds ago, 1 Hour, 2 Minutes ago ?

Screenshot 2023-07-25 at 12 13 49
RomRider commented 1 year ago

The difference with relative time is that it needs to update over time automatically like when using show_last_updated so that's something different. I'll see what I can do as I wasn't aware about the last_changed property until reading this thread 😅

Mariusthvdb commented 1 year ago

if I am allowed to piggyback on this: would it be possible to only show formatTime ? (making that up as I type, so dont take it to be an existing format)

for many of those last_changed/triggered/updated entities the dat is not important, the time would be though. Having a dedicated setting for it would be very much appreciated

Scherm­afbeelding 2023-07-25 om 13 42 35
    - type: custom:button-card
      entity: person.marijn
      state_display: >
        [[[ return formatDateTime(entity.last_updated); ]]]
      show_state: true
andyblac commented 1 year ago

@RomRider Thanks, it's just the standard lovelace entity card uses relative time when using a scene entity. also the last_changed and last_updated are reset if HA is restarted to the time it was restarted, not very useful. A entity scene does not have a last_triggered attribute unlike scripts, automations, etc.

RomRider commented 1 year ago

In the next version about to be published, I've introduced a relativeTime function.

So you'll be able to do something like:

state_display: '[[[ return relativeTime(entity.state); ]]]'

And it will update automatically over time.

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 4.0.0-dev.11 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

andyblac commented 1 year ago

@RomRider nice one, works great.

Screenshot 2023-07-26 at 09 59 32
RomRider commented 1 year ago

Breaking change in the latest beta on this, please read the release notes ;)

github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 4.0.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: