Why is the response_variable of this script is not returning any data?

I have this script that uses a response_variable to return information to a conversation agent. When the CA is executing the script it says that the requested information is not available. Looking at the traces the response_variable only contains this:

stop: null
error: false

but no further data. But input_text.now_playing contains the expected data.

This is the script:

now_playing_on_ma:
  alias: "Get Now Playing Track Name from MA"
  description: 'This script is used to get the current playing song in Music Assistant based on a voice request.
    The tool requires no arguments. Use this tool whenever the user requests title or song information for
    the currently plying title on music assistant.' 
  mode: queued
  sequence:
    - action: music_assistant.get_queue
      data:
        entity_id: media_player.receiver
      response_variable: queue_info

    - service: input_text.set_value
      data:
        entity_id: input_text.now_playing
        value: '{{ queue_info["media_player.receiver"].current_item.name[:50] }}'

    - variables:
        response: |
          {% set nowplaying =  states("input_text.now_playing") %}
          {{ {"title": nowplaying} }}

    - stop:
      response_variable: response

I’ve never used this, but the example in the docs is:

- set_conversation_response: "{{ 'Testing ' + my_var }}":

Thanks Jack, unfortunately this does not work for me. The CA is executing the script and input_text.now_playing is set correctly but still the CA answer is wrong.

OK, I have simplified my script to a minimum but still no success:

now_playing_on_ma:
  alias: "Get Now Playing Track Name from MA"
  description: 'This script is used to get the current playing song in Music Assistant based on a voice request.
    The tool requires no arguments. Use this tool whenever the user requests title or song information for
    the currently playing title on music assistant.' 
  mode: queued
  sequence:
    - variables:
        response: |
          '{"title": "Song from Band"}'
    - stop: ''
      response_variable: response

Dunno why your previous attempts failed, but the last one is obvious – a response variable must always contain a dict / mapping while you are passing a string.

The “minimum” to test with would be this:

- variables:
    response:
      title: Song from Band
- stop:
  response_variable: response

Thank you. I fixed this but it does not help. I’m also using a script generated from a blueprint that returns weather data from @TheFes (ha-blueprints/weather/3_voice_weather_forecast_full_llm.yaml at cde211ae44bf37877e5eea8ac7dfcbc671dcac13 · TheFes/ha-blueprints · GitHub)
This uses the same mechanism to return the data and it works. I cannot find out why.

Just figured out that my script works when it does not use the queued mode. So this seems to be a bug in HA core.

1 Like

I opened a bug report for this issue: Scripts running in queued mode do not return response_variable data · Issue #137298 · home-assistant/core