Conditional execution of parts of scripts

I have my receiver set up in HA. Everything works fine manually, but now I want to automate things. For example, switching the input and changing the volume works fine, but I’m stuck on how to conditionally turning my receiver on first.
What I want to do is something like:

if (states.media_players.radio == "off") {
  - service: media_player.turn_on
    - data: 
      - entity_id: media_player.radio
  - delay:
    seconds: 10
}
- service: media_player.volume_set
  - data: 
    - entity_id: media_player.radio
    - volume_level: 0.1
- service: media_player.select_source
  - data: 
    - entity_id: media_player.radio
    - source: "TUNER"

How should I do this in a proper way? Conditions don’t seem to be an option here, since I want the script to resume and not quit. The only examples of using if/else templates seem to work on simple attributes and not entire “code blocks”.

Start a script that does the check if on and turn on if not. Use wait template instead of the delay.

E.g.: in the script check if tuner is on with condition, if so exit and if not turn it on and wait for it to report on.

Then the rest of your automation is as above,

Splitting it would indeed work around the issue, but I don’t think it would work because when calling script A from another script B, script B doesn’t wait for A to finish and immediately executes the next step in the script.

Thats why you use wait_template in both the script (if off, turn on and wait for on) and in the main automation (wait for on) to work around that.