Script/automation to toggle a switch with a delay

This might be a stupid question, but I’ve set up an input boolean which I can toggle on/off from my Lovelace dashboard. When this input boolean is switched on, I want a given switch entity to toggle on/off with a delay until I the input boolean is turned off. I’ve tried creating a script with a delay and a repeat with a condition, and I have an automation which runs this script when the input boolean is set to on, but this does not work as expected, not sure what’s going on.

Can anyone provide a script/automation yaml which does this?

Hey, never mind, I figured it out.

Here’s how I did it, the script toggles the switch every 5 minutes.

This is the script:

the_script_to_repeat:
  sequence:
      repeat:
        while:
          - condition: state
            entity_id: input_boolean.the_input_boolean_to_listen_to
            state: "on"
        sequence:
          - service: switch.toggle
            data_template:
              entity_id: switch.the_switch_to_toggle
          - delay:
              minutes: 5
          - service: script.the_script_to_repeat

And here’s the automation:

- id: '1643049993169'
  alias: Automation alias
  description: ''
  trigger:
  - platform: state
    entity_id: input_boolean.the_input_boolean_to_listen_to
    to: 'on'
    from: 'off'
  condition: []
  action:
  - service: script.the_script_to_repeat
  mode: single

Simple enough !