LogicMachine Forum
SONOS app - Printable Version

+- LogicMachine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Application Store (https://forum.logicmachine.net/forumdisplay.php?fid=11)
+--- Thread: SONOS app (/showthread.php?tid=415)

Pages: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18


RE: SONOS app - Daniel - 29.12.2023

Do you use Mosaic? If no just create a floor and a room in it, also make sure it is a latest version.


RE: SONOS app - FatMax - 16.09.2024

(11.09.2019, 07:47)Daniel Wrote: 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)

Are there more functions then what is listed here? Specifically I would like to group and ungroup players via script.


RE: SONOS app - lcrowhurst - 18.10.2024

In the app is there a way of changing the banner an icon colours from green to another colour, also is it possible to remove the close button?


RE: SONOS app - mariosp - 07.01.2026

is there a way to add the play favorite button ?


RE: SONOS app - Daniel - 07.01.2026

https://forum.logicmachine.net/showthread.php?tid=415&pid=13969#pid13969
last example


RE: SONOS app - mariosp - 07.01.2026

(07.01.2026, 16:17)Daniel Wrote: https://forum.logicmachine.net/showthread.php?tid=415&pid=13969#pid13969
last example

i already tried this   sonos_app.GetStoragePlayerGroupData(groupID, 'Favorites')
and i get this to erro logs Us


RE: SONOS app - Daniel - 07.01.2026

Did you try the play/pause script?


RE: SONOS app - mariosp - 07.01.2026

(07.01.2026, 16:47)Daniel Wrote: Did you try the play/pause script?

Yes also doesnt work 
But it works from the wighet


RE: SONOS app - Daniel - 08.01.2026

Did you fallow the instructions and created first script in this post?


RE: SONOS app - mariosp - 08.01.2026

(08.01.2026, 08:27)Daniel Wrote: Did you fallow the instructions and created first script in this post?
Yes i have made a resident script every 60 sec


RE: SONOS app - Daniel - 09.01.2026

If you have this script working then first try basic play/pause
Create a bit object and then event script on it.  use this script and change Bedroom to your group name, you can see it in Sonos app on the bottom. 
 
Code:
require('custom.sonos.lib')

groupName='Bedroom'

-------------------------------------------------------------
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
https://app.screencast.com/zJSLrszerduNH


RE: SONOS app - mariosp - 09.01.2026

Thank You The problem was that I had a _ in the name! 
Is there any way to play a specific album?


RE: SONOS app - Daniel - 12.01.2026

if you add it to favorite then you can play a specific favorite from there.


RE: SONOS app - mariosp - 03.02.2026

(12.01.2026, 08:39)Daniel Wrote: if you add it to favorite then you can play a specific favorite from there.
Hello again when i try to read the the play favorites i get this (Image)


Im trying with this script but i cant make it work 
Code:
require('custom.sonos.lib')

groupName='Living Room'

-------------------------------------------------------------
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
-- play playlist by ID
sonos_app.SendApiActionCommand(url_group_id, 'playPlaylist', 491)
end



RE: SONOS app - Erwin van der Zwart - 04.02.2026

You probably need to change

groupID=k 
    break

into

url_group_id = k 
    break