openHAB integration to Spotify Web Connect API (player)

(Kris K) #267

There is nothing wrong with the widget, as mentioned this was working fine before.

I use the widget to enter the client id and secret, it authenticates correctly. But when I go back into the Open Auth link, it seems its not authenticated.

I also cannot see the token and so on being stored in Influx DB

Its not saving the token it seems.

This was working perfectly before.

(Unparagoned) #268

The static/spotify-auth.html page will not be clear that it has been authorised. But once you done it once you should never need to do it again. Here mine is fully authorised and work and this is what the auth link looks like.


If it is a persistence issue then try this setup.

Mapdb for persistence

mapdb.persist in the persistence folder

Strategies {
		everyHour : "0 0 * * * ?"
    	everyDay  : "0 0 0 * * ?"
		default = everyUpdate

Items {
		* : strategy = everyChange, everyDay, restoreOnStartup

(Kris K) #269

I reinstalled influx db persistance from Paperui.

I used the Widget

11:53:38.399 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘spotify_client_id’ received command 5c80fa9aebb74b41a6eefe36631de518
11:53:38.415 [INFO ] [smarthome.event.ItemStateChangedEvent] - spotify_client_id changed from NULL to 5c80fa9aebb74b41a6eefe36631de518
11:53:47.371 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘spotify_client_secret’ received command 3dd797838ff540a5b0319a7dc6a5e71c
11:53:47.380 [INFO ] [smarthome.event.ItemStateChangedEvent] - spotify_client_secret changed from NULL to 3dd797838ff540a5b0319a7dc6a5e71c
11:53:53.592 [INFO ] [smarthome.event.ItemStateChangedEvent] - spotify_auth_code changed from NULL to AQAkpr66g43p1f9hY0jBpl7sh8Xm1_p-t7l1MmKO_qTN0DOjjrne6LdsNM2HO_6rBhsi9aHkj0k6UuAADRjTL3wRzKveTfIKTYoaz9FD36l5XMLUtJPPlHaQlvMf7wvqGchUCVv7L4a8VsqzBKivtl4hTQfeppEk1PgBQ3KH8yHpRtE1xOZlViMYDPeMwtmNZIFB8D1YKnVXibUIMeUhNPcsBxhRZq8Lk3etiUK96bEhg9lyGy3ajXasTHbIt6QeHo-XfBmw_ECncgkEGYlIx2jd4Zxi4dIbjdPd1R7pyw-oHWk

(Kris K) #270

Problem remains:

Successfully got state from OpenHab: spotify_token_expiry
-- Calling Token Refresh Service
{'client_secret': 'XXX', 'redirect_uri': '', 'client_id': 'XX', 'refresh_token': 'NULL', 'grant_type': 'refresh_token'}
{'Content-Length': '69', 'Keep-Alive': 'timeout=600', 'Server': 'nginx', 'Connection': 'keep-alive', 'Date': 'Thu, 05 Jul 2018 01:57:25 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': 'Thu, 05 Jul 2018 01:57:26 GMT', 'Content-Type': 'application/json'}
{u'error_description': u'Invalid redirect URI', u'error': u'invalid_grant'}
-- Calling Service: Play
Successfully got state from OpenHab: spotify_current_device_id
-- Calling Service: Update
{u'error': {u'status': 401, u'message': u'Invalid access token'}}
 -> Item node missing from response :(
-- Calling Service: Get Devices
 -> Device List Failure:  <type 'exceptions.KeyError'>
-- Calling Service: Get Playlists
{u'error': {u'status': 401, u'message': u'Invalid access token'}}
 -> Playlist List Failure:  <type 'exceptions.KeyError'>
Successfully posted state to OpenHab: spotify_lastConnectionDateTime = 2018-07-05T01:57:28.000+0000
Done in 2.9642021656 seconds

(Kris K) #271

I fixed the issue, found an article on Stackoverflow.

Your URI must match in the spotify script and the Web Dev console. I had my private, internal IP address in the script but my external dns name in the Web dev.

(Pavel) #272

Both variants was tried. Internal IP was the first option. Or you ended put it in the Web Dev console at the end?

(Kris K) #273

I did web dev before also. I also emptied the states

(Kris K) #274

Does anyone know how to stop the huge amount of information in the Log file re: Spotify Updates?

There are logInfo(“Spotify”, resp) statements in the spotify.rule file that I’m sure I can remove but then I may miss information.

One rule in in particular generates a whole page off stuff!

(Unparagoned) #275

Are the large logs an issue?
Why not comment out the log info statements like you suggested?

You don’t need any of the logs unless something is wrong. So you could define DEBUG at the top of the rules and put IF statements around the logInfo statements. So if you have a problem you can then enable later on.

If you want more control you can edit spotify,py and and comment out print statements to achieve what you want.

(Kris K) #276

Thank you. Ill try your suggestions. The playlist rule generates a load of stuff that files the screen. No real issue just see it as pointless info

(Antonio Fontinha) #277

i followed this tutorial step by step but i do not know where i can do in point 5:

" Give the client id and secret to OpenHab

Save the Client ID to spotify_client_id in OpenHab (e.g. through openhab CLI smarthome:update spotify_client_id {your_id})
Copy the Client Secret to spotify_client_secret in OpenHab (e.g. through the rest API)"