Dificulty outputing to media_player - works with one script but not another

Hi Guys. very new to home assistant and learning on the fly/through posts on this community at the moment so apologies if this turns out to be something simple.

So my current project is to be able to display my ip cameras on a chromecast device and on a google home hub, ultimately using voice control. (FYI i have google assistant configured and linked through home assistant cloud)

As i am using BlueIris for my camera’s i thought a good place to start would be this thread here: Google Cast BlueIris Cameras with Home Assistant!

Having followed sebdoan excellent writeup i was able to mod the provided code to my specific requirements and ended up with the following script that works perfectly and both cameras can be displayed on both devices:

input_select:
  camera_dropdown:
    name: Cast camera
    options:
      - CAM2
      - CAM2
    initial: CAM2
    icon: mdi:camera
  cast_to_screen_dropdown:
    name: To Screen
    options:
      - Kitchen Display
      - Lounge TV
    initial: Kitchen Display
    icon: mdi:cast

script:
  execute_cast_dropdown:
    alias: Press to execute
    sequence:
      - service: media_player.play_media
        data_template:
          entity_id: >
            {% if is_state("input_select.cast_to_screen_dropdown", "Kitchen Display") %}
              media_player.kitchen_display
            {% elif is_state("input_select.cast_to_screen_dropdown", "Lounge TV") %}
              media_player.lounge_tv
            {% endif %}
          media_content_id: >
            {% if is_state("input_select.camera_dropdown", "CAM1") %}
              http://x.x.x.x:81/mjpg/CAM1/video.mjpeg
            {% elif is_state("input_select.camera_dropdown", "CAM2") %}
              http://x.x.x.x:81/mjpg/CAM2/video.mjpeg
            {% endif %}
          media_content_type: 'image/jpg'

group:
  Cast_Cameras_Group:
    name: Cast Camera to Screen
    view: no
    entities:
     - input_select.camera_dropdown
     - input_select.cast_to_screen_dropdown
     - script.execute_cast_dropdown  

now as i want to be able to use voice control i thought for a ‘proof of concept’ i would use a script that specifies one camera and one device to output, so again from the thread above i modified code suggested in one of the posts and have the following script:

script:
  cast_to_smartdisplay:
    alias: Send CAM1 to Kitchen Display
    sequence:
      - service: media_player.play_media
        data:
          entity_id: media_player.kitchen_display
          media_content_id: http://x.x.x.x:81/mjpg/CAM1/video.mjpeg
          media_content_type: 'image/jpg'

now when i execute this script, it runs but the screen on the kitchen display just goes black?

as far as i can tell i am essentially performing the same action as the original script, the only difference being i am explicitly specifying the input and output in the script rather than selecting from drop downs before it is executed, so i do not understand why i don’t get the image using the above but it worked in my original scipt.

Any help would be much appreciated!

Thanks

Mine sometimes shows just a black screen too (maybe one in 10 attempts) . I reissue the voice command a 2nd time and the image appears.

that’s interesting, i’ll try reissuing the execute a few times and see if it displays. its odd though that it is fine using the first script though.

are you using voice commands with the script you shared in your project writeup? if so i’d be interested in how you set that up to set the variables using voice commands