custom-cards / button-card

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

last_updated timestamp isn't refreshing card #630

Open ASomerN opened 1 year ago

ASomerN commented 1 year ago

Checklist

Describe the bug Accessing and using last_updated isn't refreshing the visual. I'm polling an API every 60/120 seconds, the API should respond with an update and i want to conditionally display red text on the last_updated field if this has failed

Version of the card v3.4.2

To Reproduce This is the configuration I used:

type: custom:button-card
entity: sensor.tesla_state
show_state: true
show_last_changed: true
triggers_update:
  - sensor.tesla_online
custom_fields:
  progress: >
    [[[ return '<span style="position:absolute;  left:195px; font-size:10px;">'
    + new Date(states['sensor.tesla_state'].last_updated).toLocaleString()  +
    '</span>']]]
  time_diff: |
    [[[ return `<span style="position:absolute;  left:0px; font-size:10px;">
     ${new Date().getTime() - new Date(states['sensor.tesla_state'].last_updated).getTime()}
    </span>`]]]

Screenshots Image of the display: image Data from node-red showing update time: image

Expected behavior On last_updated changing, even if the string value is unchanged, it should reflect the actual sensor data for when the sensor was pinged (is this a nodered issue?). I've removed the conditional aspect because to start with the card isn't updating.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Additional context I've also tried adding forced updates to trigger_updates on all, it didn't make any difference

3ative commented 1 year ago

Looks like you are only asking it to look at changes to "sensor.tesla_online", try adding "sensor.tesla_state" to the list. E.G.:

triggers_update:
  - sensor.tesla_online
  - sensor.tesla_state

Or just use: "triggers_update: all"