Timer Duration Limit

Is there suppose to be a duration limit for the Timer? I am running Home Assistant 0.105.3.

The Timer seems to be working correctly when the duration is set for less than a day. A set time that exceeds one day the countdown is frozen or not working.

by countdown you mean timer’s state in Lovelace card?
when it happens, could you check what is the timer’s state in Developer Tools -> States?

Looking at the code, there is no implicit max duration.

python datetime timedelta does have a max of 999999999 days though. So if you plan on running for more than 2.7 million years, you might have an issue. Keep in mind this value will be slightly less as it will do math to compare now() to this timedelta, so you might only be able to run for 2.6 million years.

Agree with @AhmadK…what does the state say?

Looking at python timedelta, anything > 86399 suddenly uses the “days” field for a string. Everything less gets converted into seconds only.

>>> timedelta(seconds=86000)
datetime.timedelta(seconds=86000)
>>> timedelta(seconds=87000)
datetime.timedelta(days=1, seconds=600)
>>> timedelta(seconds=86399)
datetime.timedelta(seconds=86399)
>>> timedelta(seconds=86400)
datetime.timedelta(days=1)
>>> timedelta(hours=10, seconds=50000)
datetime.timedelta(seconds=86000)
>>> timedelta(hours=20, seconds=50000)
datetime.timedelta(days=1, seconds=35600)

I’d be curious to know what lovelace is doing with this timedelta…if anything. The timer class simply converts this timedelta to an endtime.

>>> print(start + timedelta(days=2))
2020-03-18 13:55:53.422844
>>> print(start + timedelta(days=2, seconds=1000))
2020-03-18 14:12:33.422844
>>>

Also note, timers stop on server restart…though it sounds like as soon as you input a value > 1 day, the timer no longer counts right away, not after 24 hours.

1 Like

@AhmadK and @jocnnor I believe you are correct. It seems that the timer is working. It looks like the rendering is an issue in both the lovelace card and the state that are both not showing the countdown.

Maybe you can help me with the retrieval of the countdown via a sensor template, the code bellow shows the remaining time when you pause but I wish to publish the countdown time (lets say every minute)

sensor:

  - platform: template
    sensors: 
      climate_incubator_timer1_remaining:
        friendly_name: "Timer 1 remaining time: "
        value_template: >-
          "{{ state_attr('timer.incubator_heater_timer1', 'remaining') }}"

Add the sensor.time entity. This will cause it to update every minute:

sensor:

  - platform: template
    sensors: 
      climate_incubator_timer1_remaining:
        entity_id: sensor.time
        friendly_name: "Timer 1 remaining time: "
        value_template: >-
          "{{ state_attr('timer.incubator_heater_timer1', 'remaining') }}"

I already tried that and just in case I tried again and it breaks the sensor template:
prior:

sensor.climate_incubator_timer1_remaining	"4 days, 4:15:51"	friendly_name: Timer 1 remaining time:

after with the entity_id: sensor.time

sensor.climate_incubator_timer1_remaining	"0:00:00"	friendly_name: Timer 1 remaining time: 

Just checking, but you did add the actual sensor.time to your configuration?

It’s not there by default. Also, you’ll need one that has time (can’t be date only unless you want updates once/day).

1 Like

@jocnnor Yes I did here is a copy of the code:

  - platform: template
    sensors: 
      climate_incubator_timer1_remaining:
        entity_id: sensor.time
        friendly_name: "Timer 1 remaining time: "
        value_template: >-
          "{{ state_attr('timer.incubator_heater_timer1', 'remaining') }}"

and the template stop working? This is partially why I got fooled thinking that the issue was with the timer though it also does not display the countdown.

That doesn’t show sensor.time configured. You’d have to add it to configuration.yaml. It’s a separate sensor completely useful for many other things.

In developer tools -> states, do you see a sensor.time in the available sensors?

By specifying an entity_id in a template, you are telling HA to update this template every time the entity_id is updated. If you don’t specify one, it will use the value_template to guess which entity it needs to track. By specifying sensor.time, you are forcing it to update every 1 second minute. Without it, it will only update when timer.incubator_heater_timer1 updates…which is only on start/stop/pause.

If you don’t have a sensor.time sensor created, it will never update as it wont be able to follow the missing sensor.

Every 1 minute actually.

Oh, right! Thanks

@jocnnor Thanks for the explanation. Indeed I was missing the ‘sensor.time’ May I ask how I retrieve the running countdown attribute? I can see it in the timer if is less than 24 hours but after that it disappears from the entity

This won’t work anyway as you have a multi line symbol, followed by a single line format template

I think that the attribute ‘remaining’ is updated only if I an execution of the start/stop/pause occurs.

Though I appreciate the suggestion of using the sensor.time (I also learned something new). This is not exactly helping me to get an update of the remaining time while the timer is running.

@Mutt Strange it seems to give an output for the time? I still have the issue with getting the real time countdown

I suspect that’s a bug we’re yet to find a way to deal with.
Long story short, but here is one of the discussions, have a read. Pay attention to balloob’s reply on how LL deals with timers.

Just to make it clear - remaining attribute is not updated on running timers at the moment if you use standard timer. Therefore it’s kind of pointless to use it. At the link above I described a workaround using input_datetime - let me know if you need more details.

Not sure why the attribute vanishes when greater than 1 day. It is converting it to a string…and timedelta conversion does something different when > 1 day. Could be something else causing the attribute to be empty.

https://github.com/home-assistant/core/blob/397238372efe7e74613c49c4c542a39d0e49f8df/homeassistant/components/timer/init.py#L225

Check out the output of the python conversion when it’s less than 1 day.

>>> print(str(timedelta(hours=20, seconds=50000)))
1 day, 9:53:20
>>> print(str(timedelta(seconds=50000)))
13:53:20

BUT!!

Keep in mind, these attributes are ONLY updated on start/stop/pause events. It’s not a bug. This class updates these values, then fires off a callback to the system at some future date. In between all of those, none of these values are going to update. So even if it wasn’t missing, it’s not going to help you as it wont update ever.

You’d think the END time would be an attribute. Then you could just use a template sensor and calculate the timer yourself if you cared!

do you think it makes the attribute disappear?

Not sure. I’m not sure if there is some config that tells HA the output to expect. Attributes can be literally any string, so it should just be the entire string there unless it’s validating the attribute to something else.

I mean what did you mean by saying