I’m using Home Assistant to automate some physical buttons for my Squeezebox media player. I’ve already managed to get this to do volume up/down, pause/play, and skip track. What I want to do now is add an integration for playing a random playlist. Right now, the playlist should be selected from a hard-coded list, but I might later want to make this more sophisticated.
Here is the configuration I’ve written so far:
- id: 'random_playlist'
alias: Random Playlist
description: ''
trigger:
- platform: device
domain: mqtt
device_id: 784b3416e4c5591014c6dcd037215b17
type: action
subtype: top_left_hold
discovery_id: 0x000d6f000fe48b8e action_top_left_hold
condition: []
action:
- service: squeezebox.call_method
data:
command: playlist
parameters:
- play
- >-
{% set chosen = [
'spotify:playlist:37i9dQZF1DXa8axQnFlj0R', # sweater weather
'spotify:playlist:37i9dQZF1DX91oIci4su1D', # trance mission
'spotify:playlist:37i9dQZF1DWSQScAbo5nGF', # indie road trip
'spotify:playlist:37i9dQZEVXcK41NOc1uUJ9', # discover weekly
'spotify:playlist:37i9dQZF1DX76Wlfdnj7AP' # beast mode
] | random %}
{{ chosen }}
target:
entity_id: media_player.cube
But right now this gives this error:
2023-12-18 19:50:54.285 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: template value should be a string for dictionary value @ data['action'][0]['data']. Got None. (See /config/configuration.yaml, line 2).
I also tried this without using the set
step first, and using >
instead of >-
:
parameters:
- play
- >
{{ [
'spotify:playlist:37i9dQZF1DXa8axQnFlj0R', # sweater weather
'spotify:playlist:37i9dQZF1DX91oIci4su1D', # trance mission
'spotify:playlist:37i9dQZF1DWSQScAbo5nGF', # indie road trip
'spotify:playlist:37i9dQZEVXcK41NOc1uUJ9', # discover weekly
'spotify:playlist:37i9dQZF1DX76Wlfdnj7AP' # beast mode
] | random }}
But it gives the same error.
I think it must be to do with the way that I’m trying to use the jinja template to get an item and put it into the yaml list with that >-
operator. I can’t seem to find any documentation on >
and >-
and how they work with jinja/yaml/HA in this context. Can anybody help me with this?
Thanks,
Peter