I have been searching the forum & Google for hours and hours, but just can’t get it to work…
Background:
I am playing around with the Spotify API, because I would like to be able to use Assist to search for an Artist/Playlist and then send the URI to my Sonos speaker.
Here is where I am stuck:
I have created a command_line sensor that calls the Spotify API (with a fixes search string for now, one step after another):
- sensor:
name: ES Spotify URI
scan_interval: 300000
command: curl -X GET "https://api.spotify.com/v1/search?q=this+is+Jack+Jonson&type=playlist&limit=1&market=de" -H "Authorization:Bearer {{states('sensor.es_spotify_token')}}"
unique_id: es_spotify_uri
value_template: >
{{ value_json.playlists.items[0].uri }}
This is the response of CURL when calling it from commad line
{
"playlists" : {
"href" : "https://api.spotify.com/v1/search?query=this+is+Jack+Jonson&type=playlist&market=DE&offset=0&limit=1",
"items" : [ {
"collaborative" : false,
"description" : "This is Jack Johnson. The essential tracks, all in one playlist.",
"external_urls" : {
"spotify" : "https://open.spotify.com/playlist/37i9dQZF1DZ06evO294Tcc"
},
"href" : "https://api.spotify.com/v1/playlists/37i9dQZF1DZ06evO294Tcc",
"id" : "37i9dQZF1DZ06evO294Tcc",
"images" : [ {
"height" : null,
"url" : "https://thisis-images.spotifycdn.com/37i9dQZF1DZ06evO294Tcc-large.jpg",
"width" : null
} ],
"name" : "This Is Jack Johnson",
"owner" : {
"display_name" : "Spotify",
"external_urls" : {
"spotify" : "https://open.spotify.com/user/spotify"
},
"href" : "https://api.spotify.com/v1/users/spotify",
"id" : "spotify",
"type" : "user",
"uri" : "spotify:user:spotify"
},
"primary_color" : null,
"public" : null,
"snapshot_id" : "MjgzOTc1MTEsMDAwMDAwMDBkOTRkMTIwYzM4NDEzZjY1YThlYzhkNTBlNGZlNzQ4NA==",
"tracks" : {
"href" : "https://api.spotify.com/v1/playlists/37i9dQZF1DZ06evO294Tcc/tracks",
"total" : 48
},
"type" : "playlist",
"uri" : "spotify:playlist:37i9dQZF1DZ06evO294Tcc"
} ],
"limit" : 1,
"next" : "https://api.spotify.com/v1/search?query=this+is+Jack+Jonson&type=playlist&market=DE&offset=1&limit=1",
"offset" : 0,
"previous" : null,
"total" : 600
}
What I would like to extract is this (8th row from the bottom):
spotify:playlist:37i9dQZF1DZ06evO294Tcc
But unfortunatly, with the value_template above the sensors value is “unknown”.
Any ideas how too change the template to extract the URI?