Welcome to Smart Home Forum by FIBARO
Dear Guest,
as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.
As a member you can:
- Start new topics and reply to others
- Follow topics and users to get email updates
- Get your own profile page and make new friends
- Send personal messages
- ... and learn a lot about our system!
Regards,
Smart Home Forum by FIBARO Team

Question
pbtinus 0
Hi, I'm not a LUA specialist but I like to make my own LUA scenes and quickapps mostly by trial en error, alot of Googling and ofcourse Chatgpt
after strugling for a few weeks I need some help because I'M stuck....
I use a standard sonos player that I can adjust and add funtions to like selecting the line-in on my sonos five to play a record.
but now im struggling to get spotify working. (or playing a sonos favorite) by pressing a button in my sonos quickapp.
The QA I would like to create is a simple player with a couple of buttons to select playlists or favorites (layout as attachment)
Is there anybody that can help me with the correct code? (chatgpt has helped me a lot but i cant get it to work ... )
the URI im using that doestnt work: "x-sonos-spotify:spotify:playlist:7jBDsDWvg7FXEqo91CcUpE?sid=9" or "x-sonos-spotify:playlist:7jBDsDWvg7FXEqo91CcUpE?sid=9"
if I change it into a single track, it works.
complete code for the button:
function QuickApp:hard()
-- De URI van de Sonos-favoriet voor Tinus Soft
local favoriteUri = "x-sonos-spotify:spotify:playlist:7jBDsDWvg7FXEqo91CcUpE?sid=9"
-- Controleer of favoriteUri een geldige string is
if not favoriteUri or type(favoriteUri) ~= "string" then
print("❌ Ongeldige favorite URI")
return
end
-- Controleer of AVTRANSPORT_URI is ingesteld
if not self.AVTRANSPORT_URI then
print("❌ Fout: AVTRANSPORT_URI is niet ingesteld.")
return
end
-- Log de URI voor debugging
print("📡 Verzenden van URI naar Sonos: " .. favoriteUri)
-- Maak het XML-verzoek voor de AVTransport-service
local function createAvTransportBody(uri)
return string.format(
'<u:SetAVTransportURI xmlns:u="urn:schemas-upnp-org:service:AVTransport:1">' ..
'<InstanceID>0</InstanceID>' ..
'<CurrentURI>%s</CurrentURI>' ..
'<CurrentURIMetaData></CurrentURIMetaData>' ..
'</u:SetAVTransportURI>',
uri
)
end
local requestBody = createAvTransportBody(favoriteUri)
-- Verzend het verzoek naar Sonos om de URI in te stellen
self:sendRequest(
self.AVTRANSPORT_URI,
'"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI"',
requestBody,
function(data)
if data then
print("✅ Tinus Soft favorite is succesvol ingesteld!")
-- Controleer of de play-functie bestaat
if self.play and type(self.play) == "function" then
print("▶️ Afspelen van de playlist...")
self:play()
else
print("⚠️ Fout: play-functie bestaat niet of is niet aanroepbaar.")
end
else
print("⚠️ Geen respons van Sonos bij het instellen van de favorite.")
end
end,
function(error)
print("❌ Fout bij verzenden van verzoek naar Sonos: " .. tostring(error))
end
)
end
Please login or register to see this link.
2 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.