openHAB integration to Spotify Web Connect API (player)

Can anyone help?

I don’t know how to help you with the python script, but you could try the binding mentioned in the post above😊

1 Like

Hi,

Thanks. I haven’t seen this but I will give it a try. Thank you

I was able to get all the way through this set up but i am like the others and can’t figure out how to get this running through habpanel. Anyone have any idea?

I cannot for the life of me figure out where to add the client_id and secret_id. Can someone point me in the right direction?

I’ve spent probably upwards of 20 hours trying to figure this out. I’m willing to do the work to learn how to do all of this stuff…but it’s incredibly difficult for me to find the right reading/learning materials for anything beyond the wiki documentation. So if anyone has suggestions for the best way to learn, going forward, i’m totally open to that too.
Thanks!

Thanks

Did you try installing the Spotify Binding? It’s available in the Eclipse Market Place? I don’t know if someone already ported the widget in the topic to be usable with the binding, but you can also use:

Thanks for responding. Yeah I should have mentioned this one. I was able to figure the one you just linked this morning andgot it into habpanel. But I was hoping to have more flexibility re: choosing devices and selecting certain playlists and such. And now that I have to type this out i’m questioning my decision to use something that looks like it’s not getting updates…

Ultimately, I want the ability to pick and choose devices, play certain playlists, etc in habpanel. Does this exist? if it not, where would I begin in terms of learning how to make it myself?

The Spotify Binding supports both play lists and list of devices. I guess it’s possible to either start with the widget of this topic and the one I mentioned and modify them. This can be done in happanel itself. It’s a little bit hard to find. If you have added the widget: in edit mode of a panel, in ‘add widgets’ down in the list click on the small ‘wheel’. This should show you the page of custom widgets. Clicking on the widget opens it in edit mode and then you can add playlists and select devices (devicename as a selector)

I see, that makes sense. I just went in and started playing around with those, and at those point that’s good enough for me. great actually.

Thanks for taking the time to get me going in the right direction again, I really appreciate it!

Hi Guys. Does anyone know how to make the active device name show the name of the device instead of the numeric value?

With openHAB 2.4 and the lastest version of the Spotify Binding it should just show the name (With Selection in sitemap you can make it selectable)

Hmmm. I am on openhab 2.4 and i installed the binding from the eclipse iot store. I’m trying to get this to show in habpanel and not on the sitemap. Is there something im doing wrong or is there a newer version of the binding?

On habpanel when no devices are available, but there was one previous available it seems to show the id instead of the name.

Since you are probably going to know most of your devices beforehand, I just setup individual widgets ($devicename_DevicePlay between PLAY/PAUSE) for all devices I can imagine to be using. Meanwhile in rules I use the devicename (which is id now) and it works fine.

Also… I’m trying to repurpose an old Android-phone (S4 running 5.0.1) to be a Spotify-player… Sofar I’ve been trying to get Spotify to stay alive and connected to the API with Tasker by switching the App on screen and clicking on the player tab every 2 minutes. I also use an app called Screen Standby that is discontinued for a few years now and has it’s quirks, but works! With it I can turn the screen completely black but have the screen still on with Spotify on screen. The apk can be found from various sources, and even though there was a pro-version, it is not needed. A rooted Android device is recommended too.

All this still leaves an issue where it is not possible to control the volume via Spotify API/App when playing through an Android-device… Does anyone know if casting to a Chromecast device from an Android device would suddenly allow volume control? Or am I better off looking for the cheapest Linux/Windows device that I can make in to a Spotify player? I have not setup the normal Openhab voice channels either, so those could probably made to work with a PC device too. Are there other (cheap) devices that could be used to play from Spotify with volume control?

Hello all,

i use openhab 2.4 and i’m pretty new here:).
i try to get the spotify binding running, but it seems like the spotify.items cannot be loaded:

spotify.items (freshly pulled today) is saved in the items folder, but it’s not listet in paper ui and i get an error while trying to set my client id via cli " Error: Item ‘spotify_client_id’ does not exist."
Also my log viewer shows this:
2019-01-05 12:33:12.892 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘spotify.items’ has errors, therefore ignoring it: [1,1]: missing EOF at ‘<’

[885,12]: mismatched character ‘<EOF>’ expecting ‘’’

2019-01-05 12:33:20.490 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘spotify.items’ has errors, therefore ignoring it: [2,1]: missing EOF at ‘<’

[886,12]: mismatched character ‘<EOF>’ expecting ‘’’

maybe you guys can help me with my issue?

You have a typo in your items file. Looks like it’s missing a " But because I can’t see your items I can’t tell for sure.

Please share the content of your spotify.items file, seem to be some errors in there, like @hilbrand also mentions.

Hi RolfV and hilbrand,

thanks for your replys.
You were right, the spotify.items was “wrong”. I Have no idea how it got there, but it was a file starting with:
<!DOCTYPE html>

<html lang=“en”>

<head>

<meta charset=“utf-8”>

<link rel=“dns-prefetch” href=“https://github.githubassets.com”>

Now i have the correct .items file. Openhab loaded it, i see the items in the paper ui and i set the client id+secret.

Thank you.
Let’s see how far i will get :slight_smile:

after i set the new auth code via http://openhabianpi:8080/static/spotify-auth.html
(client id, auth code and status successfull)
i get the response (on /usr/bin/python /etc/openhab2/scripts/spotify.py):

Successfully got state from OpenHab: spotify_client_id
Successfully got state from OpenHab: spotify_client_secret
Successfully got state from OpenHab: spotify_access_token
Successfully got state from OpenHab: spotify_refresh_token
Successfully got state from OpenHab: spotify_token_issued
Successfully got state from OpenHab: spotify_token_expiry
– Calling Token Refresh Service
{‘Content-Length’: ‘69’, ‘Keep-Alive’: ‘timeout=600’, ‘Server’: ‘nginx’, ‘Connection’: ‘keep-alive’, ‘Date’: ‘Sat, 05 Jan 2019 14:43:43 GMT’, ‘Content-Type’: ‘application/json’}
{u’error_description’: u’Invalid refresh token’, u’error’: u’invalid_grant’}
Successfully got state from OpenHab: spotify_auth_code
– Calling Token Service for the first time
{‘Content-Length’: ‘68’, ‘Keep-Alive’: ‘timeout=600’, ‘Server’: ‘nginx’, ‘Connection’: ‘keep-alive’, ‘Date’: ‘Sat, 05 Jan 2019 14:43:43 GMT’, ‘Content-Type’: ‘application/json’}
{u’error_description’: u’Invalid redirect URI’, u’error’: u’invalid_grant’}
– Calling Service: Update
{u’error’: {u’status’: 401, u’message’: u’Invalid access token’}}
_ -> Item node missing from response :(_
Successfully posted state to OpenHab: spotify_lastConnectionDateTime = 2019-01-05T14:43:44+0000
Done in 0.808665037155 seconds

whats is odd, also is that the spotify registration (http://openhabianpi:8080/static/spotify-auth.html) “forgets” my settings after refreshing the site.

do i have a problem while creating/saving the resfresh&accesstoken?

I was under the assumption you used the binding. Python script is not a binding. To use the spotify binding install the binding and not the python script. The binding is available in the eclipse market place which need to be enabled in PaperUI in Configuration system with maturity level beta and the becomes available in the list of bindings in PaperUI.