Script variable for media player chrome casting youtube

Tags: #<Tag:0x00007fc3eb8edc60> #<Tag:0x00007fc3eb8edb48> #<Tag:0x00007fc3eb8eda80>

I am able to have the script with constant id and cast it to my chromecast. I am trying to improve the script to take a parameterized youtube url. This script will be called from automation reading value from textbox. I am not sure how to get it work with templated variable.

My script

alias: Chromecast
fields:
  youtube_id:
      description: Id of the youtube video.
      example: "QKae1k1BDdA"
sequence:
  - target:
      entity_id: media_player.chromecast
    data:
      media_content_type: cast
      media_content_id: '{ "app_name": "youtube", "media_id": "{{youtube_id}}" }'
    service: media_player.play_media
mode: single

I think you need to use media_extractor service.

The above script worked fine, the problem I had is with arguments, where I passed a list when string is expected. Fixing that work perfect.

Media player works for chromecast TV
Media extractor works for Google home mini.