Could someone who knows a lot help me with the syntax of a code?

first thanks for the help

i want to use the template in a script.

this template is ok

- platform: template
  sensors:
    tv_to_use:
      value_template: >
        {% if is_state("sensor.last_alexa", "media_player.echo_our_bedroom") %}
          tv_our_bedroom
        {% else %}
          tv_living_room
        {% endif %}    

but this script is not working

scr_tv_youtube:
  alias: scr_ TV -YOUTUBE
  sequence:
  - script.prepare_env_and_power_on_{{ states('sensor.tv_to_use') }}
  - service: media_player.play_media
    data_template:
      entity_id: media_player.{{ states('sensor.tv_to_use') }}
      media_content_id: 111299001912
      media_content_type: app

the script call prepare_env_and_power_on… and the media_player call above is not working.

what do i have to change to work???

thank you

  sequence:
  - service: script.prepare_env_and_power_on_{{ states('sensor.tv_to_use') }}
2 Likes

Thank you, stupid error

But and the sintax in this line ???

      entity_id: media_player.{{ states('sensor.tv_to_use') }}

Data_template should be data, and the line in question needs double quotes around the value of the entity_id key (before the M of media player and after the last } ).

1 Like

I tested it again and the code containing a call from media_player.play_media was right, the problem was simply an earlier call in another script that was not connected to a tv.
Thanks for the help.

Thanks for the help.
I tested it again and the code containing a call from media_player.play_media was right, the problem was simply an earlier call in another script that was not connected to a tv.