Hi all,
First of all, thank you, @pmpkk for developing this nice script! I’m pretty happy with it. However, I do have some questions.
For some reason, the spotify_current_volume often stays “NULL”:
When I run “/usr/bin/python /etc/openhab2/scripts/spotify.py” I get:
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
-- Calling Service: Update
{u'progress_ms': 62769, u'timestamp': 1510077753987, u'repeat_state': u'off', u'shuffle_state': True, u'item': {u'album': {u'album_type': u'single', u'name': u'Whispers From The Surface Of A Lake', u'external_urls': {u'spotify': u'https://open.spotify.com/album/0n1BpWPDxPvlwMRV8kdRHH'}, u'uri': u'spotify:album:0n1BpWPDxPvlwMRV8kdRHH', u'href': u'https://api.spotify.com/v1/albums/0n1BpWPDxPvlwMRV8kdRHH', u'artists': [{u'name': u'Hior Chronik', u'external_urls': {u'spotify': u'https://open.spotify.com/artist/0WwDqOLT2m5PuAsFGkEybC'}, u'uri': u'spotify:artist:0WwDqOLT2m5PuAsFGkEybC', u'href': u'https://api.spotify.com/v1/artists/0WwDqOLT2m5PuAsFGkEybC', u'type': u'artist', u'id': u'0WwDqOLT2m5PuAsFGkEybC'}], u'images': [{u'url': u'https://i.scdn.co/image/d8797fde5ee16b8583b62a7608e66a26fc0e838e', u'width': 640, u'height': 640}, {u'url': u'https://i.scdn.co/image/f713eae5bd2deb7b300c32da232f941ecc003cde', u'width': 300, u'height': 300}, {u'url': u'https://i.scdn.co/image/a75c993b50b31dcaf8d7c032f1838289a7ab5cb6', u'width': 64, u'height': 64}], u'type': u'album', u'id': u'0n1BpWPDxPvlwMRV8kdRHH', u'available_markets': [u'AD', u'AR', u'AT', u'AU', u'BE', u'BG', u'BO', u'BR', u'CA', u'CH', u'CL', u'CO', u'CR', u'CY', u'CZ', u'DE', u'DK', u'DO', u'EC', u'EE', u'ES', u'FI', u'FR', u'GB', u'GR', u'GT', u'HK', u'HN', u'HU', u'ID', u'IE', u'IS', u'IT', u'JP', u'LI', u'LT', u'LU', u'LV', u'MC', u'MT', u'MX', u'MY', u'NI', u'NL', u'NO', u'NZ', u'PA', u'PE', u'PH', u'PL', u'PT', u'PY', u'SE', u'SG', u'SK', u'SV', u'TR', u'TW', u'US', u'UY']}, u'name': u'Whispers From The Surface Of A Lake', u'uri': u'spotify:track:24VAOoJabL301mmPSfYp5z', u'external_urls': {u'spotify': u'https://open.spotify.com/track/24VAOoJabL301mmPSfYp5z'}, u'popularity': 50, u'explicit': False, u'preview_url': u'https://p.scdn.co/mp3-preview/17ae089ea544384e310ea6c6a105a87cd5b5870b?cid=84cfb01a9ec74483b9930e16f025d4be', u'track_number': 1, u'disc_number': 1, u'href': u'https://api.spotify.com/v1/tracks/24VAOoJabL301mmPSfYp5z', u'artists': [{u'name': u'Hior Chronik', u'external_urls': {u'spotify': u'https://open.spotify.com/artist/0WwDqOLT2m5PuAsFGkEybC'}, u'uri': u'spotify:artist:0WwDqOLT2m5PuAsFGkEybC', u'href': u'https://api.spotify.com/v1/artists/0WwDqOLT2m5PuAsFGkEybC', u'type': u'artist', u'id': u'0WwDqOLT2m5PuAsFGkEybC'}], u'duration_ms': 163143, u'external_ids': {u'isrc': u'DEG931701144'}, u'type': u'track', u'id': u'24VAOoJabL301mmPSfYp5z', u'available_markets': [u'AD', u'AR', u'AT', u'AU', u'BE', u'BG', u'BO', u'BR', u'CA', u'CH', u'CL', u'CO', u'CR', u'CY', u'CZ', u'DE', u'DK', u'DO', u'EC', u'EE', u'ES', u'FI', u'FR', u'GB', u'GR', u'GT', u'HK', u'HN', u'HU', u'ID', u'IE', u'IS', u'IT', u'JP', u'LI', u'LT', u'LU', u'LV', u'MC', u'MT', u'MX', u'MY', u'NI', u'NL', u'NO', u'NZ', u'PA', u'PE', u'PH', u'PL', u'PT', u'PY', u'SE', u'SG', u'SK', u'SV', u'TR', u'TW', u'US', u'UY']}, u'context': {u'href': u'https://api.spotify.com/v1/users/spotify/playlists/37i9dQZEVXcOW89i3DotWz', u'type': u'playlist', u'uri': u'spotify:user:spotify:playlist:37i9dQZEVXcOW89i3DotWz', u'external_urls': {u'spotify': u'https://open.spotify.com/user/spotify/playlist/37i9dQZEVXcOW89i3DotWz'}}, u'device': {u'name': u'Living', u'volume_percent': None, u'is_active': True, u'is_restricted': False, u'type': u'CastVideo', u'id': u'414901afbea954d6873c39d448045c23'}, u'is_playing': True}
Successfully posted state to OpenHab: spotify_current_track = Whispers From The Surface Of A Lake
Successfully posted state to OpenHab: spotify_current_artist = Hior Chronik
Successfully posted state to OpenHab: spotify_current_cover = https://i.scdn.co/image/f713eae5bd2deb7b300c32da232f941ecc003cde
Successfully posted state to OpenHab: spotify_current_duration = 163143
Successfully posted state to OpenHab: spotify_current_progress = 62769
Successfully posted state to OpenHab: spotify_current_playing = ON
Successfully posted state to OpenHab: spotify_current_device = Living
Successfully posted state to OpenHab: spotify_current_volume = NULL
Successfully posted state to OpenHab: spotify_current_context_uri = spotify:user:spotify:playlist:37i9dQZEVXcOW89i3DotWz
Successfully posted state to OpenHab: spotify_current_device_id = 414901afbea954d6873c39d448045c23
Successfully posted state to OpenHab: spotify_current_progress_percent = 38.47
-> Success
Successfully posted state to OpenHab: spotify_lastConnectionDateTime = 2017-11-07T18:02:47+0000
Done in 0.517739057541 seconds
When I increase the volume (volume_up), I get:
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
-- Calling Service: Volume Up
Successfully got state from OpenHab: spotify_current_volume
-> VolumeUp Failure: <type 'exceptions.ValueError'>
Successfully posted state to OpenHab: spotify_lastConnectionDateTime = 2017-11-07T18:05:44+0000
Done in 0.0548009872437 seconds
Another thing I noticed is that not all my devices have a Device ID:
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
-- Calling Service: Update
{u'progress_ms': 141323, u'timestamp': 1510079584958, u'repeat_state': u'off', u'shuffle_state': True, u'item': {u'album': {u'album_type': u'album', u'name': u'Yellow Hills', u'external_urls': {u'spotify': u'https://open.spotify.com/album/39CSo60wDA0GznZFJExlFu'}, u'uri': u'spotify:album:39CSo60wDA0GznZFJExlFu', u'href': u'https://api.spotify.com/v1/albums/39CSo60wDA0GznZFJExlFu', u'artists': [{u'name': u'Daniel Kaede', u'external_urls': {u'spotify': u'https://open.spotify.com/artist/6aup7uM4yUHX9NLba0sxmt'}, u'uri': u'spotify:artist:6aup7uM4yUHX9NLba0sxmt', u'href': u'https://api.spotify.com/v1/artists/6aup7uM4yUHX9NLba0sxmt', u'type': u'artist', u'id': u'6aup7uM4yUHX9NLba0sxmt'}], u'images': [{u'url': u'https://i.scdn.co/image/9e368c17ef08c092d95ef30fd68405a7498b0174', u'width': 640, u'height': 640}, {u'url': u'https://i.scdn.co/image/f47e4c781df3e439ed64e8c34f483a6aebb17bfe', u'width': 300, u'height': 300}, {u'url': u'https://i.scdn.co/image/5f18cbf24656817678a38298099a192385c06d99', u'width': 64, u'height': 64}], u'type': u'album', u'id': u'39CSo60wDA0GznZFJExlFu', u'available_markets': [u'AD', u'AR', u'AT', u'AU', u'BE', u'BG', u'BO', u'BR', u'CA', u'CH', u'CL', u'CO', u'CR', u'CY', u'CZ', u'DE', u'DK', u'DO', u'EC', u'EE', u'ES', u'FI', u'FR', u'GB', u'GR', u'GT', u'HK', u'HN', u'HU', u'ID', u'IE', u'IS', u'IT', u'JP', u'LI', u'LT', u'LU', u'LV', u'MC', u'MT', u'MX', u'MY', u'NI', u'NL', u'NO', u'NZ', u'PA', u'PE', u'PH', u'PL', u'PT', u'PY', u'SE', u'SG', u'SK', u'SV', u'TR', u'TW', u'US', u'UY']}, u'name': u'Unspoken Peace', u'uri': u'spotify:track:1aJAjwZXY8z3iJGayp5NIc', u'external_urls': {u'spotify': u'https://open.spotify.com/track/1aJAjwZXY8z3iJGayp5NIc'}, u'popularity': 38, u'explicit': False, u'preview_url': u'https://p.scdn.co/mp3-preview/08c6125eea944b30d1abea87d5f08adec1634424?cid=84cfb01a9ec74483b9930e16f025d4be', u'track_number': 1, u'disc_number': 1, u'href': u'https://api.spotify.com/v1/tracks/1aJAjwZXY8z3iJGayp5NIc', u'artists': [{u'name': u'Daniel Kaede', u'external_urls': {u'spotify': u'https://open.spotify.com/artist/6aup7uM4yUHX9NLba0sxmt'}, u'uri': u'spotify:artist:6aup7uM4yUHX9NLba0sxmt', u'href': u'https://api.spotify.com/v1/artists/6aup7uM4yUHX9NLba0sxmt', u'type': u'artist', u'id': u'6aup7uM4yUHX9NLba0sxmt'}], u'duration_ms': 193421, u'external_ids': {}, u'type': u'track', u'id': u'1aJAjwZXY8z3iJGayp5NIc', u'available_markets': [u'AD', u'AR', u'AT', u'AU', u'BE', u'BG', u'BO', u'BR', u'CA', u'CH', u'CL', u'CO', u'CR', u'CY', u'CZ', u'DE', u'DK', u'DO', u'EC', u'EE', u'ES', u'FI', u'FR', u'GB', u'GR', u'GT', u'HK', u'HN', u'HU', u'ID', u'IE', u'IS', u'IT', u'JP', u'LI', u'LT', u'LU', u'LV', u'MC', u'MT', u'MX', u'MY', u'NI', u'NL', u'NO', u'NZ', u'PA', u'PE', u'PH', u'PL', u'PT', u'PY', u'SE', u'SG', u'SK', u'SV', u'TR', u'TW', u'US', u'UY']}, u'context': {u'href': u'https://api.spotify.com/v1/users/spotify/playlists/37i9dQZEVXcOW89i3DotWz', u'type': u'playlist', u'uri': u'spotify:user:spotify:playlist:37i9dQZEVXcOW89i3DotWz', u'external_urls': {u'spotify': u'https://open.spotify.com/user/spotify/playlist/37i9dQZEVXcOW89i3DotWz'}}, u'device': {u'name': u'Keuken', u'volume_percent': 27, u'is_active': True, u'is_restricted': True, u'type': u'Speaker', u'id': None}, u'is_playing': True}
Successfully posted state to OpenHab: spotify_current_track = Unspoken Peace
Successfully posted state to OpenHab: spotify_current_artist = Daniel Kaede
Successfully posted state to OpenHab: spotify_current_cover = https://i.scdn.co/image/f47e4c781df3e439ed64e8c34f483a6aebb17bfe
Successfully posted state to OpenHab: spotify_current_duration = 193421
Successfully posted state to OpenHab: spotify_current_progress = 141323
Successfully posted state to OpenHab: spotify_current_playing = ON
Successfully posted state to OpenHab: spotify_current_device = Keuken
Successfully posted state to OpenHab: spotify_current_volume = 27
Successfully posted state to OpenHab: spotify_current_context_uri = spotify:user:spotify:playlist:37i9dQZEVXcOW89i3DotWz
Successfully posted state to OpenHab: spotify_current_device_id = NULL
Successfully posted state to OpenHab: spotify_current_progress_percent = 73.06
-> Success
Successfully posted state to OpenHab: spotify_lastConnectionDateTime = 2017-11-07T18:33:07+0000
Done in 0.548756122589 seconds
I guess that limits my “transfer_playback” options, right? Since that function is based on Device ID and not Device.
And I also notices that the list from “get_devices” is always different. Many of my devices only appear in that list if I am playing music via Spotify on that devices (started from the Spotify app). That also implies that the list in “get_devices” is shorter than the list I see via the app.
And there seems to be a small typo in spotify.items: I guess “spotify_forceupadte” should be “spotify_forceupdate”.
The final thing I noticed is… I can’t play a song of my choosing. I can play/pause/next/previous. But none of these commands seem to do anything. What am I doing wrong?
/usr/bin/python /etc/openhab2/scripts/spotify.py play uri spotify:track:1snNAXmmPXCn0dkF9DaPWw
/usr/bin/python /etc/openhab2/scripts/spotify.py play spotify:track:1snNAXmmPXCn0dkF9DaPWw
/usr/bin/python /etc/openhab2/scripts/spotify.py play uri spotify:track:1snNAXmmPXCn0dkF9DaPWw Livingroom
What is the correct command to play a specific number on a specific device?