Logic Machine Forum
Sonos radio control through KNX - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Sonos radio control through KNX (/showthread.php?tid=3463)



Sonos radio control through KNX - Jayce - 07.07.2021

Hi,

I've tried to connect two sonos speakers into KNX with the Sonos app in LM app store which works. The thing I need to do is to control everything through scripting, to create sort of my own app inside visualization or mosaic. Is there a way to send command to sonos through KNX script to turn on particular radio? I've tried the command in the example, doesn't work even as shown in the example. Also in case the link itself in the example is simply dead, which formats can I send and play? 
-I've seen this one being m3u but there are more radio formats like .pls or .mp3, is it possible to use these? 
-Is there a way to send a command for a particular spotify playlist?


RE: Sonos radio control through KNX - Daniel - 07.07.2021

Read this very long thread and everything should be clear.
https://forum.logicmachine.net/showthread.php?tid=415&pid=2101#pid2101


RE: Sonos radio control through KNX - Jayce - 09.07.2021

Hi,

I've read the whole thread but I'm still a bit confused since it's a bit old and a new version has came out. I don't know which stuff is actual and which is not. However i've gotten into a point, where I have few radio stations in Sonos APP in LM (favourites section). All I need now is a command to make speaker (or group of speakers) to play whatever is in the favourites, in this case a radio.


RE: Sonos radio control through KNX - Daniel - 09.07.2021

There were two apps over time, old which use older Sonos API which might stop working and new app which use new Sonos API.
If you want to use new app via script you have to fallow this:
https://forum.logicmachine.net/showthread.php?tid=415&pid=13969#pid13969
Some features in new app are not possible so users still use the old libraries to use more features. To use old way you need to upload libraries manually: https://forum.logicmachine.net/showthread.php?tid=415&pid=12301#pid12301
If you use scripts provided make sure location of libraries are correct in the script.


RE: Sonos radio control through KNX - Erwin van der Zwart - 09.07.2021

I created this for Schneider Electric Germany, maybe it is what you are looking for..

.lua   Select Sonos with IP to control playlist number with 0 to 99 and favorites with 100 to 199 with a byte value with 250 byte feedback of active selected.lua (Size: 17.81 KB / Downloads: 83)



RE: Sonos radio control through KNX - jamesng - 02.09.2022

(09.07.2021, 16:57)Erwin van der Zwart Wrote: I created this for Schneider Electric Germany, maybe it is what you are looking for..

I've been using Erwin's script on a Schneider CBUS SHAC (which doesn't have the ability to run apps) with good results, however the old UPNP code doesn't seem to support loading of Apple Music Playlists into the Sonos queue -  I suspect because they have a media type of x-rincon-cpcontainer which the Sonos devices treat differently to other playlists or streams.

By chance would you know the the UPNP command to load this playlist type?   I've combed through the previously posted variants of the SONOS scripts here on the forum but haven't been able to find a solution.

I think it requires an extra condition here for the mediatype 'x-rincon-cpcontainer' but I'm not sure what the upnp data format is - I suspect a variant of below.

Code:
if mediatype == 'x-sonosapi-stream'then

upnpavcmd(SonosDetails.sonos_ipaddress, 1400, 'SetAVTransportURI', '<CurrentURI>' .. sanitize(FavoritesTable[FavoriteNr].trackuri) .. '</CurrentURI><CurrentURIMetaData>' .. FavoritesTable[FavoriteNr].trackurimetadata .. '</CurrentURIMetaData>')


Here is the URI and MetaData that sonos returns from the playlist / favourite

Code:
["mediatype"]
* string: x-rincon-cpcontainer

["trackuri"]
  * string: x-rincon-cpcontainer:1006206clibraryplaylist:p.vB5KhgB44v?sid=204&flags=8300&sn=2

["trackurimetadata"]
  * string: <DIDL-Lite xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:r="urn:schemas-rinconnetworks-com:metadata-1-0/" xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/"><item id="1006206clibraryplaylist:p.vB5KhgB44v" parentID="00080024libraryfolder:f.4" restricted="true"><dc:title>Avici</dc:title><upnp:class>object.container.playlistContainer.#PlaylistView</upnp:class><desc id="cdudn" nameSpace="urn:schemas-rinconnetworks-com:metadata-1-0/">SA_RINCON52231_X_#Svc52231-0-Token</desc></item></DIDL-Lite>

["description"]
  * string: Apple Music Playlist

My attempted update the the code below doesn't work!

Code:
if mediatype == 'x-rincon-cpcontainer' then

upnpavcmd(SonosDetails.sonos_ipaddress, 1400, 'SetAVTransportURI', '<CurrentURI>' .. sanitize(FavoritesTable[FavoriteNr].trackuri) .. '</CurrentURI><CurrentURIMetaData>' .. FavoritesTable[FavoriteNr].trackurimetadata .. '</CurrentURIMetaData>')



Many thanks in advance

Kind Regards
James


RE: Sonos radio control through KNX - admin - 02.09.2022

Not sure if will help but the second : in trackuri should be URL-encoded:
Code:
x-rincon-cpcontainer:1006206clibraryplaylist%3ap.vB5KhgB44v?sid=204&flags=8300&sn=2



RE: Sonos radio control through KNX - jamesng - 03.09.2022

We're using Erwin's sanitize function to URL encode the data in the upnp command.  I've tried with both an encoded and normal : and it doesn't seem to change the outcome

Here the Illegal Mime Type error from the upnpavcmd post - I'm not sure how to resolve though.

Code:
* arg: 1
  * string: HTTP/1.1 500 Internal Server Error
CONTENT-LENGTH: 347
CONTENT-TYPE: text/xml; charset="utf-8"
EXT:
Server: Linux UPnP/1.0 Sonos/69.1-32100 (ZPS16)
Connection: close


<s:Envelope
xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<s:Fault>
<faultcode>s:Client</faultcode>
<faultstring>UPnPError</faultstring>
<detail>
<UPnPError
xmlns="urn:schemas-upnp-org:control-1-0">
<errorCode>714</errorCode>
</UPnPError>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>

Thanks again for any suggestions / help.

Kind Regards
James