Idea for Binding: Spotify Connect binding

spotify
binding
Tags: #<Tag:0x00007f014d233ef8> #<Tag:0x00007f014d233d90>

(Jordo) #43

Hi @mgbowman,

Ahh sorry for asking then!

For the binding, i’ll wait for a update.
I hasn’t came online for a while, and was just wondering for the progress :slight_smile:

Jordo


(Jordo) #44

Hello @hilbrand,

Sounds great, thanks for picking up the binding.
Give a shout when i can do something! :smile:

Jordo


(Hilbrand Bouwkamp) #45

Here’s an update on the Spotify Binding!

I’ve finished most of the work on the Spotify binding. I’ve made a first jar of this Binding which is available here: https://github.com/Hilbrand/openhab2-addons/releases/tag/spotify

The binding needs some updating of the documentation/javadoc, and some code cleanup (removing commented out code/renaming). It’s compiled against 2.4.0-snapshot so you’re mileage my vary with older versions.

For those wanting to use this binding. Please do test so I can get early feedback and fix/change things. So we can get it stable before merging it. (Also checkout your openHAB dashboard if you install this binding!) In the meantime I’m going to proceed and hope to have the clean up finished in some days and push it to the binding PR so it can be reviewed.

If bug’s are found, and I’ve fix them, I’ll update the jar, and post it here.

So please test it, and let me know.


openHAB integration to Spotify Web Connect API (player)
(Hilbrand Bouwkamp) #46

I’ve updated the Spotify Binding (jar) because I found some blocking issues. It should be more stable now.


(Philipp) #47

Hey @hilbrand,
thanks for working on the binding. I did some testing with my setup that consists of 3 Chromecast Audio devices and an Audio Group with all devices. The Chromecasts are only discovered when the Spotify app is active, which means that they also are shown as offline after playback stops. But that’s what I expected and rather a Chromecast issue there. I solved this using a spare android phone and tasker to select the target device there.
I noticed a few issues with the binding:

  • Album and Artist are not displayed (Track names work)
  • Album Image is also missing
  • I’ve noticed that it did around 18000 API calls yesterday. Don’t know if that is a problem though. Just seems a lot

What is working for me is setting volume and shuffle.


(Hilbrand Bouwkamp) #48

@pbross
Thanks for testing. Here’s what I found:

  • Chromecasts: It looks like they go into some sort of sleep mode when not playing. Then they are not reported by the Spotify API. Maybe it’s possible to wake them up using the chromecast binding and a rule that is triggered when clicking on play in the spotify binding.
  • No Album, Artist and Image: I can’t reproduce this. From what I found about this, some type of sources don’t give this information and some older devices also don’t seem to report this information. You could compare this by running the Spotify webclient and see what that reports. Also if you set log level to TRACE (org.openhab.binding.spotify) you can see what the Spotify API returns (Don’t forget to set the loglevel back to DEFAULT because it creates a lot of logging).
  • Lot’s of API calls: The default configuration option calls Spotify every 5 seconds (with 2 calls). The API is rate limited, and the binding should handle that, but I haven’t seen any problems.
    If this would be(come) a problem it would be worth to add some more logic to reduce the number of calls, but it might limit response time if Spotify is controlled outside. For example only call API at the end of a song and not when it’s not playing (that would not get updates when the user for example controls Spotify from a phone) and/or additional update on Refresh command.

(Hilbrand Bouwkamp) #49

I’ve updated the Spotify Binding jar. The code has also been added to the PR and unless there will be lots of feedback this version should be close to what will be the finished version to be.


(fuslwusl) #50

Hi, thanx for your great work!
I replaced the old spotify connect binding with your version.
Now my redirect url doesn’t work anymore - the old one did.
Is it possible to use https://home.myopenhab.org and what do i have to set up to get this work?


(Hilbrand Bouwkamp) #51

You need to go to the local connectspotify page, which should be accessible via your local openhab dashboard (for now, possible this will be removed) or http://<your openhab ipaddres + port>/connectspotify This will show the redirect uri. (Possible if you remove the last part (/authorize) of the redirect_uri it should work I think)

I’m not sure if myopenhab.org can be used. I haven’t tested it, and am not familiar with how myopenhab.org works. Can you access your dashboard from myopenhab.org?


(fuslwusl) #52

Hi thanx a lot. The local connection works and i am testing it now. A connection with myopenhab.org would be great for security reasons (no need to open your openhab system for connections anymore).

I am using openHAB 2.3.0-1 (Release Build) an have the following problem:
Title, Playback time etc is not shown - but PLAY, PAUSE commands are working.
Log shows following warnings:

[WARN ] [mmon.WrappedScheduledExecutorService] - Scheduled runnable ended with an exception

java.lang.NoSuchMethodError: org.eclipse.smarthome.core.library.types.OnOffType.from(Z)Lorg/eclipse/smarthome/core/library/types/OnOffType;

at org.openhab.binding.spotify.internal.handler.SpotifyBridgeHandler.updatePlayerInfo(SpotifyBridgeHandler.java:325) ~[?:?]

at org.openhab.binding.spotify.internal.handler.SpotifyBridgeHandler.pollStatus(SpotifyBridgeHandler.java:266) ~[?:?]

at org.openhab.binding.spotify.internal.handler.SpotifyBridgeHandler.lambda$0(SpotifyBridgeHandler.java:130) ~[?:?]

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:?]

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

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) ~[?:?]

at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) ~[?:?]

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) [?:?]

(Philipp) #53

I experience the same problems @fuslwusl described since the latest update. I’m also on the 2.3.0 release build.


(Hilbrand Bouwkamp) #54

Hmm… great it works. The error is related to changes in the smart home core. It’s available in the 2.4.0-snapshot… (Incidentally I was the one who submitted this method to the core and so started using it, but it breaks with current releases… so much for progress…)

I’ve updated the jar file in the url provided above that removes the use of this method, so that jar should be compatible with 2.3 (at least for not having this problem). The final release will have the methods.


(fuslwusl) #55

Thanx, it works! You just have to set the log level for the binding to WARN to get rid of the playback messages every second.


(fuslwusl) #56

Thanx for your great work - the binding is 100% reliable. I found no problems so far.


(Alan Fenwick) #57

Nice work - I have been using g that Perl script for ages (reliably) but am excited by this. Looking forward to implementing it when I get home.


(Masssssy) #58

Hey,

I’m trying to authorize my account but I get INVALID_CLIENT: Invalid redirect URI for both local IP and myopenhab.org when I try to set it up. Suggestions?

Edit: Had to add the redirect uri in the Spotify dashboard…:sweat_smile:

If I understand correctly there currently is no functionality to start playing a song/playlist on one of the devices from OpenHAB? My first goal with this would be to automatically stop playing in headphones and keep going in the living room when I come home. So much potential in a good Spotify binding!


(Hilbrand Bouwkamp) #59

Did you look in paper UI under the spotify channels -> show more -> trackToPlay channel. Is that what you are looking for?


(Masssssy) #60

Possibly. I suppose I am supposed to send the track to that item somehow? Can not find any information about format, link type, track id etc anywhere so I’m just guessing right now.

Edit: Found the documentation…doh. However I have tried sending both Spotify uri and href of a song to the trackToPlay using a string item but can’t get the song playing on my computer to change.

spotify_tracktoplay.sendUpdate("spotify:track:abc123")
spotify_tracktoplay.sendCommand("spotify:track:abc123")

'spotify:player:f7a68189' changed from ONLINE to OFFLINE: Non supported context uri

Got it working with a playlist
…sendCommand(“spotify:user:spotify:playlist:abc123”)

But it should work with tracks too, no?


(Hilbrand Bouwkamp) #61

I did a quick look-up and it looks like playing a track requires a different call in the spotify api. But that is not supported by the binding (yet: I’ll add it). It should be able to play albums, playlists.

Also if you want to transfer playing to another device you can simply start play on the other device in openHAB (you have to add that device as thing and start play on it). It will then start playing the song already playing on the other device.


(Masssssy) #62

Alright!

Now I’m just pulling my hair because Spotify and or Google have the most annoying system for casting to Chromecast.

  1. As you’ve mentioned you need to cast from a local device, eg phone or web tab in order for the device to show as online.

  2. If I cast from my phone it gets a separate device id than if I cast from a web tab even though both are casting to the same Chromecast.