Entity_id based on input select

I am trying to create a script that will tell Plex to play said movies to the plex player chosen in an input select. This is what I have but it gets errors in configuration. I am probably way off on what I need to do so any help is greatly appreciated. Here is my current test script:

play_backtothefuture:
  alias: Back to the Future
  sequence:
    - service: media_player.play_media
      data_template:
        entity_id: >
          {% if is state ("input_select.plex_player", "Shield LR") %}
            media_player.shield_lr
          {% if is state ("input_select.plex_player", "Ryder's Roku") %}
            media_player.roku_3__1gn39u202172
          {% else %}
          {% endif %}
      data:
        media_content_type: VIDEO
        media_content_id: "{ \"library_name\": \"Movies\", \"video_name\": \"Back to the Future\", \"shuffle\" : \"0\" }"
1 Like

There’s one thing to change, the ‘is state’ should be ‘is_state’, the space probably not a good idea in that spot either.

So like this.

{% if is_state("input_select.plex_player", "Shield LR") %}

1 Like

Thanks @Bit-River. Underscore got me. I also put if instead of elif on second condition. guess that means I need to take a break for a little bit. Removed space there as well just to be sure and it’s working.

1 Like

Cool, I know that code-blindness feeling.

ok, now that that is working, I am trying to pass variables to the plex media_content_id string. It does not like this line:

media_content_id: "{ \"library_name\": {{ library }}, \"video_name\": {{ movie }}, \"shuffle\" : \"0\" }"

It expects property name enclosed in double quotes. So how can I encapsulate those variables correctly? If I do “{{ library }” it just sees the whole thing as a string not a variable. Any ideas?

@salphonso

Try this:

media_content_id: "{ \"library_name\": \"{{ library }}\", \"video_name\": \"{{ movie }}\", \"shuffle\" : \"0\" }"

1 Like

Thanks @Jer78. It looks like that did it. Now to figure out if I can pass a script arguments through HA dashboard.