How to exit repeat-loop?

Hello,

In this script I switch on my aircon. Unfortunately, sometimes it doesn’t work…so I run it a second time (repeat-loop).
How can I exit the loop if the aircon is on ?

alias: 'Switch : Airco x op y graden'
description: Set airco mode to heat and set temperature
fields:
  temperature:
    description: The temperature to set the airco at
    default: 22
    example: '21'
  entity_id:
    description: The climate entity you want to control
    default: climate.airco_gang
    example: climate.airco_gang
sequence:
  - repeat:
      sequence:
        - service: climate.turn_on
          target:
            entity_id: '{{ entity_id }}'
        - service: climate.set_hvac_mode
          target:
            entity_id: '{{ entity_id }}'
          data:
            hvac_mode: heat
        - service: climate.set_temperature
          data:
            temperature: '{{ temperature }}'
          target:
            entity_id: '{{ entity_id }}'
        - service: climate.set_fan_mode
          data:
            fan_mode: auto
          target:
            entity_id: '{{ entity_id }}'
      until:
        - condition: template
          value_template: '**{{ repeat.index >= 2 }}**'
mode: single

It must been something like when the state of the entity_id is ‘on’, but how can I do that ?

There is an example in the docs:

Thanks, I found it.

      until:
        - condition: template
          value_template: '{{ repeat.index >= 2 or is_state(entity_id, ''heat'')  }}'

2 Likes