Timer - remaining time

I have a case where a button-press would start a timer for 1 hour, and if the button was pressed again, add another hour, and a third press would make it a total of 3 hours. The remaining time would be presented on a screen.
When less then 1 hour remains you should be able to press the button again to extend the time.

The “What the heck?!” is that there is no sensor or something that can give you the time remaining.
In a perfect world there would be a sensor for the timer with the time remaining.
And also the possibility to add/remove time from the timer.

Or is it just me with a very specific case? :slight_smile:

i made a github bug report on this, about a year ago. It was closed because not a priority or some such.
WTH…

Or at very least an attribute stating the time at which the timer will finish. Timers are very limited in their current state.

Absolutely! I’ve been looking for a way to do this for quite some time… and there’s never been a good way to do it.

I have a timer that displays while a given entity ID is ‘on’. The entity is supposed to turn off after a few min on it’s own, but occasionally it does not. As a ‘backup’ i have a HA timer that starts counting down once the entity ID is on.

If i do something like this in my lovelace config:

          - type: vertical-stack
            # See: https://www.home-assistant.io/lovelace/vertical-stack/
            cards:
              - type: entity-button
                name: SomeEntity
                entity: switch.some_device
              # If the timer is counting down....
              - type: conditional
                conditions:
                  - entity: timer.some_device_max_duty_time
                    state_not: "idle"
                card:
                  # ... show how much time remaining
                  type: entity
                  entity: timer.some_device_max_duty_time
                  attribute: remaining

I only ever see the initial time that the timer is set to. I would expect that the value displayed reflects the counting down nature… After all, this works as expected:

# In lovelace:
      - type: vertical-stack
        # See: https://www.home-assistant.io/lovelace/vertical-stack/
        cards:
          - type: custom:bignumber-card
            entity: sensor.human_date

# In sensors:
      # There's no "easy" way to get the simple date (MM/DD, no YY) so we template it
      # This is used for dashboards as a 'wall clock'
      - platform: template
        sensors:
          human_date:
            # Will be in format like 'Sat Nov 30'
            # See: http://strftime.org/
            ##
            # Note: the \n in there to *force* a new line for display in love lace
            value_template: "{{ now().strftime('%H:%M\n%a %b %d') }}"
            friendly_name: "Human Date"
            ##
            # Note: Home Assistant will NOT update the value unless the tempalate is associated w/ an entity
            #   that fires off state change events.
            entity_id: sensor.time

So the value of the template sensor is constantly changing which is reflected on the UI but the value of a counting down timer is not!?!?

Yeah, an attribute with remaining time of the timer is just as good in my case.

1 Like

In “entities” whrn you add “- entity:” for a timer object it shows time remaining by default. Here is example:

entities:
  - entity: switch.sonoff_10004f9c9f
  - type: section
  - conditions:
      - entity: timer.towel_dryer_timer
        state: idle
    row:
      entity: input_number.dlitelnost_raboty_polotentsesushitelia
      name: Длительность
    type: conditional
  - conditions:
      - entity: timer.towel_dryer_timer
        state_not: idle
    row:
      entity: timer.towel_dryer_timer
      name: Оставшееся время
    type: conditional
  - conditions:
      - entity: timer.towel_dryer_timer
        state: idle
    row:
      entities:
        - entity: script.start_towel_dryer_timer
          name: Запустить таймер
      type: buttons
    type: conditional
  - conditions:
      - entity: timer.towel_dryer_timer
        state_not: idle
    row:
      entities:
        - entity: timer.towel_dryer_timer
          icon: 'mdi:restart'
          name: Перезапустить
          tap_action:
            action: call-service
            service: timer.start
            service_data:
              entity_id: timer.towel_dryer_timer
        - entity: timer.towel_dryer_timer
          icon: 'mdi:timer-off-outline'
          name: Остановить
          tap_action:
            action: call-service
            service: timer.cancel
            service_data:
              entity_id: timer.towel_dryer_timer
      type: buttons
    type: conditional
state_color: true
type: entities

timer

1 Like

Yes, thats right. But its not useable in an automation.

It’s looks like a bag - the “remaining” property are not updated:
Remaining

Just my 2 cents,

I was just in the progress of raising this before I found this topic.

As mentioned above, it is widely discussed on these forums that the ‘remaining’ attribute of a timer doesn’t update unless an event is fired in the backend - the countdown that occurs on the frontend is purely frontend driven and is not fed back so, can actually get slightly out-of-sync with the actual timer.

While it would be great to have this attribute updating live, as a go-between, it would be nice to have a service which could be called such as timer.refresh or timer.update that would fire an empty event on the timer and update it’s attributes.

This could then be built in to templating avoiding hacky work-arounds (such as last triggered offsets from now, or firing an event such as timer.pause, then timer.resume to update it’s value)

3 Likes

is this fixed ?

I don’t think so, I’ve been trying to get the remaining time all night but it looks like the attribute is still stale.

It’s hacky but you can work around it by pausing then immediately starting the timer. I’m doing this in Node Red and so far it’s working well. You’ll see a flicker if you display the remaining time on your dashboard though.

Edit: No need to do this, better solution below.

1 Like

I use the attribute of finishes at (or what it’s called) and calculate the time left.
It works fine for me.

1 Like

Ahh that’s a much nicer solution! :ok_hand:

If anyone else is doing this in Node Red, it’s a simple JSONATA expression in a change node to get the seconds remaining:

($toMillis(entity.attributes.finishes_at) - $millis()) / 1000

You can add the timer entity to the msg/flow/global with an output property in a Current State node.

In node red I use this. It even persists HA restarts, unlike the hass timer. It does update the remaining time in the frontend too.

1 Like