I have a script, which has variables. But when I call a service in the script, using a variable as parameter in the data block, an empty string is passed instead of the actual content of the variable. This happens now on the media_player.play_media
service where I try to pass the contents of a variable as media_content_id
; But I encountered this before in another script where i call the denon_avr.get_command
.
Am I missing something? As this looks to me as quite basic functionality, and nothing in the docs Iāve read seem to indicate otherwise.
In the current script, which takes a variable station
as text inputfield, I define a variable stations_map
:
internet_radio_chooser:
alias: Start Internet Radio station on current Internet Radio target
variables:
stations_map:
Willy:
marantz:
category: 3
station: 0
radiobrower_id: "07b53b92-2892-4996-8e60-d3a626c46cb4"
Willy Class X:
marantz:
category: 3
station: 1
radiobrowser_id: "7bd23fe4-3173-4cd5-a548-fe0be1495342"
Studio Brussel:
marantz:
category: 3
station: 2
radiobrowser_id: "a392fb2c-fff2-47ad-8492-4a8491ba129e"
Studio Brussel Bruut:
marantz:
category: 3
station: 3
radiobrowser_id: "21b70fdc-d2b1-49e2-9afd-7883fd2d0e03"
Then depending on the selected target for the internet radio station, I execute the right service with the right parameters from the stations_map
variable:
When the target is set to āWoonkamerā I execute another script to tune the Marantz amp in that room to the selected station:
sequence:
- alias: Choose target specific actions
choose:
- conditions:
- condition: state
entity_id: input_select.internet_radio_target
state: Woonkamer
sequence:
- alias: Tune station on Marantz Main zone
service: script.marantz_iradio_my_station_chooser
data:
entity: media_player.marantz_sr5008_zone_1
category_index: "{{ stations_map[station].marantz.category }}"
station_index: "{{ stations_map[station].marantz.station }}"
Which works perfectly. The stations_map[station].marantz.category
and .station
values are succesfully passed to the script and everything works as expected.
However, for a Sonos speaker in room āBadkamerā, I want to call the radiobrowser media_player.play_media
service:
- conditions:
- condition: state
entity_id: input_select.internet_radio_target
state: Badkamer
sequence:
- alias: Start Radio Browser source for station
service: media_player.play_media
data:
media_content_id: media-source://radio_browser/{{ stations_map[station].radiobrowser_id }}
media_content_type: audio/mpeg
entity_id: media_player.badkamer
And this does not work. According to the script trace, {{ stations_map[station].radiobrowser_id }}
resolves in an empty string :
Result:
params:
domain: media_player
service: play_media
service_data:
media_content_id: media-source://radio_browser/
media_content_type: audio/mpeg
entity_id:
- media_player.badkamer
target:
entity_id:
- media_player.badkamer
running_script: false
Also calling it with only the variable:
media_content_id: "{{ stations_map[station].radiobrowser_id }}"
trace tells me it is empty:
Result:
params:
domain: media_player
service: play_media
service_data:
media_content_id: ''
media_content_type: audio/mpeg
entity_id:
- media_player.badkamer
target:
entity_id:
- media_player.badkamer
running_script: false
I donāt understand? Why does it work when calling a script, and not when calling another service? While I understand from the documentation that this should perfectly work ?