home-assistant / frontend

:lollipop: Frontend for Home Assistant
https://demo.home-assistant.io
Other
3.99k stars 2.72k forks source link

Timer entity not updated #21160

Closed qrockz closed 2 months ago

qrockz commented 3 months ago

Checklist

Describe the issue you are experiencing

I've set up an timer with an automation. The timer runs every 5 seconds and as soon it hits Idle status the timer restarts. So on the first time starting the timer the dashboard shows the time running down (5..4..3..2..1) as expected. Then the timer hits Idle status because it's finished and restarts because an automation recognized the Idle status and will restart the timer. But the dashboard does not show the time running down as it should. Instead it shows Idle. But the timer still runs and restarts in the background because the output entity logs it as you can see in the screen recording I've made

https://github.com/home-assistant/frontend/assets/56853194/99fac07f-e44a-45cc-81cf-3fcb560ecd9c

Describe the behavior you expected

The timer runs every 5 seconds and as soon it hits Idle status the timer restarts. The dashboard should always show the time running down (5..4..3..2..1) as soon the timer restarts.

Steps to reproduce the issue

automation wich will restart the timer as soon the timer hits Idle status.

alias: Atimeridle
description: ""
trigger:
  - platform: state
    entity_id:
      - timer.timerf
    to: idle
condition: []
action:
  - service: timer.start
    metadata: {}
    data:
      duration: "5"
    target:
      entity_id: timer.timerf
  - service: input_text.set_value
    metadata: {}
    data:
      value: Timer was idle
    target:
      entity_id: input_text.output
mode: restart

vertikal stack in the dashboard ui which you can see from the screen recording

type: vertical-stack
cards:
  - type: entities
    entities:
      - input_text.output
  - type: entities
    entities:
      - timer.timerf
  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: call-service
      service: timer.start
      target:
        entity_id: timer.timerf
      data:
        duration: '5'
    entity: timer.timerf
    icon: mdi:battery-clock
    name: Start Timer
  - show_name: true
    show_icon: true
    type: button
    tap_action:
      action: toggle
    entity: automation.atimer
    name: Automation restart timer infinite

just an automation which updates the text box which logs the timer status and proves that the timer is running

alias: Atimerrunning
description: ""
trigger:
  - platform: state
    entity_id:
      - timer.timerf
    to: active
    for:
      hours: 0
      minutes: 0
      seconds: 2
condition: []
action:
  - service: input_text.set_value
    metadata: {}
    data:
      value: "Timer ist running again. "
    target:
      entity_id: input_text.output
mode: restart

      entity_id: input_text.output
mode: restart

What version of Home Assistant Core has the issue?

2024.6.4

What was the last working version of Home Assistant Core?

No response

In which browser are you experiencing the issue with?

Firefox on Desktop and Mobile

Which operating system are you using to run this browser?

Ubuntu 23.10 6.5.0-41-generic

State of relevant entities

time.timerf
duration: "0:00:05"
editable: true
friendly_name: "timerf, time left:"

Problem-relevant frontend configuration

No response

Javascript errors shown in your browser console/inspector

No response

Additional information

No response

karwosts commented 3 months ago

I think this might be a core issue, as it seems that when you turn on the entity immediately in response to it going idle, the frontend receives the events out of expected order.

Every 5 seconds, we first receive a state changed event saying that the timer is being set to active, and that is immediately followed by the state changed event saying that the timer went idle. So we think it's always idle. You can see this if you look at the timer entity in the logbook:

image

You can work around this by inserting a 1ms delay operation before restarting the timer. But maybe this needs a core issue.

I think someone reported a similar issue for another type of entity recently, but I haven't looked it up yet, not sure if it ever went anywhere.

karwosts commented 3 months ago

I guess it's this one:

https://github.com/home-assistant/core/issues/117781

silamon commented 2 months ago

Closing since the core issue is solved.