Loop a Condition in automation until it will be "true"

Hi @ all.
I need a bit of help with this automation:
turn on my heat-pump if PV-Inverter-Room temperature is too hot (above 35°) and if there’s enough solar pv production and battery charge is >55%.
Then automation must turn off Heat-Pump if after 1 hour PV-Inverter-Room temperature will be below 32° or loop until temperature will be below 32° and when it will append turn off heat pump.

Can do all I want by this code or there’s something wrong? Thanks 4 help in advance.

alias: PV-Inverter-Room Automatic air conditioning (test)
description: PV-Inverter-Room Automatic air conditioning if temperature is too hot
trigger:
  - platform: numeric_state
    entity_id: sensor.ventola_mansarda_temperature
    for:
      hours: 0
      minutes: 5
      seconds: 0
    above: '35'
condition:
  - condition: numeric_state
    entity_id: sensor.battery_state_of_capacity
    above: '55'
  - condition: numeric_state
    entity_id: sensor.energy_next_hour
    above: '1.50'
  - condition: numeric_state
    entity_id: sensor.ventola_mansarda_temperature
    above: '35'
action:
  - service: notify.mobile_app_smartphone_michele
    data:
      message: >-
        La Temperatura del locale tecnico è ELEVATA ed è pari a {{
        states("sensor.ventola_mansarda_temperature") }} °, avvio
        climatizzazione
      title: >-
        Temperatura Locale tecnico di {{
        states("sensor.ventola_mansarda_temperature") }} °
  - service: climate.turn_on
    target:
      entity_id: climate.altherma
    data: {}
  - delay:
      hours: 1
      minutes: 0
      seconds: 0
      milliseconds: 0
  - if:
      - condition: numeric_state
        entity_id: sensor.ventola_mansarda_temperature
        below: '32'
    then:
      - service: climate.turn_off
        data: {}
        target:
          entity_id: climate.altherma
    else:
      - repeat:
          until:
            - condition: numeric_state
              entity_id: sensor.ventola_mansarda_temperature
              below: '32'
          sequence:
            - service: climate.turn_off
              data: {}
              target:
                entity_id: climate.altherma
mode: single

Better don’t use delay. It will not survive a restart.

1 Like