Author Topic: SONOS LUUP code help  (Read 321 times)

Offline Eilskov

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
SONOS LUUP code help
« on: March 31, 2018, 05:26:01 pm »
Hi i am trying to create some code that prevent the SONOS to start every time the motion trigger. So if music is playing, it should not run the scene.

And what I did is not working. :-(

local DEVICE_NO  = 241 -- the SONOS device number
local SS_SID = "urn:schemas-micasaverde-com:device:Sonos:1" -- the SONOS speaker service ID
 
local playstate = luup.variable_get (SS_SID, "TransportState", DEVICE_NO)
 
if playstate = "PLAYING" then
    return true
else
    return false
end

Online akbooer

  • Master Member
  • *******
  • Posts: 5964
  • Karma: +258/-69
  • "Less is more"
Re: SONOS LUUP code help
« Reply #1 on: March 31, 2018, 05:49:41 pm »
So if music is playing, it should not run the scene.

This requirement means that you should return false to stop the scene when music is playing.  Your code, therefore, needs to return the opposite result of what you had.  Try this...

Code: [Select]
local DEVICE_NO  = 241 -- the SONOS device number
local SS_SID = "urn:schemas-micasaverde-com:device:Sonos:1" -- the SONOS speaker service ID
 
local playstate = luup.variable_get (SS_SID, "TransportState", DEVICE_NO)
 
return  playstate ~= "PLAYING"

...assuming you have the correct variable and value here.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline Eilskov

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: SONOS LUUP code help
« Reply #2 on: March 31, 2018, 07:09:05 pm »
Thanks for your help.

That code failed for some reason. But you pointed me in a direction. I will try:

local DEVICE_NO  = 241 -- the SONOS device number
local SS_SID = "urn:schemas-micasaverde-com:device:Sonos:1" -- the SONOS speaker service ID
 
local playstate = luup.variable_get (SS_SID, "TransportState", DEVICE_NO)
 
if playstate == "PLAYING" then
    return false
else
    return true
end

testing that.

Offline Eilskov

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: SONOS LUUP code help
« Reply #3 on: March 31, 2018, 07:31:50 pm »
seems like the PLAYSTATE parameter is not being set correct??

Offline Eilskov

  • Newbie
  • *
  • Posts: 8
  • Karma: +0/-0
Re: SONOS LUUP code help
« Reply #4 on: April 01, 2018, 04:35:07 am »
This worked:

local DEVICE_NO  = 241 -- the SONOS device number
local SS_SID = "urn:upnp-org:serviceId:AVTransport" -- the SONOS speaker service ID
 
local playstate = luup.variable_get (SS_SID, "TransportState", DEVICE_NO)
 
if playstate == "STOPPED" then
    return true
else
    return false
end