openHAB integration to Spotify Web Connect API (player)

Hi and sorry for not replying.

Did you replace the code in your python script? (see post 166 above) You need to make sure that the script remains executable etc.

You’ll need the exec binding (which I assume is already going for you to be able to run the python script)
Also, if you edit the script, make sure to verify the executable state and ownership of the file.

Once you have done that, create some items in your items file:

String spotify_shuffle_state

Switch spotify_shuffle

Shuffle on is:
/usr/bin/python /etc/openhab2/scripts/spotify.py shuffle

Shuffle off is:
/usr/bin/python /etc/openhab2/scripts/spotify.py shuffleoff

you could create simple rule like:

rule "Map and update spotify shuffle status"

when

Item spotify_shuffle_state changed

then

logInfo("INFO","spotify_shuffle_state : "+ spotify_shuffle_state.state);

if(spotify_shuffle_state.state == "True"){

    spotify_shuffle.postUpdate(ON)

}

if(spotify_shuffle_state.state == "False"){

    spotify_shuffle.postUpdate(OFF)

}

end

and

rule "Map switch change to post spotify update"

when

Item spotify_shuffle changed

then

if(spotify_shuffle.state == ON){

    executeCommandLine("/usr/bin/python /etc/openhab2/scripts/spotify.py shuffle")

}

if(spotify_shuffle.state == OFF){

    executeCommandLine("/usr/bin/python /etc/openhab2/scripts/spotify.py shuffleoff")

}

end

If you really wanted you could reduce that to a single rule, or even just bind the actions to the items.

I now use the newer Spotify binding from Spotify Connect Binding available which works trial well, but if you are happy with what you are using, there is no real need to change it.

Good luck :slight_smile: