Idea for Binding: Spotify Connect binding

Hi all,

within the last weeks, I had the idea for a spotify connect binding. This binding should allow for controlling a spotify connect device anywhere in your network (or any device logged in with your account) and it should be independent of the system providing the Spotify connect service (e.g. a Sonos or a Denon receiver).

If have already found a lot of ressources describing the (closed) protocol of how to implement a spotify connect controller: https://github.com/sashahilton00/spotify-connect-resources

There a two interesting libraries that could be useful: the official (but closed-source) library from spotify or an open-source reimplementation in Rust called librespot which is e.g. available for arm systems like RPi. However, the examples are either implemented in Go or in Rust. I do not have any idea of how to use them from Java (ok, there is a Java/Rust bridge using JNA, but I have no experience and no idea of how to use it).

Is here anyone how is familiar with Rust or Go and would help me in supporting the implementation of a Spotify Connect binding?

Useful resources:

2 Likes

I have no clue about Go or Rust, but I love spotify:)

FYI the Rust project uses protobuf to define and marshal data, that part could probably be reused in a java binding (MIT licensed) , but Iā€™m not volunteering :wink:

Funnily enough whilst searching for some background info on Spotify Connect, this thread came up.

One of the more recent project takes the work of librespot and wraps a web server around it with REST API. The project, spotifyd-http, like librespot is also written in Rust.

Iā€™ve been able to setup the spotifyd-http web server in my network (using a Ubuntu VM - Rust didnā€™t seem to play nicely on my RPi2) and written a very rough (lots of hardcoding) OH2 binding which allows control of Spotify Connect devices (PLAY/PAUSE/NEXT/PREV only atm).

Itā€™s not as clean as a fully integrated Spotify Connect implementation in Java but until someone ports librespot to Java (and that person is unlikely to be me!) itā€™s a start.

Once Iā€™ve tidied my code up Iā€™ll push it to github for those interested.

1 Like

Hi Daniel,

spotifyd-http is really new project, I was not aware of yet. However, it looks promising. I am looking forward for your code.

I also found an article about how to create JNIā€™ble C libraries from Rust. I will give it a try within the next days and will report my experience.

Beside this article, the spotcontrol library is now completely available in Go, which might allow to make use of the gobind utility that creates a Java wrapper (originally used for Android applications).

The code is a long way from being as clean and tidy as Iā€™d like as Iā€™m struggling slightly with the concept of Things and their bridges - I donā€™t seem to have gotten my head around the lifecycle and the communication concept.

Having said that, as a proof-of-concept (read: contains bugs and issues), my code does control my Spotify Connect players when running a spotifyd-http server.

Feel free to try and contribute improvements.

Your timing is awesome.

I am getting OpenHab going - want to wrap it together with an Amazon Echo dot for some Jarvis style interaction.
My house is mostly automated already - but until this point it has been driven using Simple Remote.

I do still plan on using Simple remote (most of the time), but also want to be able to start my audio up using just voice.

I have an old Android TV box which simply runs Spotify 24/7 and is connected via both Aux and HDMI to various AV receivers around the house. I can control all of these using OpenHab - so I can create a rule that is driven by the echo to start all of these up - but I am unable to get the actual Spotify stream to start playing on the Spotify Connect.

Iā€™ll be following this project.
All I need is to be able to start a playlist (for now I am happy to hardcode my favourite playlists as items in OpenHab), play, pause, skip and stop.

Looks like you are just about there :slight_smile:

Are you planning to wrap this as an official OpenHab add-on eventually?

Did this ever get anywhere?
For now, as a quick fix, Iā€™ll do the following

  1. Use an old android phone or TV box as a Spotify server
  2. Create hue-emulation items for Each playlist Iā€™d like to be able to start, and the basic action (play, stop, next)
  3. Use tasker or similar on the android device to create tasks for each action
  4. Figure out the best way to pass my action from OpenHAB to tasker (anyone figured out which is the most effective?)
  5. Create a few rules the tell OpenHAB to fire the above requests to tasker and also manage the relevant AV gear
  6. Add the hue-emulation items to my Amazon echo discover devices

Whilst this should be easy enough to set up, it requires multiple working components for the interaction to operate. But we try :slight_smile:

1 Like

Anybody got any updates on this?

I am also looking at this and planning to see if it would be possible to use spotcontrol together with the exec binding. This would in theory at least enable me to launch a playlist on a Spotify Connect enabled device (my receiver). But it remains to be tested.

@bulletprooffool
My setup is echo connected to my amplifier, spotify linked up in the alexa app. Then you can tell her to play your playlist.

So I do not really see the point of making buttons in OH for spotify, however it would be nice to be able to play youtube videos with alexa on my tv. I read that pushbullet and tasker could be used for this, so I assume you can do the same approach for your spotify:)

I have several AV receivers plugged into and an Android TV box that us new repurposed as single Spotify server.
Plugging Alexa in directly is no good as I need the voice to work on the little speaker all the time and would not that voice going out over all 14 speakers!

I have tasker invoking Spotify on the android but now using the http binding as a trigger with auto remote.

I see IFTTT now can trigger events when a new Spotify track plays on the echo. So my idea is to control Alexa as usual, but whenever something plays via Spotify on Alexa, trigger an event that tells the android box to take over the Spotify stream.

In addition, Iā€™ll use the hue binding to trigger the next button on the Spotify server every time I say something like ā€œAlexa, turn track upā€ - with a simple rule on OH that then fire an ever to Automremote to tell tasker to invoke the ā€˜NEXTā€™ button on Spotify.

Slightly clunky - will let you know how I get on.

Wow, thats a big setupā€¦
I have 5 echos, one in each room, where I only have speakers in living room and bathroom, but you have a point it would be nice to have her not stop music if you want to switch lights on for instance. So keep me posted on your progress.

I created a python-based integration to Spotify:

1 Like

There is also a binding:

https://github.com/astenlund74/openhab2-addons/tree/master/addons/binding/org.openhab.binding.spotify

Hey @ChrisA,

I tried the binding you suggested.
The data is comming in correctly and i can see which song is played.

But i cannot control the device (play/pause and volume)
Do you have an idea why this is not posible?

  • Jordo

@Jordo Where did you download the binding? I cannot find it. Can you provide a link?

@loovanloon

I downloaded it from gitHub (user: astenlund74)
The binding is called Spotify player bridge
It was hard to find the download.

https://raw.githubusercontent.com/astenlund74/org.openhab.binding.spotify-binary/master/org.openhab.binding.spotify-2.2.0-SNAPSHOT_20171005.jar

There is an ā€œreadmeā€ om the binding page.

  • Jordi

EDIT:
You have to be spotify premium user to use the binding.

Is someone still using this binding?
It works great now at my openhab, but after an hour i still can control the playback only things like song title and artist will stop updating.

Someone with the same problem?

Jordo

Have the same problem with spotify connect binding. After an hour i still can control everything but the song, artist, album and duration will stop updating.
The binding is really great - can anybody fix this bugs?