I am wondering how to play a playlist in spotify?
I created a script to test it out…
spotifydemo:
alias: 'Spotify Demo'
sequence:
- service: media_player.play_media
data_template:
entity_id: media_player.spotify_master_bedroom
media_content_id: 'spotify:user:spotify:playlist:37i9dQZF1DX4dyzvuaRJ0n'
media_content_type: 'PLAYLIST'
but it doesn’t work. It gives this error…
ERROR (Thread-8) [homeassistant.components.media_player.spotify] media type PLAYLIST is not supported
The documentation need to include more info on how to make use of this component.
2 Likes
wjs
April 22, 2017, 12:19pm
2
I had a bit of a play when testing the component before. It seems like your final line should be:
media_content_type: playlist
Let me know if that works for you!
2 Likes
well, thanks. it works!
I am wondering how to turn on shuffle mode?
1 Like
joaquin
(Joaquín)
April 25, 2017, 3:11am
4
What kind of device you have in media_player.spotify_master_bedroom?
I’m trying to make this work with Chromecast
derdude1893
(Mathias Ha Punkt)
April 25, 2017, 7:36am
6
Thank you for the tip.
Playlist works nicely.
I would like to play a randon playlist of a list of playlists.
Something like here:
This can be adapted to various media_player’s I’m sure. I’m running Logitech Media Server with the official Spotify Plugin plus the Triode protocol handler. That allows me to use Spotify URIs.
The secret sauce is that Jinja templates can return a random item from an array. I got excited when I figured that out.
The script I’m posting also makes an API call to turn on shuffle-by-song so that the playlists are shuffled. Source for that below as well.
Keep in mind that you’ll need to change the …
I tried it this way
For people coming back to this. As of April 2017, the random filter has been broken in HA. You’ll get a random playlist the first time this runs, but subsequent commands load the same randomly-chosen playlist. Reboot HA and you’ll get a new random choice, but you’re stuck with that choice till you reboot.
@7h30n3 discovered that the problem only seemed to occur with lists . So here’s a work-around that I’ve been using to restore randomness:
data_template:
media_content_id: >
…
but could not get it to work.
Does anyone have an idea how to get this to work?
ih8gates
(Scott Reston)
April 25, 2017, 11:25am
7
What’s not working? I use the script posted every morning to wake to a random playlist.
If you’re having issues with playing Spotify URIs, the issue is with the Squeeze server. Make sure you’re logged in to mysqueezebox.com
derdude1893
(Mathias Ha Punkt)
April 25, 2017, 12:55pm
8
I use the new Spotify Connect feature with Panasonic Allplay speakers and an, echo dot. Single Playlists work as described in the first post.
but I tried your your setup like that and it does not start:
spotifydemo:
alias: 'Spotify Demo'
sequence:
- service: media_player.play_media
data_template:
media_content_id: >
{%- set plists = ["spotify:user:spotify:playlist:37i9dQZF1DX55dNU0PWnO5",
"spotify:user:spotify:playlist:37i9dQZF1DWVyfHu8SNQgH",
"spotify:user:spotify:playlist:37i9dQZF1DX9OTdoPfdJpF"
] -%}
{% set pindex = (range(0, (plists | length - 1 ) )|random) -%}
{{ plists[pindex] }}
Error in the log file:
17-04-25 14:48:41 ERROR (Thread-1) [homeassistant.util.yaml] while scanning for the next token
found character ‘%’ that cannot start any token
in “/config/script/spotify_test.yaml”, line 7, column 12
17-04-25 14:48:41 ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: while scanning for the next token
found character ‘%’ that cannot start any token
in “/config/script/spotify_test.yaml”, line 7, column 12
ih8gates
(Scott Reston)
April 25, 2017, 2:05pm
9
You’re skipping some required data for media_player.play_media.
Try this. It worked for me (except I replaced media_content_id with the value from my example)
spotifydemo:
alias: 'Spotify Demo'
sequence:
- service: media_player.play_media
data:
entity_id: media_player.spotify
media_content_type: playlist
data_template:
media_content_id: >
{%- set plists = ["spotify:user:spotify:playlist:37i9dQZF1DX55dNU0PWnO5",
"spotify:user:spotify:playlist:37i9dQZF1DWVyfHu8SNQgH",
"spotify:user:spotify:playlist:37i9dQZF1DX9OTdoPfdJpF"
] -%}
{% set pindex = (range(0, (plists | length - 1 ) )|random) -%}
{{ plists[pindex] }}
3 Likes
derdude1893
(Mathias Ha Punkt)
April 25, 2017, 2:40pm
10
How could I not see that thanks @ih8gates .
Now I just need a shuffle mode like @masterkenobi mentioned .
Want to implement this as well in my alarm clock
ih8gates
(Scott Reston)
April 25, 2017, 2:42pm
11
When testing, I was able to call that script multiple times and it would repeatedly replace the current playlist/queue with a new random one.
derdude1893
(Mathias Ha Punkt)
April 25, 2017, 2:55pm
12
You’re right not enough playlists. Seemed to pic the same playlist 4 times in a row
Still shuffle mode but it seems this one is yet missing as it does not show up in the media_player setup.
ih8gates
(Scott Reston)
April 25, 2017, 3:02pm
13
In the example in my random-playlist thread , I had to use Logitech Media Server’s API to set the shuffle mode.
The only media_player I’ve got configured that supports shuffle appears to be Kodi (kodi_set_shuffle). It’d be great for other platforms to support shuffle in a consistent way.
Please upvote:
Most media players have some ability to set shuffle. Often it’s not just an on/off. For example, Logitech Media Server supports shuffle by song / shuffle by album.
Kodi exposes kodi_set_shuffle, but it’s not documented on the component page .
I propose a standardized “set_shuffle” that will work as-needed per platform (sometimes an on/off, sometimes a specific shuffle mode).
1 Like
frelev
June 14, 2017, 9:10am
14
Is it possible to dynamically list all your spotify playlists?
So as soon you create a playlist in Spotify it appear in HASS as a selection list
1 Like
That would be very useful !!
Peleke
(Frederik Niedernolte)
October 31, 2017, 4:10pm
16
It doesn’t seem to work: Spotify in combination with chromecast
Do you know of any fix?
stalksy
(Stalksy)
June 3, 2018, 3:30pm
18
@ih8gates @derdude1893 @masterkenobi
Should this functionality still work or has it been superceeded?
From the thread I tried three different scripts to get it working as there are different approaches in the thread.
My goal is simply to have a script that will activate a set playlist on a set speaker (Google Mini/Home).
spotify_kids_chart:
alias: Test Kids Charts
sequence:
- service: media_player.play_media
data_template:
entity_id: media_player.study_speaker
media_content_id: 'spotify:user:annadmalone:playlist:15ZfTlrsnSTG3xcjXa1qp9'
media_content_type: 'playlist'
spotify_kids_chart2:
alias: Test Kids Charts2
sequence:
- service: media_player.select_source
data_template:
entity_id: media_player.spotify
source: Study Speaker
# source: media_player.study_speaker
- service: media_player.play_media
data_template:
entity_id: media_player.spotify
media_content_type: playlist
media_content_id: 'spotify:user:annadmalone:playlist:15ZfTlrsnSTG3xcjXa1qp9'
spotify_kids_chart3:
alias: Test Kids Charts3
sequence:
- service: media_player.select_source
data_template:
entity_id: media_player.spotify
source: CC32E753
# source: media_player.study_speaker
- service: media_player.play_media
data_template:
entity_id: media_player.spotify
media_content_type: playlist
media_content_id: 'spotify:user:annadmalone:playlist:15ZfTlrsnSTG3xcjXa1qp9'
1 Like
ih8gates
(Scott Reston)
June 4, 2018, 5:27pm
19
I tested the first one with the services dev tool. Looks like it works fine. What error are you seeing in the logs?
stalksy
(Stalksy)
June 5, 2018, 3:02pm
20
@ih8gates Thanks for your reply. FYI I am not ignoring you but overnight my entire HA stopped working and I am now trying to install on a NUC rather than on a QNAP Container Docker.
When I have finished I will be using my previous config and will repost if there is the same error.
Does anyone have this working? I have tried both approaches without success.