Automation - loop or repeat - where and how to configure

Hi!

I would kindly ask for some help. I’m quite unexperienced in yaml and automations. I want to automate my heatpump to avoid excesive export of solar electricity to grid.
The logic I want to take (or if it’s there any better way?) is:

  • when solar export is above 6900 W the switch.tasmota_sonoff_pow2 should be on
  • when solar export is below 6300 W and above 4400 W switch.tasmota_sonoff_pow2 should be off
  • whis ‘throttling’ should repeat (or loop) till the sensor.hot_water_temperature reaches 65 °C
  • when hot water temperature reaches 65 °C the service select.select_option should be called with option Izključeno

Problem: I don’t know where and how to put repeat action?

My code for automation:

alias: Ogrevaj vodo na grelce do 65°C - gen4
description: ""
trigger:
  - platform: state
    entity_id: select.napolni_zalogovnik_na_grelce
    to: Napolni do 65°C
condition: []
action:
  - service: mqtt.publish
    data:
      topic: ebusd/ehp/BackupModeHwc/set
      payload: "2"
  - delay: "00:00:05"
  - service: mqtt.publish
    data:
      topic: ebusd/hwc/StorageTempDesiredStop/set
      payload: "65"
  - delay: "00:00:05"
  - service: mqtt.publish
    data:
      topic: ebusd/hwc/load/set
      payload: "on"
  - delay: "00:00:05"
  - wait_template: "{{ states('sensor.hot_water_temperature') | float < 65 }}"
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ states('sensor.grid_export_power') | float >= 6900 }}"
        sequence:
          - service: switch.turn_on
            entity_id: switch.tasmota_sonoff_pow2
      - conditions:
          - condition: template
            value_template: "{{ states('sensor.grid_export_power') | float < 6300 }}"
        sequence:
          - service: switch.turn_off
            entity_id: switch.tasmota_sonoff_pow2
  - condition: numeric_state
    entity_id: sensor.hot_water_temperature
    above: 65
  - wait_template: "{{ states('sensor.hot_water_temperature') | float < 65 }}"
  - service: select.select_option
    data:
      option: Izključeno

Thank you!