Posts: 185
Threads: 38
Joined: Feb 2017
Reputation:
3
(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
Posts: 1770
Threads: 6
Joined: Jul 2015
Reputation:
118
29.06.2020, 14:06
(This post was last modified: 29.06.2020, 14:07 by Erwin van der Zwart.)
Hi,
Try this script, it is stand alone and it does not uses any of the (old) Sonos App files
BR,
Erwin
Posts: 185
Threads: 38
Joined: Feb 2017
Reputation:
3
30.06.2020, 08:00
(This post was last modified: 30.06.2020, 08:18 by Trond Hoyem.)
(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
Posts: 1770
Threads: 6
Joined: Jul 2015
Reputation:
118
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
Posts: 185
Threads: 38
Joined: Feb 2017
Reputation:
3
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
Posts: 1770
Threads: 6
Joined: Jul 2015
Reputation:
118
Hi,
Why are you looping through all players and not using the sayall command?
BR,
Erwin
Posts: 185
Threads: 38
Joined: Feb 2017
Reputation:
3
(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
Posts: 57
Threads: 28
Joined: May 2018
Reputation:
1
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?
Posts: 215
Threads: 65
Joined: Sep 2015
Reputation:
0
09.04.2022, 02:42
(This post was last modified: 13.04.2022, 01:35 by phongvucba.)
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? (
-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
-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 . 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!
-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 !
Posts: 113
Threads: 15
Joined: Nov 2019
Reputation:
6
28.01.2023, 16:06
(This post was last modified: 28.01.2023, 16:42 by Joep.)
(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)
Posts: 5
Threads: 1
Joined: Feb 2023
Reputation:
0
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)
Posts: 4694
Threads: 24
Joined: Aug 2017
Reputation:
213
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
------------------------------
Ctrl+F5
Posts: 5
Threads: 1
Joined: Feb 2023
Reputation:
0
(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
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 :-(
Posts: 4694
Threads: 24
Joined: Aug 2017
Reputation:
213
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
Posts: 5
Threads: 1
Joined: Feb 2023
Reputation:
0
24.02.2023, 18:29
(This post was last modified: 24.02.2023, 18:30 by twee_D.)
(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 i did remove the sonos app, then opened storage viewer to remove all other sonos parts, then re-installed sonos... no result :-(
Posts: 5
Threads: 1
Joined: Feb 2023
Reputation:
0
Posts: 4694
Threads: 24
Joined: Aug 2017
Reputation:
213
Here you add/delete widget as a consequences objects are created/deleted
------------------------------
Ctrl+F5
Posts: 92
Threads: 16
Joined: Jan 2020
Reputation:
2
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?
Posts: 4694
Threads: 24
Joined: Aug 2017
Reputation:
213
There is no option to manually map anything there. You can use script to link the objects together.
------------------------------
Ctrl+F5
Posts: 7
Threads: 4
Joined: May 2022
Reputation:
0
(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 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.
|