Seeking Help with Heat Pump Automation and Solar Energy Management

Hello fellow smart home enthusiasts! I’m reaching out to seek some guidance on a project I’m working on to automate my heat pump system. The goal is to optimize the use of solar energy and avoid excessive export to the grid. I’ve set up some logic, but I’m stuck on how to implement a loop or repeat function until a certain temperature is reached. Here’s what I’m trying to achieve:

  1. When solar export exceeds 6900 W, I want to turn on a specific switch to manage energy flow.
  2. If the solar export drops below 6300 W, I want to turn off that same switch.
  3. This process should continue (loop) until the hot water temperature reaches 65°C.
  4. Once the temperature is reached, I want to trigger a service to set a specific option.

Here’s the YAML code I’ve put together so far. I’m particularly unsure about where and how to incorporate the repeat action. Any insights or suggestions would be greatly appreciated!

yaml
alias: Heat Pump Automation for Solar Energy Management
description: Automate heat pump to optimize solar energy usage
trigger:

  • platform: state
    entity_id: select.solar_management
    to: “Activate”
    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: Standby

I’m particularly struggling with implementing the loop functionality to ensure the automation continues until the desired temperature is achieved. If anyone has experience with similar setups or can point me in the right direction, I’d be incredibly grateful! Happy automating!