Numeric_state condition with for

I would like to see a “for:” option added to the numeric_state condition.

I have an automation that checks every 5 minutes if all conditions are met and when so the AC is turned on. One of the conditions is that the lux level in the bedroom needs to be above 10 lx. So when we open the curtains the lx level goes above 10 and then when checked the condition is true and the AC will turn on. Now sometimes it so happens that we open the curtain and at that same moment the automation fires in which the ac is turned on immediately. I would like it to only turn on when we are allready downstairs. So a for: ‘00:05:00’ option would only make the numeric state condition go true when the lx is above 10 for 5 minutes. I know this was allready added to the trigger side of the automation. But when testing it in the condition part I get an error. So I guess it’s not yet a feature there

A post was merged into an existing topic: Make numeric_state behaviour consistent in trigger vs condition

For future reference, automations designed this way, where they “poll” a set of conditions, are inefficient and can often be redesigned (the Time Pattern Trigger is replaced with a set of matching triggers and conditions). The end-result is an efficient automation that triggers only when necessary as opposed to every X minutes.

I understand but my automations are becoming to complex to use triggers. The question is in what aspect are they inefficient. If it’s system resources then that is not a problem for me at the moment. I guess a few lines of code running every 5 minutes isn’t a big problem? I imagine games with thousands of things happening on screen is far more complex then checking if a temperature is on a value. And a lx level is above a value for 10 minutes. Only the movement of a character in games involves hundreds maybe thousands of automations running 120 times a second or more.

In the 2.5 years that I have been helping people to debug their automations, I have never heard anyone make that claim. I’ll believe it when I see it.

It’s not just a needless use of resources (regardless of how many CPU cycles are available) it’s often an example of a limited understanding of what is available in Home Assistant.

Many new users employ polling because that’s the only design pattern they know. They defend their usage of it because they are often unfamiliar with any other pattern. To paraphrase an old adage, they only know how to use a hammer and see everything as a nail. Home Assistant provides more specialized and efficient tools than just a hammer.

But continue hammering away if that’s what you prefer to do. :man_shrugging:

3 Likes

numeric_state have the “for” clause only when used as trigger, but it is not available when used as a condition for the automation.
This is strange to me. As an example, state has the “for” clause for both trigger and condition mode.

I think it should be added for completeness.

1 Like

Can you show us an example of this then instead of telling us what we don’t know. We are all here to learn and everyone started somewhere.

Check my posting history; you’ll discover I have shared many examples over the past ~4 years.