Load management based on solar panels production

I created some rules to automate turn on and turn off of air conditioners based on solar panel production.
I’m using Daikin binding for conditioners and SolarEdge binding for photovoltaic.

To turn on conditioner I check every 5 seconds if i’m exporting more than 1kW then turn it on.
This is the rule code:

triggers:
  - id: "5"
    configuration:
      cronExpression: 0/5 * * * * ? *
    type: timer.GenericCronTrigger
conditions:
  - inputs: {}
    id: "2"
    configuration:
      itemName: SolarEdge_Live_Export
      state: "1"
      operator: ">"
    type: core.ItemStateCondition
  - inputs: {}
    id: "1"
    configuration:
      itemName: Condizionatore_Power
      state: OFF
      operator: =
    type: core.ItemStateCondition
actions:
  - inputs: {}
    id: "4"
    configuration:
      itemName: Condizionatore_Power
      command: ON
    type: core.ItemCommandAction

Then to turn them off I check every 5 seconds if import of electricity it’s >0, with this rule:

triggers:
  - id: "1"
    configuration:
      cronExpression: 0/5 * * * * ? *
    type: timer.GenericCronTrigger
conditions:
  - inputs: {}
    id: "3"
    configuration:
      itemName: SolarEdge_Live_Import
      state: "0"
      operator: ">"
    type: core.ItemStateCondition
  - inputs: {}
    id: "4"
    configuration:
      itemName: Condizionatore_Power
      state: ON
      operator: =
    type: core.ItemStateCondition
actions:
  - inputs: {}
    id: "5"
    configuration:
      itemName: Condizionatore_Power
      command: OFF
    type: core.ItemCommandAction

This work as expected, but after some days of use I found out a thing I didn’t considered.
There’s a lot of situation that can cause the air conditioner turn off and on repeatedly, for example in a partially cloudy day where solar panels production can vary a lot during the day.
Or also when turning on high comsumption appliance for few time (for example a microwave for 30 seconds).
I want to avoid turn off units just for 30 seconds or less.
I already thought of increasing the 5 seconds interval to something more like 1 minute, but it’s not the solution, because also if the rule it’s less frequent, it could happen that it run during a very short period where the production of the panels is low, causing an unnecessary shutdown.

Instead of checking the value in that moment, there’s a way to check if the value kept a value greater than 0 for a certain period (for example 5 minutes), and after that time turn of the conditioners??

Maybe you want take a look at debounce.

You can restructure the task for event-driven rules.
Start a five-minute timer.
Trigger a rule from ‘value’ changes.
If ‘value’ less than X, cancel timer.
If timer runs to the end, you know ‘value’ has been above X for five minutes continuously, and timer code can do whatever it is you want to happen.

First of all thank you to both for the tips and sorry for the delay but I didn’t see the notify about the answers.
I modified the in this way (I used blockly because I’m not god with coding).


But I’m getting this error:
Received a QuantityType state ‘0.31 kW’ with unit for item SolarEdge_Live_Export, but the condition is defined as a plain number without unit (1), please consider adding a unit to the condition.

So the problem seem to be with the “kW” after the number, but I can’t find a way to exclude it. Any help?