Idea for Binding: Spotify Connect binding

Hi @mgbowman,
Any progress so far with the binding?

  • jordo

Hi @Jordo,

Unfortunately I’ve too busy with my house to be able to work on this. Once I’m settled in the new place and I clear the smoke from my new automation setup, I’ll get back into OH2 development. Until then, please don’t expect much of me :see_no_evil:

Matthew

I’ve picked up on this binding in consultation with @mgbowman , see also the pull request (although no work from me visible on this pr). I’ve already made some progress. It requires some significant work as there were over 80 review comments. This should also fix the bug. I planning to have this work done by the end of August.

1 Like

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

Hello @hilbrand,

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

Jordo

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.

5 Likes

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

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.

@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.
1 Like

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.

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?

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?

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

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

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.

1 Like

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.

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

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.

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!

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