Script with field for entity_id

I’m trying to create a script using a field that allows me to select a media player. This is the code that I wrote:

alias: Prepare speaker
sequence:
  - choose:
      - conditions:
          - condition: state
            entity_id: "{{ player }}"
            state: "off"
        sequence: []
    default: []
mode: single
icon: mdi:cast-audio
fields:
  player:
    selector:
      entity:
        filter:
          integration: cast
    name: Player
    required: true
    default: media_player.nesthubab4d

Home assistant is giving me this errror:

Message malformed: Entity {{ player }} is neither a valid entity ID nor a valid UUID for dictionary value @ data['sequence'][0]['choose'][0]['conditions'][0]['entity_id']

What am I doing wrong?

You cannot use templates in a State condition, use a Template condition instead.

- condition: template
  value_template: "{{ is_state(player, 'off') }}"
2 Likes