Accessing template variables in a script

Beginner to scripts and templates needing advice

{% set SqueezePlayLists = { 'Dinner':'dplstaticpl_PGPBtJ1Dd6Co5RDdrt9%2F%2FJKp1d8',
                     'Karen':'dplstaticpl_xXMhdJQR%2FUp59ZgBx%2Bj4ypsz55k',
                     'Speaker-Test':'dplstaticpl_maRsj0ELIYXNTbXiYejkTvghpek',
                     'RockSteady':'dplccustom_rocksteady',
                     'Guitars':'dplccustom_guitars',
                     'long_songs':'dplccustom_long_songs',
                     'my_jazz':'dplccustom_my_jazz'} %}

{% set Item = SqueezePlayLists[ states('input_select.lmsplaylist_select') ] %}

{{ Item }}

The above works correctly when I test it in the Developer Tools Template editor
but when i insert it into a script as below no matter how I enter Item in the code it is passed across as Item rather than the value of Item

lms_dynamic_play:
  alias: Lms Dynamic
  mode: single
  icon: mdi:music

  sequence:
  - service: squeezebox.call_method
      {% set SqueezePlayLists = { 'Dinner':'dplstaticpl_PGPBtJ1Dd6Co5RDdrt9%2F%2FJKp1d8',
                     'Karen':'dplstaticpl_xXMhdJQR%2FUp59ZgBx%2Bj4ypsz55k',
                     'Speaker-Test':'dplstaticpl_maRsj0ELIYXNTbXiYejkTvghpek',
                     'RockSteady':'dplccustom_rocksteady',
                     'Guitars':'dplccustom_guitars',
                     'long_songs':'dplccustom_long_songs',
                     'my_jazz':'dplccustom_my_jazz'} %}

      {% set Item = SqueezePlayLists[ states('input_select.lmsplaylist_select') ] %}

    data:
      command: dynamicplaylist
      parameters:
      - playlist
      - play
      - 'Item'  # I've tried {{ Item }, "Item", "{{ Item }}" etc etc
    target:
      entity_id: media_player.{{ states('input_select.lms_instance') }}

If anybody could explain what I am doing wrong I’d be very grateful

The Template editor does not understand YAML. So your templates are correct from a purely Jinja standpoint, but the YAML is invalid. Jinja templates can only be used to provide the value for a YAML key/value pair. Whenever you work with variables you also need to be careful of scoping issues.

lms_dynamic_play:
  alias: Lms Dynamic
  mode: single
  icon: mdi:music
  sequence:
    - variables:
        SqueezePlayLists:
          Dinner: 'dplstaticpl_PGPBtJ1Dd6Co5RDdrt9%2F%2FJKp1d8'
          Karen: 'dplstaticpl_xXMhdJQR%2FUp59ZgBx%2Bj4ypsz55k'
          Speaker-Test: 'dplstaticpl_maRsj0ELIYXNTbXiYejkTvghpek'
          RockSteady: 'dplccustom_rocksteady'
          Guitars: 'dplccustom_guitars'
          long_songs: 'dplccustom_long_songs'
          my_jazz: 'dplccustom_my_jazz'
        item: "{{ SqueezePlayLists[ states('input_select.lmsplaylist_select') ]  }}"
    - service: squeezebox.call_method
      data:
        command: dynamicplaylist
        parameters: "{{ ['playlist', 'play', item] }}"
      target:
        entity_id: media_player.{{ states('input_select.lms_instance') }}

* I don’t use squeezebox, so the parameter template may need some adjustment…

thanks for that it didnt work at first until I changed the parameters block to

    data:
      command: dynamicplaylist
      # parameters: "{{ ['playlist', 'play', item] }}"
      parameters:
      - playlist
      - play
      - "{{ Item }}"
    target:
      entity_id: media_player.{{ states('input_select.lms_instance') }}

before that it was still getting passed as the string Item rather than the value of Item

is there any easy method of degugging scripts to show the value of variables etc

once again thanks for your help

If you run a script manually it will create a debug trace. The trace will contain the values of any YAML variables.