Numeric_state condition with "for:"?

When using numeric_state or state triggers as well as when using state conditions it is possible to use the “for” attribute on the condition to specify for how long the condition will have to be met before the trigger fires / the condition is fulfilled.

condition: state
entity_id: binary_sensor.thingy
state: 'on'
for: 60

Condition only passes when binary_sensor.thingy is on for at least 60 seconds. Also see state condition documentation.

However, when I try to add a for: to a numeric_state condition, I get an error.

Example condition:

condition: numeric_state
entity_id: sensor.thingy
below: 30
for: 60

Error:

Invalid config for [automation]: [for] is an invalid option for [automation]. Check: automation->action->0->choose->0->conditions->5->for. (See ?, line ?).

Am I doing something wrong? Is for: simply not supported for numeric_state conditions? Why is that? It appears to be supported for numeric_state triggers.

Please refer to the documentation, it is not a supported option: https://www.home-assistant.io/docs/scripts/conditions/#numeric-state-condition

These situations are where a Template Binary Sensor are useful.

Create the binary sensor with the above or below condition.

Then use that binary_sensor as your state trigger for: the desired time.

Thank you for the clarification @tom_l. I did refer to the documentation, and noticed it wasn’t explicitly listed, but it wasn’t clear to me if this was just a gap in the documentation or it actually wasn’t supported. It seemed a little inconsistent that the for: attribute was supported on state conditions and all state triggers (including numeric_state triggers), but not on numeric_state conditions. That’s why I posted for clarification.

That seems like a reasonable workaround. Thanks!

For reference: here’s the feature request in the forum to add for: support to numeric_state conditions.

@dev0 Could you clarify the feature request link please because it just points back to this thread.

I would like to add my vote for this feature.

Edit - found this feature request, but as it’s been going since 2016 I don’t hold much hope for it. :frowning:

3 Likes