How to add a condition for a specific amount of time


I’m trying to start my dishwasher when I’ve enough solar energy.
I have two uses cases:

  1. The diswhasher is ready but there is not enough solar excedent
  2. The solar excedent and the dishwasher becomes ready.

The usecase 1 is perfect and already working
The usecase 2 is partially working: It does start instantly if their is enough solar power, but if it was just closed at some “peak” of energy, it will consider ready.

is there a way to add, as a condition(not a trigger) that it must be in this state for a given amount of time?

alias: Start dishwasher when enough power and dishes dirty
description: ""
  - platform: numeric_state
      - sensor.grid_export_power
      hours: 0
      minutes: 5
      seconds: 0
    above: 2.0
  - platform: state
      - binary_sensor.lave_vaisselle_door
    to: "off"
  - condition: and
      - condition: state
        entity_id: input_boolean.vaisselle_sale
        state: "on"
      - condition: state
        entity_id: binary_sensor.lave_vaisselle_door
        state: "off"
      - condition: state
        entity_id: sensor.lave_vaisselle_operation_state
        state: Ready
      - condition: numeric_state
        entity_id: sensor.grid_export_power
        above: 2.0
  - service: switch.turn_on
    metadata: {}
    data: {}
      entity_id: switch.lave_vaisselle_power
  - delay: "00:00:10"
  - service: home_connect.start_program
      device_id: af59a88273788a4573d17914afb5eff4
      program: Dishcare.Dishwasher.Program.Auto2
mode: single

I’m looking for some equivalent of the “for” of the trigger.

Timer helper?

Not totally sure to understand how it can be setup?

You would create an automation for every change on the “power export”, and stop and reset the time every time it goes below 2kwh and start again when it goes above?

That seems overkill, especially since I’ve multiple devices that will stop and start with different minimum consumption.

Create a template binary sensor that is “on” when the grid export power is above your threshold. This will provide an entity that you can use in the conditions block with a State condition which allows use of the duration variable for.

That could work, it’s not ideal, because it still mean that I’ve to create one entity when it’s above 1.5kw, above 2kw, above 2.5kw, … it’s a shame the numeric state condition cannot have a for.

You could probably set up a trigger-based template sensor to handle multiple ranges and have an attribute for each range to store the timestamp when the range was entered… but I think that’s going to be more complicated in the long term compared to multiple binary sensors. The binary sensors route also gives you the option to configure delay_off so that passing clouds don’t zero out the duration.