I am trying to integrate a script from Jeffery Stone (https://www.youtube.com/watch?v=ey8MoQUDsRM) on gathering all media players from a script. My script is as follows:
alias: get_room_services_single
sequence:
- variables:
room_services: |-
{% set jarvis_speaker = states.media_player |
selectattr('entity_id', 'in', area_entities(room)) |
rejectattr('attributes.last_called', 'undefined') |
map(attribute='entity_id') |
list | first %}
{"jarvis_speaker":"{{jarvis_speaker}}"}
- stop: ok, Im done.
response_variable: room_services
mode: single
If I go to Developer tools and run the script, it returns just fine.
However, when I try to call this from a test automation, it states that it fails becuase template value should be a string for dictionary value @ data[‘message’]
alias: Test Automation with Variables
description: ""
trigger:
- platform: state
entity_id:
- input_boolean.test_helper
to: "on"
condition: []
action:
- service: script.get_room_services_single
data: {}
response_variable: room_services
- service: notify.alexa_media
data:
message: This is a test
target: {{ room_services.jarvis_speaker }}
enabled: true
mode: single
I’m obviously missing something very simple here. My guess is I’m not addressing the directory value correctly but I can’t figure out what exactly to use. The script is setting the return value to jarvis_speaker isn’t it?