I want to use the below as a condition so actions of start.timer with a duration are not overwriting a timer if the duration being sent is less that the current timer duration. However, this always returns true no matter what the attribute is set too.
I don’t think string comparisons using greater than and less than are going to return the expected results. You should really convert the duration to an int and then compare them.
The only thing is that I have no idea what format that attribute is in, and if it really is a string with the colons and zeros, that probably won’t convert to an int without some more work. This might work (assuming the duration is only minutes only every time):
Use the built-in functions/filters. Much less chance for the unintended to happen that way.
One thing I certainly did not expect is that according to the documentation for the Timer integration, the duration attribute may contain both a timestring or an int specifying seconds. WTF?
If a template needs to take that into account, things quickly turn messy:
{{ (state_attr('timer.secuirty_lights', 'duration') | string
if state_attr('timer.secuirty_lights', 'duration') is number else
state_attr('timer.secuirty_lights', 'duration')) | as_timedelta
> '00:04:00' | as_timedelta }}
And pretty please fix the typo in timer.secuirty_lights…
Originally I thought I accidentally duplicated Mayhem_SWE’s example but, upon closer inspection, it’s different.
There’s no need to use an if to check the duration value’s format prior to conversion. The duration value is stored as a time string in H:M:S format, even when it’s initially specified as a number in seconds.