Spotify Connect Binding

Hello Hilbrand. I was wondering if it is possible to add to your Spotify binding a channel equivalent to the “Goto Song Radio” on the spotify application?

It doesn’t look like this information is available through the spotify api. Meaning it’s not possible to add such a feature.

Every once in a while I do get “Disposing handler for thing ‘spotify:player:xxxx’ takes more than 5000ms.” and CANT seem to solve it by restarting the binding / touching the jar file.
The only solution is restarting the openHAB service

What version of the binding are you running? Make sure you have a version as recommended in the first post of this topic. Some older version had a concurrency problem. So if you are running an older version that might cause the problem.

I was using “2.5.0.201901221556” but did now update to “2.5.0.201903261051” and will see if the issue reoccurs

That’s an older version. I would recommend to recreate the Spotify things because the configuration of the things changed. (name has become unique key, to handle changing id’s).

I am running the latest version “Spotify Binding (Beta 30/04/2019 23:00)”, but removing all old Spotify things and re-authorizing to Spotify did the trick to remove the error. Many thanks.

I can successfully switch the audio cast device using the OH binding between my Samsung phone, Win10 device and Android TV, however, Google Home / Google Mini don’t work through the OH binding.

Of note, the deviceID for my GoogleHome/GoogleMini are shorter than the rest:

SURFACE2 96063887a3488e63368b4cec38a7277da772c4b4
android tv d129fbddb69ae7b5c81a0c545392ca1e6e021de6
PaulCell 06f45ed180c2c1dc803447e829d9154c8247124c
Family speaker d28aeccf4cef4c54b67c306aee218ed3
Kitchen 3c3c19b8617c23f8c501dcfb4c4da3cf

Below are the logs when I try to switch from Kitchen speaker to Family speaker.
It gives an error “Device not found”.
I seem to recall something about needing to wake up the devices? Has someone had success with that?

The code I am running to cause the logs below:

sendCommand(spotify_player_16adcc6b9bd_deviceId, “92a19431959273f18e71a696912f3bbd”)
sendCommand(spotify_player_16adcc6b9bd_deviceName, “Family speaker”)

2019-05-21 20:37:06.498 [vent.ItemStateChangedEvent] - spotify_player_16adcc6b9bd_trackProgress changed from 2:31 to 2:32
2019-05-21 20:37:07.500 [vent.ItemStateChangedEvent] - spotify_player_16adcc6b9bd_trackProgress changed from 2:32 to 2:33
2019-05-21 20:37:08.500 [vent.ItemStateChangedEvent] - spotify_player_16adcc6b9bd_trackProgress changed from 2:33 to 2:34
2019-05-21 20:37:09.051 [ome.event.ItemCommandEvent] - Item ‘spotify_player_16adcc6b9bd_deviceId’ received command 92a19431959273f18e71a696912f3bbd
2019-05-21 20:37:09.053 [nt.ItemStatePredictedEvent] - spotify_player_16adcc6b9bd_deviceId predicted to become 92a19431959273f18e71a696912f3bbd
2019-05-21 20:37:09.055 [vent.ItemStateChangedEvent] - spotify_player_16adcc6b9bd_deviceId changed from 3c3c19b8617c23f8c501dcfb4c4da3cf to 92a19431959273f18e71a696912f3bbd
2019-05-21 20:37:09.056 [ome.event.ItemCommandEvent] - Item ‘spotify_player_16adcc6b9bd_deviceName’ received command Family speaker
2019-05-21 20:37:09.058 [nt.ItemStatePredictedEvent] - spotify_player_16adcc6b9bd_deviceName predicted to become Family speaker
2019-05-21 20:37:09.059 [vent.ItemStateChangedEvent] - spotify_player_16adcc6b9bd_deviceName changed from Kitchen Speaker to Family speaker
2019-05-21 20:37:09.122 [hingStatusInfoChangedEvent] - ‘spotify:player:16adcc6b9bd’ changed from ONLINE to OFFLINE: Device not found
2019-05-21 20:37:09.128 [hingStatusInfoChangedEvent] - ‘spotify:device:16adcc6b9bd:9606’ changed from ONLINE to OFFLINE (BRIDGE_OFFLINE): Spotify Bridge Offline
2019-05-21 20:37:09.129 [hingStatusInfoChangedEvent] - ‘spotify:device:16adcc6b9bd:d129’ changed from ONLINE to OFFLINE (BRIDGE_OFFLINE): Spotify Bridge Offline
2019-05-21 20:37:09.130 [hingStatusInfoChangedEvent] - ‘spotify:device:16adcc6b9bd:3c3c’ changed from ONLINE to OFFLINE (BRIDGE_OFFLINE): Spotify Bridge Offline
2019-05-21 20:37:09.501 [vent.ItemStateChangedEvent] - spotify_player_16adcc6b9bd_trackProgress changed from 2:34 to 2:35
2019-05-21 20:37:10.507 [vent.ItemStateChangedEvent] - spotify_player_16adcc6b9bd_trackProgress changed from 2:35 to 2:36
2019-05-21 20:37:11.321 [hingStatusInfoChangedEvent] - ‘spotify:player:16adcc6b9bd’ changed from OFFLINE: Device not found to ONLINE
2019-05-21 20:37:11.329 [hingStatusInfoChangedEvent] - ‘spotify:device:16adcc6b9bd:9606’ changed from OFFLINE (BRIDGE_OFFLINE): Spotify Bridge Offline to ONLINE
2019-05-21 20:37:11.335 [hingStatusInfoChangedEvent] - ‘spotify:device:16adcc6b9bd:d129’ changed from OFFLINE (BRIDGE_OFFLINE): Spotify Bridge Offline to ONLINE
2019-05-21 20:37:11.336 [hingStatusInfoChangedEvent] - ‘spotify:device:16adcc6b9bd:3c3c’ changed from OFFLINE (BRIDGE_OFFLINE): Spotify Bridge Offline to ONLINE
2019-05-21 20:37:11.338 [vent.ItemStateChangedEvent] - spotify_player_16adcc6b9bd_deviceId changed from 92a19431959273f18e71a696912f3bbd to 3c3c19b8617c23f8c501dcfb4c4da3cf
2019-05-21 20:37:11.338 [vent.ItemStateChangedEvent] - spotify_player_16adcc6b9bd_deviceName changed from Family speaker to Kitchen Speaker
2019-05-21 20:37:11.508 [vent.ItemStateChangedEvent] - spotify_player_16adcc6b9bd_trackProgress changed from 2:36 to 2:37
2019-05-21 20:37:12.508 [vent.ItemStateChangedEvent] - spotify_player_16adcc6b9bd_trackProgress changed from 2:37 to 2:38
2019-05-21 20:37:13.508 [vent.ItemStateChangedEvent] - spotify_player_16adcc6b9bd_trackProgress changed from 2:38 to 2:39
2019-05-21 20:37:14.508 [vent.ItemStateChangedEvent] - spotify_player_16adcc6b9bd_trackProgress changed from 2:39 to 2:40

Thanks,
Paul

I should add that I can only switch the output to a device thats shows up on this list:

curl -X "GET" "https://api.spotify.com/v1/me/player/devices"

The Chromecast binding seems to think the device is active, but Spotify binding does not.
How can I wake it up the way my Spotify app does on the phone?

image

1 Like

The Spotify API “Get Recommendations Based on Seeds” seems equivalent to “Goto Track Radio”.
The issue is that it does not provide a new playlist id but a detailed list of tracks. So it needs an extra step to create the related playlist.
I guess it’s a lot to ask but it will be great if it is part of your binding. I am happy to help but I am not a software developer.

I’m also having trouble sending music to my receiver (ONKYO). From the spotify app on my phone or PC I can easily transfer it even when the receiver is OFF.

From the spotify binding, I can ONLY use it once I have transferred the music through my phone spotify App once (after every time i switch the receiver OFF and back ON i have to do this). Afterwards, I can switch music from receiver to phone and back through the Binding.

I have also tried turning the receiver ON and setting it to the spotify mode before using the OH binding but no luck.

It would be great to do whatever the App does and “wake up” any device automatically…

Thanks for the development! I succesfully installed the binding, but I’m facing some issues.
I run spotify through my chromecast audio. When I turn on the spotify app and play music, I can effectively see all the correct information on the sitemap: track progress, album image, the player, etc…

However, when I press the buttons on the sitemap nothing happens. I press pause, but the music keeps playing. On the other hand, if I press pause on my android phone, then the button on my sitemap switches to pause.

So it’s basically showing the correct information, but I cannot control spotify from my sitemap.

Any idea what is causing this?

@hilbrand
I have installed the binding and set it up as the docs said. It worked like a charm, it started the selected playlist instantly.
However after a restart I get this error:

2019-07-11 19:57:05.755 [ERROR] [nal.common.AbstractInvocationHandler] - An error occurred while calling method 'ThingHandler.handleCommand()' on 'org.openhab.binding.spotify.internal.handler.SpotifyDeviceHandler@33b59f': null

java.lang.NullPointerException: null

	at org.openhab.binding.spotify.internal.handler.SpotifyHandleCommands.handleCommand(SpotifyHandleCommands.java:127) ~[?:?]

	at org.openhab.binding.spotify.internal.handler.SpotifyDeviceHandler.handleCommand(SpotifyDeviceHandler.java:68) ~[?:?]

	at sun.reflect.GeneratedMethodAccessor159.invoke(Unknown Source) ~[?:?]

	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]

	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]

	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [112:org.eclipse.smarthome.core:0.10.0.oh240]

	at org.eclipse.smarthome.core.internal.common.InvocationHandlerSync.invoke(InvocationHandlerSync.java:59) [112:org.eclipse.smarthome.core:0.10.0.oh240]

	at com.sun.proxy.$Proxy232.handleCommand(Unknown Source) [302:org.openhab.binding.spotify:2.5.0.201904302100]

	at org.eclipse.smarthome.core.thing.internal.profiles.ProfileCallbackImpl.handleCommand(ProfileCallbackImpl.java:75) [119:org.eclipse.smarthome.core.thing:0.10.0.oh240]

	at org.eclipse.smarthome.core.thing.internal.profiles.SystemDefaultProfile.onCommandFromItem(SystemDefaultProfile.java:49) [119:org.eclipse.smarthome.core.thing:0.10.0.oh240]

	at sun.reflect.GeneratedMethodAccessor158.invoke(Unknown Source) ~[?:?]

	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]

	at java.lang.reflect.Method.invoke(Method.java:498) ~[?:?]

	at org.eclipse.smarthome.core.internal.common.AbstractInvocationHandler.invokeDirect(AbstractInvocationHandler.java:153) [112:org.eclipse.smarthome.core:0.10.0.oh240]

	at org.eclipse.smarthome.core.internal.common.Invocation.call(Invocation.java:53) [112:org.eclipse.smarthome.core:0.10.0.oh240]

	at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:?]

	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:?]

	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:?]

	at java.lang.Thread.run(Thread.java:748) [?:?]

==> /var/log/openhab2/events.log <==

2019-07-11 19:57:05.744 [ome.event.ItemCommandEvent] - Item 'Spotify_Bathroom_TrackToPlay' received command spotify:playlist:37i9dQZF1DXcBWIGoYBM5M

2019-07-11 19:57:05.751 [nt.ItemStatePredictedEvent] - Spotify_Bathroom_TrackToPlay predicted to become spotify:playlist:37i9dQZF1DXcBWIGoYBM5M

2019-07-11 19:57:05.755 [vent.ItemStateChangedEvent] - Spotify_Bathroom_TrackToPlay changed from spotify:playlist:37i9dQZEVXbMDoHDwVN2tF to spotify:playlist:37i9dQZF1DXcBWIGoYBM5M

Can you help me, why this happens?

Thanks!

@rkrisi

Based on the error the only logical way to trigger this would be if the specific device thing is being initialized by openHAB before the Bridge is being initialized (for some reason). If this is true than the workaround would be to remove the device thing and add it again. (The bridge, with OAuth2 configuration can be kept). Can you check if this suggestion fixes your problem? Because than I’m going to see how I can improve that part.

If it doesn’t work can you check the log for other errors (or reboot again and see if you get any errors)

Thanks I’ll try this.

Also I have one other question (I suppose this is how the API works but maybe someone has some idea), so sometimes some devices go OFFLINE, and only come back online if I start the Spotify app on one of my device. Are there other methods to bring devices back to online?

Some devices disappear from the Spotify Api when they go offline. For example this is known behavior of Chromecasts. The binding can’t do anything about it because for the binding the device doesn’t exist anymore. If a device can be switched on by another binding, it might be possible to use a rule to first switch the device on and than trigger the play. But it’s probably not straight forward.

I will see what I can do, because these are always on devices (like Chromecasts) and they are online 90% of time, so not a really big problem…

After deleting and re-adding the Thing, it works again. However just after a bundle:refresh it refuses to work…

That reloads all binding things and could result in the same problem, I would assume. Do you have the thing configuration in files? And is the device configuration above the bridge? and if so can you try with placing the device configuration after the bridge?

No, I’m using PaperUI to manage my Things and using files just for items/rules.
Any idea regarding PaperUI?

Did you find a solution for this issue? I have a similar issue (however with a Yamaha device with Spotify Connect). Only works when there is already something playing.