Page 1 of 5
Python Plugin: Spotify
Posted: Friday 29 June 2018 9:53
by Sjaakios
This plugin will use the spotify API's to start playback on your spotify connected device.
A spotify premium account is required!
Having some time between project, i've decided to learn some python... So i'm far from a professional so it can still be buggy, let me know if you run into any issues. I've tested this having domoticz running on my Synology Nas, running version 3.8153.
Code + installation steps can be found here:
https://github.com/DaanJJansen/domoticz-spotify
Let me know what you think.
ps. if anybody knows a better solution for the one off manual action to get the authorisation code from Spotify, i'm all ears.
Re: Python Plugin: Spotify
Posted: Friday 29 June 2018 20:29
by Innovator
Thank you for developing this plugin. I tried to get it started on my Synology DS918 + with Domoticz version 4.9700 today.
Until now no device has the following output:
Error: (Spotify) Error calling 'http: // localhost: 8080 / json.htm? Param = getuservariables & type = command'
Error: (Spotify) Can not read the uservariable holding the persistent variables.
Maybe I made a mistake but I think everything is correctly filled in at Spotify including http: // localhost
Re: Python Plugin: Spotify
Posted: Friday 29 June 2018 23:17
by Sjaakios
This error is about not able to reach your domoticz system, it's trying to fetch some user variables. Is this the correct url + port to reach domoticz?
Re: Python Plugin: Spotify
Posted: Wednesday 04 July 2018 0:16
by mozo78
Hi,
Now I could add it, and a new switch appeared. The value of the switch is changing, it shows the current spotify device (phone, or PC). Can you help me how to use the user variables? That is not clear for me.
Re: Python Plugin: Spotify
Posted: Wednesday 04 July 2018 7:44
by Egregius
Hi, I'm having troubles retrieving the code. After entering the code I get this in the logfile:
Code: Select all
Error: (Spotify) Bad request to spotify, code entered in hardware parameters could one be used once. Please get a new one
Any ideas?
Re: Python Plugin: Spotify
Posted: Wednesday 04 July 2018 9:30
by Sjaakios
mozo78 wrote: ↑Wednesday 04 July 2018 0:16
Hi,
Now I could add it, and a new switch appeared. The value of the switch is changing, it shows the current spotify device (phone, or PC). Can you help me how to use the user variables? That is not clear for me.
You could update the user variable with your search string + type of search. Where type of search could be 'artist', 'playlist', 'track', 'album' and the search string is what you want to search.
E.g. update your user variable with 'artist coldplay'. After update, press on the new switch the spotify device (in your case phone or PC) on which you want to listen to coldplay.
Playback should start.
Re: Python Plugin: Spotify
Posted: Wednesday 04 July 2018 9:35
by Sjaakios
Egregius wrote: ↑Wednesday 04 July 2018 7:44
Hi, I'm having troubles retrieving the code. After entering the code I get this in the logfile:
Code: Select all
Error: (Spotify) Bad request to spotify, code entered in hardware parameters could one be used once. Please get a new one
Any ideas?
Hmmmmm... The code can only be used once to retrieve an access token. Did something else went wrong with the plugin before? Try getting a new code from spotify and try again.
To validate, spotify redirects you to
http://localhost/?code=AQ......Cusmbo right? You've entered 'AQ......Cusmbo' in the code parameter?
ps. corrected the spelling mistake in error msg.....
Error: (Spotify) Bad request to spotify, code entered in hardware parameters could
one only be used once. Please get a new one
Re: Python Plugin: Spotify
Posted: Wednesday 04 July 2018 11:28
by Egregius
Yes, I'm redirected to (just changed some of the numbers)
Code: Select all
http://localhost/?code=AQDDgWQ2tTz1ErSgQ_jkty4Viz7ZA7cpTKV01KRrZW5vdLd-CZ01uKPeESo5OJE36i1hMYPAhvhuCjtTY31Ukr3OUt_IzWKUMiDARF1UmHa2b8RnXjLJFkIIiJ5k9r3Uv11AcVofaWbxDoFFy-EwZ2gXRY6m49p7j3PPhIV_tz-2-jDzpXSicy_29nJVE_vIaua-Ydut8nYS-zvws9jkYalM0PNMrvqbjkX1EpPAj3werhkeddEbN07o1Wg
and then I past the 251 characters as code in the settings page
Code: Select all
AQDDgWQ2tTz1ErSgQ_jkty4Viz7ZA7cpTKV01KRrZW5vdLd-CZ01uKPeESo5OJE36i1hMYPAhvhuCjtTY31Ukr3OUt_IzWKUMiDARF1UmHa2b8RnXjLJFkIIiJ5k9r3Uv11AcVofaWbxDoFFy-EwZ2gXRY6m49p7j3PPhIV_tz-2-jDzpXSicy_29nJVE_vIaua-Ydut8nYS-zvws9jkYalM0PNMrvqbjkX1EpPAj3werhkeddEbN07o1Wg
I didn't used the plugin yet, just came across this topic

Re: Python Plugin: Spotify
Posted: Wednesday 04 July 2018 12:36
by Sjaakios
And you tried getting a new code, and enter this accordingly in the plugin?
Meant with using the plugin, it ran befor (e.g. already a call made to spotify using the entered code, making the code invallid as it can only be used once)

Re: Python Plugin: Spotify
Posted: Wednesday 04 July 2018 14:49
by Egregius
Yes, already tried 5 codes. The plugin never worked, it instantly drops the error in the logfile.
Re: Python Plugin: Spotify
Posted: Wednesday 04 July 2018 15:12
by Sjaakios
Hmmm, ok... weird
I've updated the script to provide some more debug information to get a better clue on what is going on.
The request that is failing is making a post call to spotify with your client_id, client_secret and the code. I've made the error more precise so we can see what code spotify is returning. Error code 400 means the client_id, client_secret or code is incorrect.
So if you would, please update your code with the latest version on GIT and PM me the debug log (as it will contain your client_id and secret).
Re: Python Plugin: Spotify
Posted: Wednesday 04 July 2018 18:46
by eddieb
Hmm,
just installed the spotify plugin ...
The handling on the api went as expected.
I get a "Cannot read the uservariable holding the persistent variables" error in the logging right after (re)starting the pluging from the hardware menu
It does not give any devices
Any seggestions ?
Eddie
Re: Python Plugin: Spotify
Posted: Thursday 05 July 2018 10:09
by Sjaakios
This error is about not being able to read the user variables from domoticz. It uses url + port set in hardware parameters.
In your log, is there also a line with:
Code: Select all
Error calling 'http://xxxxx/json.htm?type=command¶m=getuservariables'
Can you validate from the machine running domoticz, that you able to make this call?
Re: Python Plugin: Spotify
Posted: Thursday 05 July 2018 10:20
by eddieb
Hi,
I am running domoticz on Syno ..
http://IP:8084/
I will try to run that command later today.
Eddie
Re: Python Plugin: Spotify
Posted: Thursday 05 July 2018 12:10
by eddieb
root@diskstation:~# curl -v -L
http://127.0.0.1:8084/json.htm?type=com ... rvariables
[1] 31159
root@diskstation:~# > GET /json.htm?type=command HTTP/1.1
> Host: 127.0.0.1:8084
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Content-Length: 24
< Content-Type: application/json;charset=UTF-8
< Cache-Control: no-cache
< Pragma: no-cache
< Access-Control-Allow-Origin: *
<
{
"status" : "ERR"
}
suggestions ????
Re: Python Plugin: Spotify
Posted: Thursday 05 July 2018 12:19
by Sjaakios
ahhh do you have user authentication enabled for domoticz?
Re: Python Plugin: Spotify
Posted: Thursday 05 July 2018 12:22
by eddieb
No, not from 127.0.0.1 ...
Re: Python Plugin: Spotify
Posted: Thursday 05 July 2018 12:22
by Sjaakios
and changed port in spotify hardware parameters to 8084?
Re: Python Plugin: Spotify
Posted: Thursday 05 July 2018 12:27
by eddieb
As you see ...

- Screen Shot 2018-07-05 at 12.25.42.png (78.07 KiB) Viewed 12776 times
Re: Python Plugin: Spotify
Posted: Thursday 05 July 2018 12:32
by Sjaakios
the error from your curl command is because request is incomplete...., somehow stripps the last query parameter. Try:
curl -v -L "
http://127.0.0.1:8084/json.htm?type=com ... rvariables"
When i execute this on my Synology, i get a list of variables