This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

SONOS app
Hello everyone Smile
I have been following this conversation for the last year and implementend the SE version which was working nicely.
I'd like to test this new app and more specifically the new Sonos API. Has anyone manage to control their Sonos with the new API ?
I am completely stuck with all theses :
Create authorization code -> https://developer.sonos.com/reference/au...tion-code/
Create token -> https://developer.sonos.com/reference/au...ate-token/
etc ...

I don't know what part is already done by the LM Sonos App itself and what part should I do to have a simple script doing play/pause (without using the objects automatically created but fully Sonos API) ? https://developer.sonos.com/reference/co...back/play/
Anyone could help us on that ?
Thank you very much.
Reply
Hi,

The old version of the Sonos app was created by me, in that app i created a self build API that was able to receive HTTP command with arguments and those where converted to LUA commands to SOAP (UpnP).

The new version of the app is build by our development department and the decission was made to certify the app to be able to use the official Sonos API, due to this certification we where forced to drop the self build API in the app. Now you can only use the objects that are created automatically by adding them to the touch application.

There is no build in mechanisme to send HTTP commands to the app anymore in the new version.

We still can use the old .lp API by uploading it to the ftp folder, but i still need to make some adjustments as the old app performed a auto scan of Sonos devices on startup that is now missing in the .lp file, but i have no time this moment to do it.

BR,

Erwin
Reply
Hi

Here is how to use new Sonos app via script:

The app runs a daemon which keeps communication with each player/group The daemon will be closed down after 120s if no update is send so we need to run such script every 60s to keep communication up and running.
Code:
require('custom.sonos.lib')

groupID=sonos_app.GetStoragePlayerGroups()
for k, v in pairs(groupID) do
   sonos_app.SendApiActionCommand(k, 'watchPlayerGroup', os.time())
end

To control the players we need to know groupID which can be read via such command.
Code:
groupID=sonos_app.GetStoragePlayerGroups()

Basic control is done like this
Code:
-- simle command: play, pause, skipToPrev, skipToNext
sonos_app.SendApiActionCommand(url_group_id, 'play')
Code:
-- set volume
sonos_app.SendApiActionCommand(url_group_id, 'setVolume', 50)

The url_group_id is in the table from the groupID but it can be read automatically when we know group name so example start/pause script would looks like that.
Code:
require('custom.sonos.lib')

groupName='Kitchen'

-------------------------------------------------------------
groupID=sonos_app.GetStoragePlayerGroups()
for k, v in pairs(sonos_app.GetStoragePlayerGroups()) do
  if groupID[k].groupName == groupName then
  groupID=k 
    break
  end
end
-------------------------------------------------------------

value = event.getvalue()
if value then
    sonos_app.SendApiActionCommand(groupID, 'play')
else
  sonos_app.SendApiActionCommand(groupID, 'pause')
end

To read Playlist table use this
Code:
sonos_app.GetStoragePlayerGroupData(groupID, 'Playlists')

To Play a playlist
Code:
-- play playlist by ID
sonos_app.SendApiActionCommand(url_group_id, 'playPlaylist', playlist_id)
playlist_id looks like a number but it is a string!

To read Favorites use
Code:
sonos_app.GetStoragePlayerGroupData(groupID, 'Favorites')

To play a Favorites
Code:
sonos_app.SendApiActionCommand(url_groupID, 'playFavorite', url_favID)
Reply
Thank you very much Erwin and Daniel for you answers !
Reply


Forum Jump: