Yes, @Andrew_Pawelski, spotify states are only updated through spotify.py. So you will constantly have to trigger the script. You can do this within your spotify.rules with a cron expression. I am currently only pulling twice a minute 0/30 * * ? * * * and hitting the update button when I want to get the current state (this could also archived with Page Visibility API dont’t you think @pmpkk? )
I am waiting for spotify to release a webook or some kind of aparatus that sends realtime updates to the client.
P.S.: This is what my spotify.rules currently looks like:
rule "Spotify run script"
when
Time cron "0/30 * * * * ? *" or
Item spotify_forceupadte received update
then
val resp = executeCommandLine("/usr/bin/python /etc/openhab2/scripts/spotify.py", 5000)
logInfo("Spotify", resp)
end
rule "Spotify Action"
when
Item spotify_action received update
then
val resp = executeCommandLine("/usr/bin/python /etc/openhab2/scripts/spotify.py " + spotify_action.state.toString, 5000)
logInfo("Spotify", resp)
end
I wanted to ask the same question. I see some interaction on this forum on the spotify.py solution, but not on the Spotify Binding. How do both compare? From an architectural perspective, I prefer a binding instead of a py-script. But the py-script seems to be more mature (and more used).
Hi!
I am making some progress!
It now works really nice but i am still not able to send commands.
Is this even possible?
The commands are labeled with “current” -> current playing for instance.
Can i fire play/pause?
If yes, how?
Thank you!!
@Jonas88, the best way to learn this spotify integration is to look at the code of the custom ground floor widget in the matching matrix theme. It’s also from @pmpkk (you should load the widget and then use habpanel’s build in widget code editor to examine the relevant code.)
If you do not want to use a custom widget but directly take habpanel widgets you would have to use a “button” widget and set it to fire (alternating) events to item spotify_action. See this image:
Ok, i am feeling dumb right now. i just didn’t find it.
For the other guys:
just send commands to the spotify_action item like:
play pause etc … you don’t even need to code, you can just use a button widget for example.
Only “problem” i got now is that my log is growing like crazy because i call the script quite frequently … i did manage to get rid of the status update but if spotify is running the item change (current time) is getting mad. i tried to find a solution to exclude a single item from the log but it doesn’t seem to be that easy …
I see “John’e echo” in your config.
Does this mean you can select a spotify song on the weg UI and stream it through Amazon echo.
Or is this about something totally different?
I tried recreating the bug you talked about. It was easiest to rename my echo to Jem’s Echo which should work unless something more exotic with character sets and encoding is going on. I wasn’t able to recreate the problem. Maybe I accidently patched it at some point and you have an old version.
All the following worked.
python spotify.py play Jem
python spotify.py play "Jem’s"
python spotify.py play “Jem’s Echo”
NCO Who’s code are you running? You should probably be using pmpkk’s version since it seems like he’s backported the key features. But if you are using mine then…
I have mine setup so I can play on any device I like. It allows me to use voice controls on my Echo and home without it changing playback device or I can use my Google Home to play music on my Amazon Echo. At the moment if you want to specify what an album you need to have the spotify uri. I tried using the uri of a song but it seems like the webapi doesn’t like that.
You can do
python spotify.py play spotify:album:4DEZVbAxlZPRXWCHUV5wF3 “Jem’s Echo”
The bug only appears if the echo with the apostrophe appears earlier in the
list than the one you are after.
So assuming g the first item return from your api is Jem’s echo -if you try
migrate to any of your other devices, you’ll see the prob.
If Jem’s echo is last in the list, then the bug won’t appear.
Also, make sure that after the echo rename, the name with an apostrophe
does appear in your returned list from the API as having an apostrophe.
I still can’t replicate the problem. Are you sure you sure you are using my fork? Maybe you are using the main version that pmpkk created?
Here is an example where the first and last device both have apostrophes in them. Maybe Echos’ have better encoding than iphones’ but I’m not sure.The API results have apostrophes as they should.
I set up everything according to your GitHub instruction, but with the last step I keep getting an Error 400 from the API. Do you have an idea why this happens?
/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