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.
Need to install gupnp-tools which provides gssdp-discover.
I created a script called discover.sh which takes a parameter of the UUID of a Upnp device and returns the IP address:
Next is a script called source.sh to set the source of the DS:
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):
radio.xml
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:
Enjoy one less thing to do in the morning :)
Here's the api documentation for the DS:
http://docs.linn.co.uk/wiki/index.php/Developer:Davaar
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 discover.sh which takes a parameter of the UUID of a Upnp device and returns the IP address:
#!/bin/sh gssdp-discover -t ${1} -n 3 | grep Location | sed 's/.*http:\/\///' | sed 's/:.....\/.*//'
Next is a script called source.sh to set the source of the DS:
#!/bin/sh curl -X POST -d @${2} $1/Ds/Product/control --header "Content-Type:text/xml" --header "Accept:text/xml" --header "SOAPAction:urn:av-openhome.org:service:Product:1#SetSourceIndex"
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):
radio.xml
<?xml version="1.0"?> <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <u:SetSourceIndex xmlns:u="urn:av-openhome.org:service:Product:1"> <Value>1</Value> </u:SetSourceIndex> </s:Body> </s:Envelope>
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.
#!/bin/sh SCRIPTS=/home/barry/scripts/ds RADIO=${SCRIPTS}/radio.xml UUID=uuid:4c494e4e-0026-0f21-d74b-013330780171 DS=`${SCRIPTS}/discover.sh ${UUID}` ${SCRIPTS}/source.sh ${DS} ${RADIO}
Now just add it to your crontab:
45 6 * * 1-5 /home/barry/scripts/kitchen_radio.sh
Enjoy one less thing to do in the morning :)
Here's the api documentation for the DS:
http://docs.linn.co.uk/wiki/index.php/Developer:Davaar
Comments
Would you have any suggestions on how to do this?
I want to put a DS player in standby from a Raspberry Pi.
Thanks!
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.
Thanks!
1
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 "SOAPAction:urn:av-openhome.org:service:Product:2#SetStandby"
This was written some time ago and I've since moved on to either:
Upnp Playlist Service - this has basic alarm clock functionality
https://github.com/bazwilliams/upnp-playlist-service
Openhome device Python library - this provides a basic python library - you could set standby functionality using this instead.
https://github.com/bazwilliams/openhomedevice
Home Assisant - A Smart Home application that can run on a Raspberry Pi, now supports openhome devices. This is what I use.
https://home-assistant.io/
https://home-assistant.io/components/media_player.openhome/
Let me know how you get on!
I tried that but could't get it to work.
But I found a simpler solution through the Linn Forum.
https://forums.linn.co.uk/bb/showthread.php?tid=16758&pid=429173#pid429173
I have now combined that with your discover.sh and it works very nicely. I will post it soon, once I have cleaned up things.
Thanks for your help!
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 :)
Looks like an very interesting platform and I will investigate further. Thanks for this suggestion!