In order to save myself what little hair I have left I’d like to understand better why something that works in the template editor completely borks when being run as a script.
Using MA’s get_queue action in dev tools I copy the result over to the template editor and can access the object using something like this.
{% set action_response = {"media_player.livingroom_stereo":{"queue_id":"apc... etc" %}
{% set queue_info = action_response['media_player.livingroom_stereo'] %}
{{ queue_info.current_item.stream_title }}
Works like a charm, but if I pass that into a script and try to run it (even just reloading the templates) it borks and throws the error:
Template variable error: 'dict object' has no attribute 'current_item' when rendering '{{ queue_info.current_item.stream_title }}'
Instead I have to use something like this for it to work in a script.
{% set action_response = {"media_player.livingroom_stereo":{"queue_id":"apc... etc" %}
{{ action_response ['media_player.livingroom_stereo'].current_item.stream_title }}
So what’s the difference between how the template editor and the script engine parse this?
The script:
# This works
- action: music_assistant.get_queue
target:
entity_id: media_player.livingroom_stereo
response_variable: queue_info
- event: test_script
event_data:
stream_title: "{{ queue_info['media_player.livingroom_stereo'].current_item.stream_title }}"
- stop: null
# This borks
- action: music_assistant.get_queue
target:
entity_id: media_player.livingroom_stereo
response_variable: queue_info
- variables:
queue_two: "{{ queue_info['media_player.livingroom_stereo'] }}"
- event: test_script
event_data:
stream_title: "{{ queue_two.current_item.stream_title }}"
- stop: null