Automation for boiler coil

Hi everyone,
I can’t create the right automation for my purpose. Let me explain: I have a photovoltaic system and a storage of 300 liters of hot water for the bathroom. This water storage is heated by a heat pump and a gas boiler (in layers). I also have inserted a coil that runs on electricity which I would like to activate when my photovoltaic system gives more than 2000 watts to the electricity grid. Unfortunately I can’t make it work correctly, meaning that the Shelly 3em that controls the output current is too “immediate and sensitive”. Sometimes my automation sees that I’m temporarily giving more than 2000w of current to the network and activates the coil for any reason, it can be either when the heat pump stops, or the washing machine stops or the oven stops. In short, I would need the power consumption to be checked for 5/10 seconds and, if the condition persists, the coil should be activated. I tried the code I’m attaching, but it doesn’t work! Is it possible to do this? Can you help me? Thank you.

Code:

alias: Boiler coil ON with 2000 watts to the electricity grid
  description: ''
  trigger:
     #check shelly boiler coil is off
  - platform: device
    type: turned_off
    device_id: 2edadbf6cb16c0ffdda25c5f0715c206
    entity_id: b2faa7297e84fc79af557a903d22abe3
    domain: switch
  condition:
     #check photovoltaic system gives more than 2000 watts to the electricity grid
  - type: is_power
    condition: device
    device_id: c5d62eb6b901b3c7c8f944e7a96f175b
    entity_id: cc171a510451a659d1d854b01ce1edcf
    domain: sensor
    below: -2000
       #wait 10 seconds but this condition does not work
  - condition: template
    value_template: delay 10
       #check again photovoltaic system gives more than 2000 watts to the electricity grid
  - type: is_power
    condition: device
    device_id: c5d62eb6b901b3c7c8f944e7a96f175b
    entity_id: cc171a510451a659d1d854b01ce1edcf
    domain: sensor
    below: -2000
  action:
     #turn on shelly boiler coil
  - type: turn_on
    device_id: 2edadbf6cb16c0ffdda25c5f0715c206
    entity_id: b2faa7297e84fc79af557a903d22abe3
    domain: switch
  mode: single

I’d recommend using simpler and clearer entity triggers and conditions, rather than the messy device versions. Try this, replacing the capitalised IDs with your real ones:

trigger:
  - platform: numeric_state
    entity_id: sensor.SHELLY_ID
    below: -2000
    for:
      seconds: 10
action:
  - service: switch.turn_on
    target:
      entity_id: switch.COIL

That will trigger when the power sensor drops from above to below -2000W and stays there for 10 seconds.

Will look like this but with your entity:

Thank you very much!