Empty progress bar with `remain_time`
jd1 opened this issue · comments
Describe the bug
I tried to show the remaining charging time of my car, but the progress bar doesn't show any progress. It's always empty. Only the remaining time is updated.
Your card configuration
type: custom:timer-bar-card
entity: switch.tmbjc7ny6nf049498_charging
remain_time:
entity: sensor.tmbjc7ny6nf049498_charging_time_left
units: minutes
debug: true
Debug information
State: on (state mode = active)
Mode: active (auto mode = N/A, unused)
Duration: second
Time remaining: 10800
Counter: 10800
Attr: {"last_result":"N/A","last_timestamp":"1970-01-01T00:00:00","model":"Škoda Enyaq 80 iV 80/2022-05-31","icon":"mdi:battery-outline","friendly_name":"TMBJC7NY6NF049498 Charging"}
switch.tmbjc7ny6nf049498_charging
automatically updates its state to 'on' if the car starts charging. This is recognized by the card. It's visible and the states changes in the debug information.
sensor.tmbjc7ny6nf049498_charging_time_left
contains the remaining time in minutes. One problem of this entity is that it only updates every 5 minutes, but this shouldn't break the card.
I don't why the progress bar is not updating. According to the docs it should be enough to set Remaining Time + Active State and active state is detected correctly.
I got it working with a template sensor:
- name: End of charging
device_class: timestamp
state: "{{ now() + timedelta(minutes=states('sensor.tmbjc7ny6nf049498_charging_time_left')|int) }}"
With this I can use end_time
and the card is working as expected:
type: custom:timer-bar-card
entity: switch.tmbjc7ny6nf049498_charging
end_time:
entity: sensor.end_of_charging
name: verbleibende Zeit
debug: true
I created a small test setup to have a look at all values:
- The first row is the card with
remain_time
. It does not update at all. It always shows the same value. Only when you refresh the page, a new value is loaded. - The second row uses the template entity. It works.
- The third row is the sensor with the remaining charging time:
sensor.tmbjc7ny6nf049498_charging_time_left
As mentioned above, it only updates every 5 minutes, but it updates. - The fourth row is the template sensor. Since
sensor.tmbjc7ny6nf049498_charging_time_left
updates every 5 minutes, the value of the template sensor jumps a little bit.
Sorry it's taken so long for me to reply. The v1.28 update back in June should have made the remain_time
option more reliable when used with other entities.
Are you using this version or the latest version, or is this still an issue with the card?
Thanks for the reply. I'm using version 1.29.1.
As you can see in the screenshots, the calculation of duration is not correct. Maybe remain_time
wasn't taken into account for one of the calculations. I dug a little bit into the code and tried a fix in findDuration. It didn't work, but it was just a quick attempt without understanding the full context.
Well, I guess those updates didn't fix whatever the problem may be here.
My guess is/was that the card is not re-rendering every time the entity changes. Since you're already digging into the code, try adding a console.log
and see if it fires every second (or every minute, or however often that time left entity updates). The shouldUpdate
function is what's responsible for deciding whether the card needs to re-render (and in doing so grab new information from Home Assistant).
That remain_time
is difficult to test as no built-in components in Home Assistant use that scheme. Thus, I've also written no tests for it. The template is always going to be more reliable.