Jump to content
  • 1
Guest deraaij

Sonos - Virtual Device

Question

Guest deraaij

Update: Please use TCP as of version 3.x as os.execute has been depreciated. As soon as we are able to have custom headers I will update the LUA code.

Hi all,

For those who are interested I made a Virtual Device based on the new LUA feature (inspired on lua code for MIOS) which can control a sonos device. It uses curl but will change it when the http api is documented. Change the IP address accruing to your needs.

EDIT: Added additional comments from other post which I posted in this thread.

EDIT: Changed req.lua --> /tmp/req.lua which works with beta 3.423 & 3.424

Play

Please login or register to see this code.

Stop

Please login or register to see this code.

Pause

Please login or register to see this code.

Previous

Please login or register to see this code.

Next

Please login or register to see this code.

Mute

Please login or register to see this code.

UnMute

Please login or register to see this code.

Volume – Not Working yet because we do not get the value off: _sliderValue_ @fibaro how does this work with Lua?

Please login or register to see this code.

Example Text-2-Speech using LUA in a scene:

Please login or register to see this code.

Remark: Play is initiated with the last statement to actual play the text (change it accordingly).

Example play song from network with LUA:

Please login or register to see this code.

Remark: Play is initiated with the last statement to actual play the song (change it accordingly).

Example radio station via LUA:

Please login or register to see this code.

Remark: Play is initiated with the last statement to actual play radio (change it accordingly). For now only the radio name is set.

Regards,

Mark[/b]

Share this post


Link to post
Share on other sites

Recommended Posts

  • 0
Guest deraaij
  • Inquirer
  • With this code you can make scenes talk via son0s:

    Please login or register to see this code.

    Share this post


    Link to post
    Share on other sites
    • 0
    Guest deraaij
  • Inquirer
  • Hi all,

    I have been playing around and found out that it also works when just using TCP commands. Also the volumeslider works. If you add commands be aware to change the content Length in line with the length of the body message.

    EDIT: Added additional comments from other post which I posted in this thread.

    EDIT: Added way to get your own radio station.

    Play

    Please login or register to see this code.

    Stop

    Please login or register to see this code.

    Pause

    Please login or register to see this code.

    Previous

    Please login or register to see this code.

    Next

    Please login or register to see this code.

    Mute

    Please login or register to see this code.

    UnMute

    Please login or register to see this code.

    Volume

    Please login or register to see this code.

    Example Text-2-Speech using TCP:

    Please login or register to see this code.

    Remark: adjust lenght accoring to Soap body. And play needs to be initiated to actual play the text.

    Example play song from network with TCP:

    Please login or register to see this code.

    Remark: adjust lenght accoring to Soap body. And play needs to be initiated to actual play the song.

    Example radio station via TCP:

    Please login or register to see this code.

    Remark: adjust lenght accoring to Soap body. And play needs to be initiated to actual play radio.

    Ok, to get the correct url for your radio station do the following:

    1.) Play correct radio station on a zone.

    2.) Surf to http://<>:1400/status/radiolog

    3.) Take the correct url, and replace the one in the example code (

    Please login or register to see this code.

    ).

    Ungroup zone option 1

    Please login or register to see this code.

    Ungroup zone option 2

    This one proved to be a bit more stable for some users.

    Please login or register to see this code.

    Group to zone

    First check :1400/status/topology the UUID of your main zone, e.g: RINCON_000E58226B1601400

    Please login or register to see this code.

    Be aware that if you copy and paste the TCP variant it add's some spaces which you have to delete manually. After save of the radio variants html encoded text is changed to normal chars if you make a change and save it again it will not work.

    Regards,

    Mark

    Share this post


    Link to post
    Share on other sites
    • 0
    I have been playing around and found out that it also works when just using TCP commands. Also the volumeslider works. If you add commands be aware to change the content Length in line with the length of the body message.

    Hi Mark,

    Can you give more information on how to use the TCP commands?

    In LUA i can control Sonos but have the same issue as you discribe earlier.

    After adding a virtual device with ip number x.x.x.x and TCP port 1400 and a button with one of the tcp commands doesn't give any result.

    Thanks a lot!

    Ruud

    Share this post


    Link to post
    Share on other sites
    • 0
    Guest deraaij
  • Inquirer
  • I have been playing around and found out that it also works when just using TCP commands. Also the volumeslider works. If you add commands be aware to change the content Length in line with the length of the body message.

    Hi Mark,

    Can you give more information on how to use the TCP commands?

    In LUA i can control Sonos but have the same issue as you discribe earlier.

    After adding a virtual device with ip number x.x.x.x and TCP port 1400 and a button with one of the tcp commands doesn't give any result.

    Thanks a lot!

    Ruud

    Hi Ruud,

    Be aware that if you copy & paste it adds some unwanted trailing spaces. If you remove those it will work

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    Regards,

    Mark

    Share this post


    Link to post
    Share on other sites
    • 0
    Guest deraaij
  • Inquirer
  • Thank you!

    You are welcome!

    This weekend I finished a python script which receives an update from the sonos as soon as something changes (Paused --> playing et cetera). I will post the info shortly.

    I use it to set my receiver to on and the correct input when someones hits play on the particular zone.

    Regards,

    Mark

    Share this post


    Link to post
    Share on other sites
    • 0
    Guest deraaij
  • Inquirer
  • Hi I got some question on playing song and/or radio. So i want to share some more examples:

    Example Text-2-Speech using LUA in a scene:

    Please login or register to see this code.

    Remark: Play is initiated with the last statement to actual play the text (change it accordingly).

    Example Text-2-Speech using TCP:

    Please login or register to see this code.

    Remark: adjust lenght accoring to Soap body. And play needs to be initiated to actual play the text.

    Example play song from network with LUA:

    Please login or register to see this code.

    Remark: Play is initiated with the last statement to actual play the song (change it accordingly).

    Example play song from network with TCP:

    Please login or register to see this code.

    Remark: adjust lenght accoring to Soap body. And play needs to be initiated to actual play the song.

    Example radio station via LUA:

    Please login or register to see this code.

    Remark: Play is initiated with the last statement to actual play radio (change it accordingly). For now only the radio name is set.

    Example radio station via TCP:

    Please login or register to see this code.

    Remark: adjust lenght accoring to Soap body. And play needs to be initiated to actual play radio.

    Be aware that if you copy and paste the TCP variant it add's some spaces which you have to delete manually. After save of the radio variants html encoded text is changed to normal chars if you make a change and save it again it will not work.

    In case of questions let me know.

    Regards,

    Mark

    Share this post


    Link to post
    Share on other sites
    • 0

    Wonderful job deraaij!!!

    with the control and text2speech it's time for me to buy some Sonos 3 for my rooms.

    What about the sound quality? is really good?

    I was thinking to buy Bose, but now I think I wll buy the Sonos system.

    Regards

    Share this post


    Link to post
    Share on other sites
    • 0

    Thank you so much! This is great!! + voice function! Absoluteley amazing!!!

    If you come up with more commands/functions please let us know

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/smile@2x.png 2x" width="20" height="20" />

    Share this post


    Link to post
    Share on other sites
    • 0
    Guest deraaij
  • Inquirer
  • Wonderful job deraaij!!!

    with the control and text2speech it's time for me to buy some Sonos 3 for my rooms.

    What about the sound quality? is really good?

    I was thinking to buy Bose, but now I think I wll buy the Sonos system.

    Regards

    Your welcome!

    It depends on the size of the room which sonos is the best option. I have all the types and I am very happy with them. I would only not recommend the play:3 for a big room.

    Thank you so much! This is great!! + voice function! Absoluteley amazing!!!

    If you come up with more commands/functions please let us know

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/smile@2x.png 2x" width="20" height="20" />

    Your welcome! I hope I have time to include art when playing a radio station.

    I also have a python script which can trigger a scene when a sonos starts playing. If some one is interested I will post it.

    Regards,

    Mark

    Share this post


    Link to post
    Share on other sites
    • 0

    Hi,

    Very interesting !

    Can you advise on what is possible to do with V1.045 using http within a virtual device, please

    Thanks,

    YG

    www.ghafoor.org

    Share this post


    Link to post
    Share on other sites
    • 0
    Guest deraaij
  • Inquirer
  • Hi,

    Very interesting !

    Can you advise on what is possible to do with V1.045 using http within a virtual device, please

    Thanks,

    YG

    www.ghafoor.org

    You can use the TCP versions. Those work both in the beta and the stable version. Lua is only available in the beta release.

    Regards,

    Mark

    Share this post


    Link to post
    Share on other sites
    • 0

    Your welcome! I hope I have time to include art when playing a radio station.

    I also have a python script which can trigger a scene when a sonos starts playing. If some one is interested I will post it.

    Regards,

    Mark

    Thank you:), I am definately interested, but Im not that familiar with python scripting. Hope you can explain a little... Perhaps give a step by step guide or link to necessary documentation.

    Thanks again for your support.

    Share this post


    Link to post
    Share on other sites
    • 0
    Guest deraaij
  • Inquirer
  • Hi am not a real programmer but it works. You need python and the twisted library:

    Please login or register to see this code.

    Obviously it will work in any other program language.

    Regards,

    Mark

    Share this post


    Link to post
    Share on other sites
    • 0

    Thank you! Looks interesting!

    I was wondering if you have any solution to group all zones in house. In case of a fire alarm I want all zones to play a message on repeat. Now I have the solution for message and repeat (see below). But is there any command that I can group all zones??

    "Repeat all" command:

    POST /MediaRenderer/AVTransport/Control HTTP/1.1

    Content-Length: 308

    SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#SetPlayMode"

    0

    REPEAT_ALL

    0x0D0x0A0x0D0x0A

    Share this post


    Link to post
    Share on other sites
    • 0
    Guest deraaij
  • Inquirer
  • Thank you! Looks interesting!

    I was wondering if you have any solution to group all zones in house. In case of a fire alarm I want all zones to play a message on repeat. Now I have the solution for message and repeat (see below). But is there any command that I can group all zones??

    "Repeat all" command:

    POST /MediaRenderer/AVTransport/Control HTTP/1.1

    Content-Length: 308

    SOAPACTION: "urn:schemas-upnp-org:service:AVTransport:1#SetPlayMode"

    0

    REPEAT_ALL

    0x0D0x0A0x0D0x0A

    Hi I had a look for you:

    First check :1400/status/topology the UUID of your main zone, e.g: RINCON_000E58226B1601400.

    Second step is to make sure no zone is grouped (per ip adress):

    Please login or register to see this code.

    Third step add members per IP Adress to one main zone (using the RINCON ID from step 1):

    Please login or register to see this code.

    Of course you could use LUA to loop through a list of IP adresses, but you have all the info to continue

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/smile@2x.png 2x" width="20" height="20" />

    Regards,

    Mark

    Share this post


    Link to post
    Share on other sites
    • 0

    Thanks, this is awesome!!

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/smile@2x.png 2x" width="20" height="20" /> Great job!

    Share this post


    Link to post
    Share on other sites
    • 0
    Guest deraaij
  • Inquirer
  • Thanks, this is awesome!!

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/smile@2x.png 2x" width="20" height="20" /> Great job!

    You're welcome!

    Share this post


    Link to post
    Share on other sites
    • 0
    Guest deraaij
  • Inquirer
  • You can also ungroup a zone by:

    Please login or register to see this code.

    Share this post


    Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

    ×