Friday, December 20, 2013

Linn DS Alarm Function

Update 2014 - An alternative to this is available on GitHub which uses Node.js and should be cross platform. Linn DS Playlist and Alarm Server

Switching the radio on in the kitchen in the morning is a low priority amongst setting table, pouring cereals, carrying children, etc. The Sonos has an alarm clock facility which allows you to switch on the radio at a set time avoiding hassle of starting a controller.

When I upgraded to my Linn Sneaky DS, I no longer had this function, though the remote control made it easy if I forgot to take my phone downstairs with me.

Last week I decided to figure it out. I have a Linux machine which runs Ubuntu and runs all the media servers, backups and network shares. I decided to investigate how to control my DS from the command line.

Conveniently, the DS can be controlled via a web api, so after reading the docs and a few examples I was able to switch off and on and change source via Postman (Chrome REST client).

I then set about writing a curl script to send the commands and package this up as a shell script.

One final problem was discovering the IP address of the DS which I solved by using gupnp-tools which has a scanner; this scans my network for UPNP devices and since I know the UUID of the DS I can extract the correct IP address.

By adding the script to my Linux box' crontab, the DS starts on the radio each weekday morning.

How it works

Need to install gupnp-tools which provides gssdp-discover.

I created a script called which takes a parameter of the UUID of a Upnp device and returns the IP address:

gssdp-discover -t ${1} -n 3 | grep Location | sed 's/.*http:\/\///' | sed 's/:.....\/.*//'

Next is a script called to set the source of the DS:

curl -X POST -d @${2} $1/Ds/Product/control --header "Content-Type:text/xml" --header "Accept:text/xml" --header ""

This takes in 2 parameters, the first is the IP address of the device you want to control and the second is a file containing an XML body containing details of which source to set on the device, in this case, it is the radio function (source Id 1):

<?xml version="1.0"?>
<s:Envelope xmlns:s="">
  <s:Body s:encodingStyle="">
    <u:SetSourceIndex xmlns:u="">

Finally it's all put together in the following script. Set the SCRIPTS property to where you've saved the files above. Set the UUID property to the UUID of your DS - you'll need to scan your network to find this. In Windows, my DSs appear in the network view of Windows Explorer and I can see the unique identifier (UUID) if I right click the DS and view properties.


Now just add it to your crontab:
45 6 * * 1-5 /home/barry/scripts/

Enjoy one less thing to do in the morning :)

Here's the api documentation for the DS:


Guussie said...

Hi barry, I have tried to modify your code in order to put a DS player in StandBy but I can't get it to work.

Would you have any suggestions on how to do this?

I want to put a DS player in standby from a Raspberry Pi.


Guussie said...

I ahem tried to modify your code with the objective to put a DS player in StandBy but can't get it to work.

The discover code works but I seem to have mistakes in the xml portion.

Would you be able to point me in the right direction?

I want to switch off a DSi from a Raspberry Pi.


Barry said...

To put the Ds into standby, you'd need to use the Product service. Assuming Davaar > 50, the Xml will look something like this:


And the command would look a bit like:

curl -X POST -d @${2} $1/Ds/Product/control --header "Content-Type:text/xml" --header "Accept:text/xml" --header ""

This was written some time ago and I've since moved on to either:

Upnp Playlist Service - this has basic alarm clock functionality

Openhome device Python library - this provides a basic python library - you could set standby functionality using this instead.

Home Assisant - A Smart Home application that can run on a Raspberry Pi, now supports openhome devices. This is what I use.

Let me know how you get on!

Barry said...

That's annoying - XML doesn't work in Blogger comments :(

Barry said...

Basically replace SetSourceIndex with SetStandby

Guussie said...

> Basically replace SetSourceIndex with SetStandby

I tried that but could't get it to work.

But I found a simpler solution through the Linn Forum.

I have now combined that with your and it works very nicely. I will post it soon, once I have cleaned up things.

Thanks for your help!

Barry said...

No worries.

I would recommend the Home Assistant solution though - hooks into any other smart home equipment you may have - including Alexa or Google Home.

Great having my Ds switch off when I leave the house and change colour based on the source!

I wrote the openhome support :)

Guussie said...

I installed the Home Assistant on my test rig. Seems to work OK but the openhome component does not install correctly, even after updating the configuration file.

Looks like an very interesting platform and I will investigate further. Thanks for this suggestion!

Guussie said...