Script for opening apps on TV

Hello,
firstly i want to mention that i am knew with writing scripts and also a bit confused. Secondly, my overall goal is to change source on TV based on which one is turned on. Once the scripts are done then i will use IFTTT to execute them via voice commands. What the script i want to do

I have 2 TVs one in the bedroom and one in the living room and instead of having one command for every app and every TV i want to choose the TV based on its state. If both are turned off i want to turn on the one in the living room and then go to the app i want. The part to choose TV when one of them is open it’s ok. I m having a problem with the script that turns on the tv.

I was thinking of checking if both TVs are off, then turn one ON and then continue to the code that i have already and working that chooses between the 2 TVs. If anyone has an idea of how to do it or a better way to do it i would be grateful. The code i have and working is at the end…

  netflix:
    alias: Netflix Script
    sequence:
    - service: media_player.select_source
      data_template:
        entity_id: >
          {% if (states('media_player.bedroom_tv') == 'on') %}
            media_player.bedroom_tv
          {%-elif (states('media_player.living_room_tv') == 'on')  %}
            media_player.living_room_tv
          {% else %}
### MAYBE I WILL USE THIS PART TO TURN ON THE TV ###
          {% endif %}
        source: 'Netflix'

Apparently i always figure things out after i ask for help… This one it does what i want… Still open to optimise it though… And a question I Have. Can i use IFTTT ingredients and pass the ingredients as the source app to open? So instead of a script for every source i want i will have one code and the things it will change it will be the ingredient.

  netflix:
    alias: Netflix Script
    sequence:
    - service: media_player.turn_on
      data_template:
        entity_id: >
          {% if (states('media_player.bedroom_tv') == 'off') and (states('media_player.living_room_tv') == 'off') %}
            media_player.living_room_tv
          {% endif %}
    - service: media_player.select_source
      data_template:
        entity_id: >
          {% if (states('media_player.bedroom_tv') == 'on') %}
            media_player.bedroom_tv
          {%-elif (states('media_player.living_room_tv') == 'on')  %}
            media_player.living_room_tv
          {% else %}
          
          {% endif %}
        source: 'Netflix'