View to the past

Hello everyone,

Is it somehow possible to query how long a numerical condition exists for a condition?

Example: As a condition for moving my awning, I would like to query whether the wind speed has been below 25 in the last 30 minutes.

I’ve already tried

condition: numeric_state
entity_id: sensor.gw1100a_wind_speed
below: 25
for:
  - hours: 0
  - minutes: 30
  - seconds: 0

, but I get an error message:
Message malformed: extra keys not allowed @ data['action'][0]['if'][1]['conditions'][3]['for']

If you look at the documentation for the numeric state condition you will see there is no for time: https://www.home-assistant.io/docs/scripts/conditions/#numeric-state-condition

However if you look at the documentation for the numeric state trigger, there is a for time https://www.home-assistant.io/docs/automation/trigger/#numeric-state-trigger

Can you change your automation to use the numeric state trigger instead of the condition?

If not, you can create a triggered template binary sensor (numeric state trigger with for time) and use the state of that in a state condition.

No, unfortunately not.
I’ll probably have to solve it with a helper.

Hang on. This:

Is not what the for time enable you to determine. The for time (if it was available) would make the condition true if the value remained below 25 for the last 30 minutes without going above. Which is quite different to what you wanted.

I think I just expressed myself incorrectly.

The awning should only be extended if there has not been a storm in the past half hour.

This should do what you want:

template:
  - trigger:
      - id: 'on'
        platform: numeric_state
        entity_id: sensor.gw1100a_wind_speed
        below: 25
        for:
          minutes: 30
      - id: 'off'
        platform: numeric_state
        entity_id: sensor.gw1100a_wind_speed
        above: 24.99
    binary_sensor:
      - name: Low wind speed
        state: "{{ trigger.id }}"

And your condition would be

condition:
  - condition: state
     entity_id: binary_sensor.low_wind_speed
     state: 'on'
1 Like