Script with repeat action and additional action after n-th repeat

Hi, I have a script which repeats actions 5 times. After the 5th repetition an additional action shall be executed in the end. As “5” will be replaced by an input number in the future (to repeat it n-times), I need a function, which detects if the script is in the last cycle, and if yes, the additional action shall be added.

The script is for watering different zones in n=5 cycles, and if watering is finished (n-th cycle completed) then a bucket (water requirement) shall be reset by the additional action.

The script looks like this, goes through the cycles, but does not reset the bucket in the end. Any idea what’s wrong?

alias: Consecutive watering 2 Zones and Pause
sequence:
  - repeat:
      count: "5"
      sequence:
        - alias: Watering zone 1 - Rasen
          if:
            - condition: time
              weekday:
                - mon
                - wed
                - fri
              enabled: true
          then:
            - service: homeassistant.turn_on
              data: {}
              target:
                entity_id: input_boolean.eve_aqua_1_garten
            - delay:
                seconds: >-
                  {{states("sensor.smart_irrigation_garten_rasen") |
                  multiply(1/5)}}
            - service: homeassistant.turn_off
              data: {}
              target:
                entity_id: input_boolean.eve_aqua_1_garten
        - alias: Watering zone 2 - Vorgarten
          if:
            - condition: time
              weekday:
                - mon
                - tue
                - wed
                - thu
                - fri
                - sat
              enabled: true
          then:
            - service: homeassistant.turn_on
              data: {}
              target:
                entity_id: input_boolean.eve_aqua_2_vorgarten
            - delay:
                seconds: >-
                  {{states("sensor.smart_irrigation_vorgarten") |
                  multiply(1/5)}}
            - service: homeassistant.turn_off
              data: {}
              target:
                entity_id: input_boolean.eve_aqua_2_vorgarten
        - alias: Dummy zone 3 - Pause
          if: []
          then:
            - service: homeassistant.turn_on
              data: {}
              target:
                entity_id:
                  - input_boolean.eve_aqua_3_pause
            - delay:
                seconds: "{{states(\"sensor.smart_irrigation_pause\") | multiply(1/5)}}"
            - service: homeassistant.turn_off
              data: {}
              target:
                entity_id:
                  - input_boolean.eve_aqua_3_pause
        - if:
            - condition: template
              value_template: repeat.last
          then:
            - alias: Reset bucket 1 - Rasen
              if:
                - condition: time
                  weekday:
                    - mon
                    - wed
                    - fri
                  enabled: true
              then:
                - service: smart_irrigation.reset_bucket
                  target:
                    entity_id: sensor.smart_irrigation_garten_rasen
                  data: {}
            - alias: Reset bucket 2 - Vorgarten
              if:
                - condition: time
                  weekday:
                    - mon
                    - tue
                    - wed
                    - thu
                    - fri
                    - sat
                  enabled: true
              then:
                - service: smart_irrigation.reset_bucket
                  target:
                    entity_id:
                      - sensor.smart_irrigation_vorgarten
                  data: {}
mode: single
icon: mdi:sprinkler-variant
fields: {}