Repeat until X=True or X repetitions

Hello,

how can I make my loop run until one of the conditions is true.
Either power > 15W
or
The loop went through 5 times.

alias: Lautsprecher WZ Ein
sequence:
  - if:
      - condition: not
        conditions:
          - condition: state
            entity_id: switch.lautsprecher_wz_steckdose
            state: "on"
    then:
      - service: switch.turn_on
        data: {}
        target:
          entity_id: switch.lautsprecher_wz_steckdose
      - delay:
          hours: 0
          minutes: 0
          seconds: 3
          milliseconds: 0
  - if:
      - condition: not
        conditions:
          - condition: state
            entity_id: switch.lautsprecher_wz
            state: "on"
    then:
      - repeat:
          until:
            - condition: numeric_state
              entity_id: sensor.lautsprecher_wz_steckdose_power
              above: 15
          sequence:
            - service: script.turn_on
              data: {}
              target:
                entity_id: script.logitech_toggle_power
            - delay:
                hours: 0
                minutes: 0
                seconds: 5
                milliseconds: 0
mode: single

then:
      - repeat:
          until:
            condition: or
            conditions:
              - condition: numeric_state
                entity_id: sensor.lautsprecher_wz_steckdose_power
                above: 15
              - "{{ repeat.index | int == 5 }}"
          sequence:
            - service: script.turn_on
              data: {}
              target:
                entity_id: script.logitech_toggle_power
            - delay:
                hours: 0
                minutes: 0
                seconds: 5
                milliseconds: 0

should work I think.

1 Like