Play spotify playlist through local MPD instance

Hello,
i am trying to control the local MPD instance with home assistant to play a spotify playlist. This is what i tried:
image
I can start the playback using Mopidy and Moped, so spotify login works and playback works too.

Then i tried to do this to play a stream:

{
“entity_id”: “media_player.mpd”,
“media_content_type”: “audio/mp4”,
“media_content_id”: “http://stream.100p.nl/100pctnl.mp3”
}

Not working eighther.

My config to include MPD looks like this:

media_player:

platform: mpd
host: 192.168.0.18
port: 6600

And the Widget on the startpage shows the current playback triggered by moped:

image

So it seems to have found the MPD instance. But i can not control it with the servicecall. What am i missing to call?

Greetings

Does realy no one have a clue of what to do here? I just want to mimic what other apps like “moped” proved to be possible, but can not figure out how to do it. Please help me.

Okay found a workaround using mopidy and a Service.
Add the following in the configuration.yaml:

rest_command:
play_lounge:
url: “http://192.168.0.18:6680/mopidy/rpc
method: “POST”
payload: ‘[{“jsonrpc”:“2.0”,“id”:1,“method”:“core.tracklist.clear”},{“jsonrpc”:“2.0”,“id”:2,“method”:“core.tracklist.add”,“params”:{“uri”:“spotify:user:ABC:playlist:DEF”}},{“jsonrpc”:“2.0”,“method”:“core.playback.play”,“id”:3}]’

That sends a batch RPC to mopidy, which does the following to MPD:

  1. clear current tracklist
  2. add tracks from given spotify user and playlist
  3. starts the playback

Needs mopidy addon installed and configured with premium spotify account. Can then be used as service “rest_command.play_lounge” in hass.io

1 Like

This is exactly what i want. But through HAdashboard. I found out it got an input_select option. but it needs to load
{{states.media_player.mpd.attributes.source_list}} . I will look into your option.

If you go to services you can directly start a specific mpd (spotify)playlists. I want to use this to start a playlist in HAdashboard.

1 Like

Found it!
Thanks gcosta74!

1 Like

Nice finding, thanks for sharing! :slight_smile:
Will try that too, looks good! Could you please share your .conf code on how you use it with spotify playlists?
Will also try to use “Music from Sing (by singmovie)” in a Service as source, i always thought you need to use those cryptic playlist IDs. Did you do more than adding the spotify user and those IDs to make that work?

Thanks!

This is a playlist in spotify. It’s the movie soundtrack from Sing :wink:
You don’t need to use this if you use the github widgets from gcosta74. You can forget my first post.

Do you have mopidy (MPD) running? If you add this to home assistant the source attribute contains all the playlists from MPD (if you add mopidy-spotify to MPD you have a connection to spotify and the spotify playlists) https://github.com/mopidy/mopidy-spotify

2 Likes

Good point again! I was wondering for some “show your projects” Topics how they controlled spotify so easily. But i am one of those nooby hass.io users, so my options to install are very limited. Do you use the full home assistant, or did you manage to add mopidy-spotify to hass.io?

I have 2 rasp pi3.
1 with HASSIO
2 OSMC (kodi) with running mopidy and appdaemon hadashboard ( in docker)

Hi there, did you ever work this out? I’m in an identical situation, everything works fine i just seem to work out how to use this add-on without manually using the web ui!

Hi,
yes i did! But maybe it is not the best solution.
I Control music now by MQTT, the remotedy app and by that app-deamon interface on a tablet.

It works as following:
mopidy installed on hass.io has spotify credentials in the config. This alone allows the remotedy app to start spotify playlists. We use that app mainly for skipping a song or pausing the music with no other options in reach.

Then there is the complicated part using the REST API of Mopidy. Will post that later if i don’t forget.
I have a script for each playlist to play. That Script uses the REST_COMMAND Service to send which playlist of spotify to play to Mopidy.
This Script now now triggered by app-deamon on a tablet (they have a widget for that) or by an automation, which is triggered by MQTT.

The REST Command of Mopidy is somewhere in their docs under “RPC”, and is very poorly documented in my opinion. Will post my approach when i come home.

Hello,

So it is not possible to start spotify playlist from HA?

Play spotify:
alias: Spotify
sequence:
- service: media_player.play_media
data:
entity_id: media_player.mpd
media_content_type: playlist
media_content_id: spotify:user:xxx:playlist:xxxx

This is not working

Spotify killed the interface mopidy was using. No more spotify from raspberry pi.