#YAML help needed for intent_script: 'media_player' is undefined when rendering '{{ media_player }}'

1 messages · Page 1 of 1 (latest)

shrewd gorge
#

I'm trying to build a custom intent file to control my music. I've followed the guide at https://www.home-assistant.io/voice_control/custom_sentences_yaml/ but I keep getting errors. Been trying for several hours to find the issue but no success.

Hope a fresh set of eyes help:
configuration.yaml:
intent_script: SpotifyPlaylist: speech: text: Okay, ik speel de playlist af in de {{ media_player }}. action: - action: spotcast.start data: force_playback: false random_song: true repeat: "off" shuffle: true offset: 0 start_position: 0 ignore_fully_played: false entity_id: "{{ media_player }}" uri: "{{ playlist_id }}"

custom_sentences/nl/media.yaml:
# Example config/custom_sentences/en/media.yaml language: "nl" intents: SpotifyPlaylist: data: - sentences: - "(Speel|start) [de] (playlist|afspeellijst) {playlist_id} [maar] [af] (in|op) de {media_player}" lists: media_player: values: - in: "slaapkamer" out: "media_player.bedroom" - in: "kinderkamer" out: "media_player.lenn" [..] - in: "deurbel" out: "media_player.g4_doorbell_speaker" playlist_id: values: - in: "len[n][s] favoriet[en]" out: "spotify:playlist:5AP6JNb6Z2dSAkeeJP768d" - in: "lenn" out: "spotify:playlist:54MxfdxhOGO2WEKt2LCF7z" - in: "milenco" out: "spotify:playlist:29aiPfdrGUh6TDEjvsJV3r" - in: "kerst" out: "spotify:playlist:37i9dQZF1DX4dopZ9vOp1t" - in: "top 2000" out: "spotify:playlist:1DTzz7Nh2rJBnyFbjsH1Mh"

The error I'm getting:
Template variable warning: 'media_player' is undefined when rendering '{{ media_player }}'

Home Assistant

Open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server.

covert rose
#

Have you looked into Music Assistant at all?

#

There's a repository there for voice control of music 🙂

#

But to answe directly the question about media_player not rendering, you would be better off utilizing slots and domains to automatically target applicable media devices

#

For example, here's a custom sentence I have to handle muting media players:

language: "en"
intents:
  MediaPlayerControl_ClearPlaylist:
    data:
      - sentences:
          - "Clear playlist on <name>"
        requires_context:
          domain: "media_player"
      - sentences:
          - "Clear playlist"
        requires_context:
          area:
            slot: true
#

so <name> will automatically populate a name slot with the name of the media player, since it is locked to the media_player domain. So it will trigger on any media player entity

shrewd gorge
#

Thanks Nick, I've been doing quite some Google searches today but havent found that one, found two other repos

covert rose
#

For what you are trying to do, Music Assistant may simplify things a bit

shrewd gorge
#

Using domains, can I then using the Assist aliases I set on entities/devices?

covert rose
#

using the above sentence I made, here's the script that takes that name and maps it to the entity:

description: "Used to clear the playlist on a media player. Takes either the argument 'name' which is the media player to clear the playlist on, or area which is the area the request is made from."
action:
  - service: media_player.clear_playlist
    target:
      entity_id: >-
        {%- if area %}
        {{ states.media_player | selectattr('entity_id', 'in', area_entities(area)) | selectattr('entity_id', 'in', integration_entities('music_assistant')) | map(attribute='entity_id') | join(', ') }}
        {%- else %}
        {{ states.media_player | selectattr('name', 'match', name) | selectattr('entity_id', 'in', integration_entities('music_assistant')) | map(attribute='entity_id') | list | first | default }}
        {%- endif %}
speech:
  text: >-
    Playlist cleared 
    {% if name -%}
    on {{name}}
    {%- endif -%}
    .
#

Yes, it will consider friendly names and aliases

#

when using intent scripts/custom sentences

shrewd gorge
#

Hmm okay, thanks again

#

That might work instead of this. I was hoping for a simple thing I've missed since I've been trying for 7 hours 😄