Automation : Automatically increase the power controller on my heating rod step by step depending on the PV power surplus

Hello, I would like to increase and decrease a power controller on my heater automatically step by step depending on PV power surplus.

I have a shelly that can measure the current at the heater power controller and I also have an electricity meter that displays the surplus.

Unfortunately I do not manage to build the automation . The controller is not set correctly. Where is the error? Can someone help me please? Here is my code:

By the way, the power controller is controlled by an ESP8266 via ESPHome as a light dimmer.

alias: Increase heater power
description: |-
  Increase the power of the controller until the consumption is higher than the
    value of the power supply.
trigger:
  - platform: numeric_state
    entity_id: sensor.stromueberschuss
    above: sensor.heizstab_shelly_switch_0_power
condition: []
action:
  - repeat:
      until:
        - condition: numeric_state
          entity_id: sensor.heizstab_shelly_switch_0_power
          above: sensor.stromueberschuss
      sequence:
        - service: light.turn_on
          data:
            brightness_step_pct: 1
          target:
            device_id: 97bd4f311d90ef232ef02d504a93f677
mode: restart


I have solved it by following automation:

alias: Automation Heizstab
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.stromzahler_haushalt_sum_active_instantaneous_power
condition:
  - condition: numeric_state
    entity_id: sensor.hoymiles_1500_ch1_p_dc
    above: 150
    enabled: false
action:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: sensor.stromzahler_haushalt_sum_active_instantaneous_power
            below: -50
        sequence:
          - service: fan.increase_speed
            data:
              percentage_step: 1
            target:
              entity_id: fan.heizstab_heizstab
      - conditions:
          - condition: numeric_state
            entity_id: sensor.stromzahler_haushalt_sum_active_instantaneous_power
            above: -10
            below: 100
        sequence:
          - service: fan.decrease_speed
            data:
              percentage_step: 1
            target:
              entity_id: fan.heizstab_heizstab
      - conditions:
          - condition: numeric_state
            entity_id: sensor.stromzahler_haushalt_sum_active_instantaneous_power
            above: 100
        sequence:
          - service: fan.turn_off
            data: {}
mode: single