frontend icon indicating copy to clipboard operation
frontend copied to clipboard

'remaining' Attribute of timer helper Entity stays static instead of counting down

Open RoepLuke opened this issue 2 years ago • 2 comments

Checklist

  • [X] I have updated to the latest available Home Assistant version.
  • [X] I have cleared the cache of my browser.
  • [X] I have tried a different browser to see if it is related to my browser.

Describe the issue you are experiencing

I tried using the attribute "remaining" in an Entity-Attribute Card. The Attribute 'remaining' of a timer helper always stays at the initial time. Per my definition this should at least periodically decrease as the time is active, otherwise it would be a duplicate of the 'duration' attribute. image image image

Describe the behavior you expected

I expected the attribute 'remaining' to at least periodically (every second / every ten seconds / etc.) to update an display the remaining time instead of the duration.

Steps to reproduce the issue

  1. Create a timer helper with any duration
  2. Create a Lovelace Dashboard and add a Entity Card (Select the timer Entity and set the 'remaining'-Attribute to be displayed)
  3. Save the created Card and edited Dashboard
  4. Start/activate the Timer helper
  5. The Time on the card will stay the same. You can also check this in the developer tools when taking a look at the timer Entity

What version of Home Assistant Core has the issue?

2022.5.3 and before

What was the last working version of Home Assistant Core?

No response

In which browser are you experiencing the issue with?

Mozilla Firefox 100.0 (64-Bit)

Which operating system are you using to run this browser?

Fedora 36 for Workstations

State of relevant entities

timer.gaeste_anwesend_timeout - active

ATTRIBUTES
duration: 6:00:00
editable: true
finishes_at: 2022-05-13T03:30:15+00:00
remaining: 6:00:00
restore: true
icon: mdi:timer-outline
friendly_name: gaeste_anwesend_timeout

Problem-relevant frontend configuration

type: entity
entity: timer.gaeste_anwesend_timeout
name: Timer
unit: HH:MM:SS
state_color: true
attribute: remaining

Javascript errors shown in your browser console/inspector

none

Additional information

The other Variant (Create Lovelace card by selecting only the timer entity and creating a card from that) suggested by @wjarka in another issue regarding timer helpers (https://github.com/home-assistant/frontend/issues/12587) works on my HA-Instance, but that's not what I want designwise: image

RoepLuke avatar May 12 '22 22:05 RoepLuke

I have experience the same issue for well over a year with the Lovelace entity card (not the Entities card).

Home Assistant 2022.7.3 Supervisor 2022.07.0 Operating System 8.2 Frontend 20220707.0 - latest

rml1111 avatar Jul 12 '22 17:07 rml1111

@rml1111 this seems to be by design... see here: https://github.com/home-assistant/core/issues/73752 I personally don't see why this should be the behavior by design, but according to the commenter in that issue it currently seems to be.

Here is my workaround, using either a mushroom-template-card or a general template-entity:

{% if is_state('timer.YOUR_ENTITY_ID','active') %}

{% set finish_timestamp = as_datetime(state_attr('timer.YOUR_ENTITY_ID','finishes_at')) %}
{% set current_timestamp = now() %}
{% set remaining_in_seconds = (finish_timestamp - current_timestamp).seconds %}
{{ timedelta(seconds = remaining_in_seconds) }}

{% else %}

{{ '00:00:00' }}

{% endif %}

This updates about every minute by default.

RoepLuke avatar Aug 12 '22 13:08 RoepLuke

@RoepLuke thanks so much for your feedback. I agree that the behavior in for timers in the ENTITY card does not make sense, especially since timers countdown in real-time in the ENTITIES card? Why is there a difference between the two. Nonetheless, I will give your workaround a try. A couple of questions, would it be possible to share the full YAML for the mushroom-template-card? I tried inserting the code above and got an error. Also, do you know if there is there a way to change the default update interval - for example, to every 10 seconds?

rml1111 avatar Aug 17 '22 13:08 rml1111

This is the template card

guests-off.png guests-on.png

type: custom:mushroom-template-card
entity: input_boolean.guests_are_here
fill_container: true
tap_action:
  action: toggle
hold_action:
  action: more-info
double_tap_action:
  action: none
primary_info: name
secondary_info: none
icon_color: |-
  {% if is_state('timer.gaeste_anwesend_timeout','active') %}
  green
  {% endif %}
secondary: >-
  {% if is_state('timer.gaeste_anwesend_timeout','active') %}

  {% set finish_timestamp = as_datetime(state_attr('timer.gaeste_anwesend_timeout','finishes_at')) %}
  {% set current_timestamp = now() %}
  {% set remaining_in_seconds = (finish_timestamp - current_timestamp).seconds %}
  {{ 'Timeout ' ~ timedelta(seconds = remaining_in_seconds) }}

  {% else %}

  {{ 'Keine anwesend' }}

  {% endif %}
primary: Gäste
icon: mdi:account-multiple-plus-outline
badge_icon: |-
  {% if is_state('timer.gaeste_anwesend_timeout','active') %}
  mdi:timer-outline
  {% endif %}
badge_color: green

It uses the following helper entites:

unique_id: timer.gaeste_anwesend_timeout type: timer

unique_id: input_boolean.guests_are_here type: boolean

Update interval:

I know that template entities created via configuration.yml can have a non-default update-interval / can be updates via a service. Generally Template Entites update as soon as their inputs do and i this case the now() function causes an update at the start of every minute.

RoepLuke avatar Aug 17 '22 14:08 RoepLuke

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Nov 15 '22 15:11 github-actions[bot]

I just tested the behavior in 2022.11.2 (container) and the issue still persists. The above mentioned workaround works but thats by far not a user-friendly solution.

RoepLuke avatar Nov 15 '22 18:11 RoepLuke

I'm going to go ahead and close this as the current behavior is by design.

As described in the linked issue https://github.com/home-assistant/core/issues/73752, the fact that remaining attribute does not count down while the timer is active was declared to be by design in the core repo. Like it or not, that is outside the scope of a frontend issue. The fact is that we get the remaining attribute from core, and it is what it is, even if it seems weird. Therefore when asked to display the remaining attribute in the entity card, that is what we must do.

The entities card has a special renderer for timer entities, that uses special code to calculate the time remaining in the browser. That is why it is able to show a live count down.

The single entity card is simpler and does not have these special per-domain renderers, it just simply displays the state or attribute requested. So displaying the actual value of remaining as it is reported by core is the correct behavior when that is selected for a timer entity.

If you want some other kind of card other than entities to show active timer countdowns, that's a good topic for the discussions area to make feature requests, or you can use a custom card workaround. But there's nothing here that I would describe as a bug that could be fixed.

karwosts avatar Jul 24 '23 20:07 karwosts