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 that you accept these cookies being set.

SONOS app
(05.06.2020, 14:46)Erwin van der Zwart Wrote: Hi,

What source are you playing from? We store the current URI when playing the mp3 and works with Intune Radio, but it might be that playing Spotify or other service has another methode then the URI we store and That might be the cause of what you experience. Can you test it with a radio station playing?

BR,

Erwin
Hi Erwin

That was the cause... I was playing from Spotify, but tested now with a radio station in the Sonos app, and then it worked.
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
Hi,

Try this script, it is stand alone and it does not uses any of the (old) Sonos App files

.lua   Sonos doorbell by script.lua (Size: 14.84 KB / Downloads: 78)

BR,

Erwin
Reply
(29.06.2020, 14:06)Erwin van der Zwart Wrote: Hi,

Try this script, it is stand alone and it does not uses any of the (old) Sonos App files


BR,

Erwin

Nothing happens when running it. 

I changed the start of the script to;

Code:
    playername = 'Kontor'
  renew_stored_player_data = true  -- set to true to force a network scan and renew stored player data table
    audiofile = 'http://192.168.39.10/user/Ringeklokke.mp3'
    duration = 10 -- duration of the audiofile
    volume = 10

I am soon ready to give up the sonos integration. It seems that what I need to do is not possible, or I am just not able to do it...

What I need to do is the following:
- If I get a TRUE on my object, I want to play a mp3 file from the ftp of LM on a certain player.
- If I get a FALSE on my object, the playing of the mp3 shold stop.

I am able to play the file on the player I want with the old API created by Erwin. But it seems that to stop it when playing is not possible as it always play the complete file. As I am playing a file to indicate that the alarm is triggered, I naturally need the file to stop when I reset the alarm by entering the code.

Is this even possible, or should I simply tell the customer that we need to go for a totally different solution?
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
Hi,

This is the most cleaned methode to do what you need:
Code:
-- Function to execute Sonos requests
function upnpavcmd(host, port, cmd, param)
  local client, soap, reqs, service, res, err
  require('socket')
  client = socket.tcp()
  client:settimeout(3)
  -- try connecting to upnp endpoint
  res, err = client:connect(host, port)
  if not res then
      return nil, err
  end
  -- guess service name based on command
  if cmd == 'SetVolume' or
     cmd == 'GetVolume' or
     cmd == 'SetMute' or
     cmd == 'GetMute' or
     cmd == 'SetBass' or
     cmd == 'GetBass' or
     cmd == 'SetTreble' or
     cmd == 'GetTreble' or
     cmd == 'SetLoudness' or
     cmd == 'GetLoudness' then
    base = 'MediaRenderer'
    service = 'RenderingControl'
  elseif cmd == 'Browse' then
    base = 'MediaServer'
    service = 'ContentDirectory'
  else
    base = 'MediaRenderer'
    service = 'AVTransport'
  end
  -- soap envelope
  soap = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">' ..
           '<s:Body>' ..
             '<u:' .. cmd .. ' xmlns:u="urn:schemas-upnp-org:service:' .. service .. ':1">' ..
               '<InstanceID>0</InstanceID>' ..
               (param or '') ..
             '</u:' .. cmd .. '>' ..
           '</s:Body>' ..
         '</s:Envelope>'
  -- http request   
  reqs = 'POST /' .. base .. '/' .. service .. '/Control HTTP/1.1\r\n' ..
         'CONNECTION: close\r\n' ..
         'HOST: ' .. host .. ':' .. port .. '\r\n' ..
         'CONTENT-LENGTH: ' .. soap:len() .. '\r\n' ..
         'CONTENT-TYPE: text/xml; charset="utf-8"\r\n' ..
         'SOAPACTION: "urn:schemas-upnp-org:service:' .. service .. ':1#' .. cmd .. '"\r\n' ..
         '\r\n' .. soap
  -- send http request
  res, err = client:send(reqs)
  if not res then
    return nil, err
  end
  -- get reply and close connection
  res, err = client:receive('*a')
  client:close()
  return res, err
end


if event.getvalue() == true then
  upnpavcmd('192.168.10.181', 1400, 'SetVolume', '<Channel>Master</Channel><DesiredVolume>30</DesiredVolume>')
  upnpavcmd('192.168.10.181', 1400, 'SetAVTransportURI', '<CurrentURI>x-rincon-mp3radio://http://192.168.0.10/user/deurbel.mp3</CurrentURI><CurrentURIMetaData/>')
  upnpavcmd('192.168.10.181', 1400, 'Play', '<Speed>1</Speed>')
else
  upnpavcmd('192.168.10.181', 1400, 'Pause')
end
BR,

Erwin
Reply
I got it to somewhat work by doing like this:

Code:
if alarm then
  --alert('Brannalarm utløst i ' .. text)
  for _, PlayerID in ipairs(players) do
    --http://127.0.0.1/user/sonos.lp?action=say&uuid=' .. PlayerID .. '&audiofile=' .. audiofile .. '&volume=15&duration=200
    reply = socket.http.request('http://127.0.0.1/user/sonos.lp?action=say&uuid=' .. PlayerID .. '&audiofile=' .. audiofile .. '&volume=80&duration=200')
    log(PlayerID)
  end
  log(alarm, reply)
else
  for _, PlayerID in ipairs(players) do
    reply = socket.http.request('http://127.0.0.1/user/sonos.lp?action=stop&uuid=' .. PlayerID ..'')
  end
  log(alarm, reply)
end

But then there is a delay in this sonos function so that it takes a lot of time to start all the players I have in the list. 

I also now esperienced another challenge; I did a scan in the sonos network to verify my player ID's, and then the log from that scan is too long for the log-window, and I cannot see all players. Is there a way to list only player name and ID? There is a lot of information in the normal scan, and so it is not possible to see the complete result.
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
Hi,

Why are you looping through all players and not using the sayall command?

BR,

Erwin
Reply
(30.06.2020, 22:40)Erwin van der Zwart Wrote: Hi,

Why are you looping through all players and not using the sayall command?

BR,

Erwin
Because I should not use all players, but a selection of them.
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
Hello,

We have a problem with one client and Sonos system. I have installed Sonos app in our LogicMachine. It finds the Sonos and everything is fine till it comes to controlling it – controls are very delayed. For example, if I press pause on a song from the app from LogicMachine, it pauses it after 10-30 seconds. Internet connection is strong (100mbps). The particular Sonos model is „Sonos Connect“ and it is used to stream audio to „Denon“ amplifier. Sonos is connected to internet via cable. Where could be the problem?
Reply
Hi guys !
I don't know if anyone still uses the Sonos app now? I'm using it and haven't seen any errors yet. Has anyone switched to Sonos API's Sonos?
I use Sonos API and have a few questions that I can't answer, I really need your help:
(https://developer.sonos.com/reference/au...ation-api/)
(https://forum.logicmachine.net/showthrea...15&page=14)
-require('custom.sonos.lib') -->Where do I get this library? And where to put in LM5? Sad(
-I also want to add the command line:
Adjust the volume to increase or decrease a certain range.
-sonos_app.SendApiActionCommand(groupID, 'playPlaylist',1) ---This command, it makes my queue add a lot of songs over and over again Sad
-sonos_app.SendApiActionCommand(groupID, 'setPlayModes', 'repeat') --it didn't work for me, even though i tried repeatOne,shuffle,v.v..
--------------------------
I use Sonos app and have a few questions that I can't answer, I really need your help:
-How can I Load 1 Playlists that I have created, for example named Demo1 and Demo2. Because if these playlists can be played, customers can add their own favorite songs Smile . Very helpful
"http://192.168.100.5/user/sonos.lp?action=loadplaylist&uuid=RINCON_F0F6C126547C01400&listname=Demo2&autoplay=true "
I tried the above and it doesn't work! Sad
-How can I play a playlist that I save on LM5 (via ftp is apps)
-Can I get Sonos' status? (eg status play,mute,volume.etc...)
Thank so much everyone !
Reply
(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)

Be aware that in some examples url_groupID is used instead of the correct groupID
So you need to replace this to get it work.


To play your own (doorbell) file using the new Sonos API you just need to follow the steps below.

First we need to add the url as a radiostation in TuneIn.
1. Go to the Browse tab within the Sonos app and select TuneIn.
2. Tap My radio stations.
3. Tap the three dots at the top right and tap Add new radio station.
4. Enter the streaming URL and station name and tap OK.
5. The station will be listed and available in the My radio stations section under TuneIn.
6. Add the station as a fovorite.

Now you can use the new api.
1. Read favorites table to see what id the station got.
favorites = sonos_app.GetStoragePlayerGroupData(groupID, 'Favorites')

2. play favorite by ID
favorite_id = '27'
sonos_app.SendApiActionCommand(groupID, 'playFavorite', favorite_id)
Reply
I added Sonos to LM last week for testing purposes. This worked perfectly (new app --> sonos --> and then it was included in the object list).

Since I was done testing things, I wanted to start back clean I then deleted all objects. But now I can't get the sonos app back in my list of objects. I also deleted and re-added the sonos app in the meantime, but this did not solve anything either.

How do I add sonos to my objects now?

Translated with www.DeepL.com/Translator (free version)
Reply
I didn't use this app for a long time but as far I remember the objects are created when new player is added. Can you delete player from the app?
If not then install Storage viewer, find Sonos storage and delete it.
Make yourself a backup before just in case Smile
------------------------------
Ctrl+F5
Reply
(24.02.2023, 11:06)Daniel Wrote: I didn't use this app for a long time but as far I remember the objects are created when new player is added. Can you delete player from the app?
If not then install Storage viewer, find Sonos storage and delete it.
Make yourself a backup before just in case Smile

Thanks for the help, but it didn't work. Removed everything mention RINCON  (sonos) and re-installed the app... but the object just doesn't appear :-(
Reply
you must click the add widget button, fill or select existing mosaic location and done. If you done it already then in same place is delete button where you can delete it and start over again.
------------------------------
Ctrl+F5
Reply
(24.02.2023, 17:30)Daniel Wrote: you must click the add widget button, fill or select existing mosaic location and done.  If you done it already then in same place is delete button where you can delete it and start over again.

I know, and did that (+ button in the upper right corner to add or remove apps)... doesn't work Huh Sad i did remove the sonos app, then opened storage viewer to remove all other sonos parts, then re-installed sonos... no result :-(
Reply
Can no one help me here?
Reply
Here you add/delete widget as a consequences objects are created/deleted
   
------------------------------
Ctrl+F5
Reply
Hi.

Is it possible to use own created groupadresses for Sonos controller? Or do you have to use the ones that automatic sign by the Sonos app when creates the widgets?
Reply
There is no option to manually map anything there. You can use script to link the objects together.
------------------------------
Ctrl+F5
Reply
(24.02.2023, 18:29)twee_D Wrote:
(24.02.2023, 17:30)Daniel Wrote: you must click the add widget button, fill or select existing mosaic location and done.  If you done it already then in same place is delete button where you can delete it and start over again.

I know, and did that (+ button in the upper right corner to add or remove apps)... doesn't work Huh Sad i did remove the sonos app, then opened storage viewer to remove all other sonos parts, then re-installed sonos... no result :-(

Hi Daniel -

I had the same issue - the connection with SONOS worked except the add widget button.   The solution was to connect all devices to the router and not the MESH network.  The leaves me with the issue on the network but at least the LM is working as a charm.
Reply


Forum Jump: