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 script on homeLynk
#1
hello, i'am  trying to get the sonos script ,i found on the forum, to simulate a doorbell.
when i give the value's to the groupadress manually ( value = 1 " for stopping the current player", value =20 "adding playlist", value = 30 "playing from queue" , value = 19 "clearing current queue") and even getting in it sequence a part of it, but only the stopping of the player gives me a error.

this is a piece of the script i used and partly modified
Code:
-- Action on object value 20
    
if value == 20 and Sonos_Info.sonos_ipaddress ~= nil then

upnpavcmd(Sonos_Info.sonos_ipaddress, 1400, 'Pause') -- here it goes wrong
 
 id = getplaylistid(PL_1)
 if id ~= nil then
   
   -- add playlist to queue
   upnpavcmd(Sonos_Info.sonos_ipaddress, 1400, 'AddURIToQueue', addplaylist(id))
 end
 sleep(1)
 
 -- Start playing with first track in que
    uri_queue = "x-rincon-queue:" .. Sonos_Info.sonos_rincon .. "#0"
    upnpavcmd(Sonos_Info.sonos_ipaddress, 1400, 'SetAVTransportURI', '<CurrentURI>'..uri_queue..'</CurrentURI><CurrentURIMetaData/>')
    upnpavcmd(Sonos_Info.sonos_ipaddress, 1400, 'Play', '<Speed>1</Speed>')
 
 sleep(3)
  -- Clear current queue
    upnpavcmd(Sonos_Info.sonos_ipaddress, 1400, 'RemoveAllTracksFromQueue')
 sleep(1)
 
 -- Set volume to <DesiredVolume>??</DesiredVolume>
    upnpavcmd(Sonos_Info.sonos_ipaddress, 1400, 'SetVolume', '<Channel>Master</Channel><DesiredVolume>' .. Sonos_Volume .. '</DesiredVolume>')

 -- Unmute  
    upnpavcmd(Sonos_Info.sonos_ipaddress, 1400, 'SetMute', '<Channel>Master</Channel><DesiredMute>0</DesiredMute>')
 
    -- Set radio to xx
    upnpavcmd(Sonos_Info.sonos_ipaddress, 1400, 'SetAVTransportURI', '<CurrentURI>x-rincon-mp3radio://' .. URL_1 .. '</CurrentURI><CurrentURIMetaData/>')

    -- Start playing  
    upnpavcmd(Sonos_Info.sonos_ipaddress, 1400, 'Play', '<Speed>1</Speed>')

 
 --Exit script
 return

end

if someone could look into it an d give me hand with it ...
greatings steven
Reply
#2
Hi,

The easiest way to control your Sonos is to install the Sonos app from the appstore, even if you don't plan to use the app you can use the API that is build in to control your Sonos devices, by installing the app you automaticly have access to that API.

Look into this thread to see all possible commands to the Sonos App API: https://forum.logicmachine.net/showthread.php?tid=415

BR,

Erwin
Reply
#3
hi Erwin,
thanks for the reply. I thought the app store was exclusive for LM because i didn't found him, but after looking around i found it .

thank you so much !!!!
Reply
#4
hi Erwin,
 i installed the sonos app but still i'am struggling with the doorbell function.
i uploaded the sound file to the homelynk ftp/user, and its there i cheked it, but when i execute the script the player stops playing the current radio station and in the sonos app the file name witch i uploaded gets loaded in the player but it wound play , when i hit the play button i'am getting the message "can't play <soundfile>, becuase server can't be reached".

 local reply = socket.http.request('http://admin:put7856@192.168.0.203/apps/data/sonos/sonos.lp?action=say&name=Keuken&audiofile=ftp://apps:apps@192.168.0.203/user/there_is_someone_at_the_door.mp3&volume=30&duration=5')

i'am using firmware 2.0.1

i hope you can help me out .
greatings steven
Reply
#5
You need to escape the audiofile parameter and it's better to use http to access files in user folder:
Code:
require('socket.url')
audiofile = socket.url.escape('http://192.168.0.203/user/there_is_someone_at_the_door.mp3')
reply = socket.http.request('http://admin:put7856@192.168.0.203/apps/data/sonos/sonos.lp?action=say&name=Keuken&audiofile=' .. audiofile .. '&volume=30&duration=5')
Reply


Forum Jump: