Custom Intents and Music Assistant

I have successfully made custom sentences and intents before. I tried carrying over the successful configurations to creating voice assistant music_assistant.play_media commands and nothing I am doing seems to work. The intents are recognized, but I have a slew of errors about undefined slots. I’ve been battling this for a few days, started with a pretty complex setup and now I’m just trying to successfully execute the simplest command and I am still getting this error. I’m at a loss please help.

  • Core 2024.12.3
  • Supervisor 2024.11.4
  • Operating System 14.0

::: configuration.yaml :::

(was previously using intent_script.yaml with an !include but trying to remove any step that could be causing the errors I’ve just added the intents straight into configuration.yaml)

conversation:

intent_script:
  PlayTrack:
    action:
      - service: music_assistant.play_media
        target:
          entity_id: media_player.satellite1
        data:
          enqueue: play
          media_id: "{{ slots.track }}"
          media_type: track
          radio_mode: true

::: custom_sentences.yaml :::

language: en
intents:
  PlayTrack:
    data:
      - sentences:
          - "Play {track}"
        expansion_rules:
          play: "((play)|(listen to))"
          track: "[the] (track|song)"
        slots:
          track:
            type: string
lists:
  track:
    wildcard: true

::: voice assistant debug :::

stage: done
run:
  pipeline: 01j63nxzvp20gxge71fm3ydd1k
  language: en
  runner_data:
    stt_binary_handler_id: null
    timeout: 300
events:
  - type: run-start
    data:
      pipeline: 01j63nxzvp20gxge71fm3ydd1k
      language: en
      runner_data:
        stt_binary_handler_id: null
        timeout: 300
    timestamp: "2024-12-16T13:25:03.525490+00:00"
  - type: intent-start
    data:
      engine: conversation.home_assistant
      language: en
      intent_input: Play cold cold ground
      conversation_id: null
      device_id: 68d37a8f38f384523fe526cb946b4b8e
      prefer_local_intents: false
    timestamp: "2024-12-16T13:25:03.525583+00:00"
  - type: intent-end
    data:
      processed_locally: true
      intent_output:
        response:
          speech:
            plain:
              speech: An unexpected error occurred
              extra_data: null
          card: {}
          language: en
          response_type: error
          data:
            code: unknown
        conversation_id: null
    timestamp: "2024-12-16T13:25:03.556233+00:00"
  - type: run-end
    data: null
    timestamp: "2024-12-16T13:25:03.556308+00:00"
intent:
  engine: conversation.home_assistant
  language: en
  intent_input: Play cold cold ground
  conversation_id: null
  device_id: 68d37a8f38f384523fe526cb946b4b8e
  prefer_local_intents: false
  done: true
  processed_locally: true
  intent_output:
    response:
      speech:
        plain:
          speech: An unexpected error occurred
          extra_data: null
      card: {}
      language: en
      response_type: error
      data:
        code: unknown
    conversation_id: null

::: logs :::

Logger: homeassistant.helpers.template
Source: helpers/template.py:2746
First occurred: 8:18:53 AM (4 occurrences)
Last logged: 10:27:34 AM

Template variable error: 'slots' is undefined when rendering '{{ slots.track }}'

Logger: homeassistant.helpers.script.intent_script_playtrack
Source: helpers/script.py:2032
First occurred: 8:18:53 AM (4 occurrences)
Last logged: 10:27:34 AM

Intent Script PlayTrack: Error executing script. Error for call_service at pos 1: Error rendering data template: UndefinedError: 'slots' is undefined

Logger: homeassistant.helpers.intent
Source: helpers/intent.py:144
First occurred: 8:18:53 AM (4 occurrences)
Last logged: 10:27:34 AM

Error handling PlayTrack
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 631, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2733, in _render_with_context
    return template.render(**kwargs)
           ~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.13/site-packages/jinja2/sandbox.py", line 327, in getattr
    value = getattr(obj, attribute)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2765, in _fail_with_undefined_error
    return super()._fail_with_undefined_error(*args, **kwargs)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
jinja2.exceptions.UndefinedError: 'slots' is undefined

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 414, in async_prepare_call_from_config
    render = template.render_complex(config[conf], variables)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 248, in render_complex
    render_complex(key, variables, limited, parse_result): render_complex(
                                                           ~~~~~~~~~~~~~~^
        item, variables, limited, parse_result
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 254, in render_complex
    return value.async_render(variables, limited=limited, parse_result=parse_result)
           ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 633, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'slots' is undefined

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/intent.py", line 144, in async_handle
    result = await handler.async_handle(intent)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/intent_script/__init__.py", line 234, in async_handle
    action_res = await action.async_run(slots, intent_obj.context)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1801, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 464, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 528, in _async_step
    self._handle_exception(
    ~~~~~~~~~~~~~~~~~~~~~~^
        ex, continue_on_error, self._log_exceptions or log_exceptions
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 558, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 526, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 735, in _async_call_service_step
    params = service.async_prepare_call_from_config(
        self._hass, self._action, self._variables
    )
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 421, in async_prepare_call_from_config
    raise HomeAssistantError(f"Error rendering data template: {ex}") from ex
homeassistant.exceptions.HomeAssistantError: Error rendering data template: UndefinedError: 'slots' is undefined

Logger: homeassistant.components.conversation.default_agent
Source: components/conversation/default_agent.py:441
integration: Conversation (documentation, issues)
First occurred: 8:18:53 AM (4 occurrences)
Last logged: 10:27:34 AM

Unexpected intent error
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 631, in async_render
    render_result = _render_with_context(self.template, compiled, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2733, in _render_with_context
    return template.render(**kwargs)
           ~~~~~~~~~~~~~~~^^^^^^^^^^
  File "/usr/local/lib/python3.13/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/usr/local/lib/python3.13/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "<template>", line 1, in top-level template code
  File "/usr/local/lib/python3.13/site-packages/jinja2/sandbox.py", line 327, in getattr
    value = getattr(obj, attribute)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 2765, in _fail_with_undefined_error
    return super()._fail_with_undefined_error(*args, **kwargs)
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
jinja2.exceptions.UndefinedError: 'slots' is undefined

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 414, in async_prepare_call_from_config
    render = template.render_complex(config[conf], variables)
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 248, in render_complex
    render_complex(key, variables, limited, parse_result): render_complex(
                                                           ~~~~~~~~~~~~~~^
        item, variables, limited, parse_result
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 254, in render_complex
    return value.async_render(variables, limited=limited, parse_result=parse_result)
           ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/template.py", line 633, in async_render
    raise TemplateError(err) from err
homeassistant.exceptions.TemplateError: UndefinedError: 'slots' is undefined

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/intent.py", line 144, in async_handle
    result = await handler.async_handle(intent)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/intent_script/__init__.py", line 234, in async_handle
    action_res = await action.async_run(slots, intent_obj.context)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1801, in async_run
    return await asyncio.shield(create_eager_task(run.async_run()))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 464, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 528, in _async_step
    self._handle_exception(
    ~~~~~~~~~~~~~~~~~~~~~~^
        ex, continue_on_error, self._log_exceptions or log_exceptions
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 558, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 526, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 735, in _async_call_service_step
    params = service.async_prepare_call_from_config(
        self._hass, self._action, self._variables
    )
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 421, in async_prepare_call_from_config
    raise HomeAssistantError(f"Error rendering data template: {ex}") from ex
homeassistant.exceptions.HomeAssistantError: Error rendering data template: UndefinedError: 'slots' is undefined

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/conversation/default_agent.py", line 441, in _async_process_intent_result
    intent_response = await intent.async_handle(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<10 lines>...
    )
    ^
  File "/usr/src/homeassistant/homeassistant/helpers/intent.py", line 152, in async_handle
    raise IntentUnexpectedError(f"Error handling {intent_type}") from err
homeassistant.helpers.intent.IntentUnexpectedError: Error handling PlayTrack

If I run the same music_assistant.play_media action in the developer section it executes every time. I’ve tried lots of different variations to see if I can figure out where the trouble is coming from, but it seems like no matter what I do, I cant get the intent to pull in the slots data. I am really at a loss as to where the issue is. Any help would be greatly appreciated.

Added some lines and seem to have resolved the undefined slots error:

intent_script:
  PlayTrack:
    sequence:
      - variables:
        media_id: "{{ slots.track | default('unknown') }}"
      - action: music_assistant.play_media
        target:
          entity_id: media_player.satellite1
        data:
          enqueue: replace
          media_id: "{{ media_id }}"
          media_type: track
          radio_mode: true

Used variables to pull in the slot info before passing it to the media_play. This removed the errors, but now not passing the data from variables to music assistant service.

Also switched from calling music_assistant.play_media as a service to an action. Neither are giving the correct result.