Status of “for:” trigger

Is there a way to check the status of the “for:” condition when used with an automation state trigger?

I have an automation set to run after an input Boolean is on for 12 hours, but it doesn’t seem to be working right. I’d like to be able to see the elapsed time as HA sees it to troubleshoot the automation.

You can’t determine the elapsed time of the for option.

During those 12 hours, if you restart Home Assistant or even just Reload Automations, whatever elapsed time the for may have had is lost and it starts its countdown again.

Basically, it’s inadvisable to use for to handle long stretches of time because it’s vulnerable to being reset merely by Reload Automations.

There are more robust ways of handling long durations that can even survive a restart. What is the application you have that requires this 12-hour period?

Notification for high pH in my pool. I have it set to notify if the sensor goes above 8, but I really only want to know if it goes above 8 and stays above 8 for a while because it fluctuates a lot, particularly after the addition of certain chemicals which will cause high readings for a couple hours. It is also inaccurate when the pool pump is off.

You might want to have a look at the History Stats integration which can report the duration that the input_boolean is on. Alternatively, you can create a Template Sensor that calculates how long the input_boolean is on (based on its last_changed property).

Ok. I think I’ve actually found a good solution by creating a timer entity which I can start and stop based on the input_boolean and it will fire the automation if the timer successfully completes. And I can output the timers current state.

Timers don’t survive a restart (and are reset by Reload Timers). The two techniques I suggested don’t have that drawback (and are simpler to implement).

However, if you want to use a timer, you may be interested in a technique for restoring active timers after a restart.