Using the TOTAL start time of a Timer in an automation / Template Sensor check

Chaps; long story short I use HA to automate my Koi Pond Waterchanges. I have one pump that emptys water, and another that fills again. 1% Pond Volume every day. I use timers to fill and empty. The timer turns the pump on, when the timer finishes it turns the pump off. SIMPLE

I would like to have automations that check the devices have not been on longer than the total time of the timer. I want the automation to follow the initial total time of the timer . . . so if I change the Timer total time, the automation follows. Rather than setting a static time in the automation.

I’ve worked out how to GET the timer total into a template sensor

state: "{{ state_attr('timer.timer_pond_61_waterchangedaily_max_empty_time', 'duration') }}"

But this gives me an output of 0:14:00
I need to covert this into seconds . . . . . but for the life of me I can’t figure out how to do it. I thought this would work but it throws an error

state: "{{ states('sensor.template_sensor_pond_timer_waterchangedaily_empty_total_time_hrs_mins') | float > 1 }}"

ValueError: Template error: float got invalid input ‘state: “0:14:00”’ when rendering template

Any help would be greatly appreciated

{{ as_timedelta(state_attr('timer.timer_pond_61_waterchangedaily_max_empty_time', 'duration')).seconds }}
1 Like

Awesome mate, THANKYOU

Your syntax is missing a “)” if you wanted to update it

{{ as_timedelta(state_attr('timer.timer_pond_61_waterchangedaily_max_empty_time', 'duration')).seconds }}
1 Like

It looks like it doesn’t matter in this context since your pump is not running for more than a day, but in case you leverage this logic elsewhere:

.seconds is a property of a timedelta object that represents the number of seconds remaining if all the full days are removed (i.e. the resulting value will never reach or exceed 46800).

If you want to convert the entire timedelta object to seconds, you should use the .total_seconds() method.

2 Likes

Thanks matey . . . . great info