# 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.

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