Different on/off actions for automation with repeat until?

Hello, I am trying to control my water boiler through an automation.

The water boiler accepts a phone line, so I have set up a FreePBX system with an ATA. Then, homeassistant runs a shell_command to copy a call file to the /var/spool/asterisk/outgoing FreePBX dir, that causes FreePBX to call the boiler and send the DTMF tones for it to run for 30 minutes.

I also have a shell_command to turn the boiler off with the same method.

My problem is that the on state of the boiler only lasts for 30 minutes. So, I wrote up an automation to run the shell_command every 32 minutes so that it keeps the boiler running continuously. The automation gets triggered by an input_boolean.

Now, I want the input_boolean to have a dual action. If I turn it on, I want the automation to run as mentioned above, but if I turn it off, I want it to issue the boiler off shell_command. How can I do this?

Here is my configuration.yaml:


# Loads default set of integrations. Do not remove.
default_config:

# Text to speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

shell_command:
  boiler_heat_on: cp /asterisk/turn_boiler_on.call /asteriskout/.
  boiler_heat_off: cp /asterisk/turn_boiler_off.call /asteriskout/.


# Example configuration.yaml entry
input_button:
  boiler_heat_off:
    name: Boiler heat OFF
  boiler_heat_on:
    name: Boiler heat ON


automation boiler off:
  trigger:
    - platform: state
      entity_id: input_button.boiler_heat_off
  action:
    - service: shell_command.boiler_heat_off

automation boiler on:
  initial_state: false
  trigger:
    - platform: state
      entity_id: input_button.boiler_heat_on
  action:
    - service: shell_command.boiler_heat_on

automation keep boiler on:
  alias: "Run Boiler Until Off"
  trigger:
    - platform: state
      entity_id: input_boolean.keep_boiler_on
  condition:
    - condition: state
      entity_id: input_boolean.keep_boiler_on
      state: "on"
  action:
    repeat:
      sequence:
        - service: shell_command.boiler_heat_on
        - delay:
            minutes: 32
      until:
        - condition: state
          entity_id: input_boolean.keep_boiler_on
          state: "off"
            

input_boolean:
  keep_boiler_on:
    name: Keep Boiler On
    initial: false

Relevant sections are: automation keep boiler on AND input_boolean