Jump to content

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


  • 3

Sonos - Virtual Device


Guest deraaij

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]

Link to comment
Share on other sites

Recommended Posts

  • 0
Guest deraaij
  • Inquirer
  • Hi,

    1) Changed original LUA and TCP post to include other commands which were listed in different post in this thread.

    2) Changed LUA so it works with latest beta (3.424 & 3.423)

    Regards,

    Mark

    Link to comment
    Share on other sites

    • 0
    Guest deraaij
  • Inquirer
  • Hi Mark,

    I am just about to start testing LUA so any hints regarding what has changed would be great.

    Sorry:

    It is writing the temp file now to /tmp/ which is neater and the old path gave issues now. (although i use the tvp variant).

    Link to comment
    Share on other sites

    • 0
    Guest merylion
  • Inquirer
  • Hello,

    I am thinking about controlling sonos and Fibaro from computer application.

    To do it I am thinking to create C++ program and get it compiled into executable file

    Was anyone trying anything similar before?

    What I need is to be able to change global variable in Fibaro and just send play command to Sonos.

    Thank you in advance for help

    Also does anyone have code examples for queue few files played from network location?

    I wanted to make playlist of few mp3s played one after one

    Can anyone help on this?

    Marcin

    [ Added: 2013-03-14, 22:20 ]

    Hi All,

    After removing os.execute function in newest beta version

    Can you tell me which type of scripts I can use in LUA for controlling of Sonos?

    Thanks for answer

    Marcin

    [ Added: 2013-04-05, 12:04 ]

    Hi,

    I just started implementing :

    Please login or register to see this code.

    And can not get it working.

    So step by step:

    I am creating Virtual Device with IP address of my Sonos.

    Port I have set to 1400

    In advance tab I am crating new button and pasting above code.

    Trying to invoke this button gives nothing.

    WireShark are showing no telegrams being send from Fibaro to Sonos.

    I have seen that in some comments here I has been written that some spaces should be deleted in code (which spaces - I was trying many times different configurations) or/and adjusting content-length value - how to calculate this value propertly?

    I have HC2 v3.525 software

    Can anyone help?

    Best Regards

    Marcin

    Link to comment
    Share on other sites

    • 0

    Does this LUA code still work in the latest beta 3.544 of the firmware, or was the os.execute command removed?

    I'm not getting any response from my play/stop buttons.

    Link to comment
    Share on other sites

    • 0

    Hi,

    I just tried all the buttons in the first post, however I couldn't get it to work. Does this solution still work with the latest HC2 software versions or was this only for the older ones?

    Link to comment
    Share on other sites

    • 0
    Guest deraaij
  • Inquirer
  • Hi,

    I just tried all the buttons in the first post, however I couldn't get it to work. Does this solution still work with the latest HC2 software versions or was this only for the older ones?

    You should use the TCP version, LUA doesn't work anymore will update first post.

    Link to comment
    Share on other sites

    • 0

    Mark,

    the TCP version of the volume slider does not work with my system.

    It is also very strange that when i delete a certain button then another button of the sonos suddenly doesn't work anymore. Do you have al list of all functions that are available for sonos. Is there a site somewhere you can lookup all available commands ?

    Can you post a txt file with all your commands you have working so far ?

    The content length is the number of chars for the whole envelope ?

    Regards,

    Wesley

    Link to comment
    Share on other sites

    • 0
    Hi,

    I just tried all the buttons in the first post, however I couldn't get it to work. Does this solution still work with the latest HC2 software versions or was this only for the older ones?

    You should use the TCP version, LUA doesn't work anymore will update first post.

    Thanks, I added it, but I still can't get the text to speech to work. How do I initiate a play after the TCP command?

    Link to comment
    Share on other sites

    • 0
    Guest deraaij
  • Inquirer
  • Mark,

    the TCP version of the volume slider does not work with my system.

    It is also very strange that when i delete a certain button then another button of the sonos suddenly doesn't work anymore. Do you have al list of all functions that are available for sonos. Is there a site somewhere you can lookup all available commands ?

    Can you post a txt file with all your commands you have working so far ?

    The content length is the number of chars for the whole envelope ?

    Regards,

    Wesley

    Hi All the TCp commands in the third post are working for me. There is a bug with virtual devices when you delete buttons so as a workaround I would make a new one and don't delete any buttons. Make sure when you copy and paste that there are no spaces added behind the commands. Correct it is the complete envelope. When you paste commands with html tags you can only save it once so store your commands also locally.

    [ Added: 2013-04-27, 17:30 ]

    Hi,

    I just tried all the buttons in the first post, however I couldn't get it to work. Does this solution still work with the latest HC2 software versions or was this only for the older ones?

    You should use the TCP version, LUA doesn't work anymore will update first post.

    Thanks, I added it, but I still can't get the text to speech to work. How do I initiate a play after the TCP command?

    You should make a scene which executes two buttons, first the text-2-speech and next the play button. (till a LUA option is available again).

    Link to comment
    Share on other sites

    • 0
    Hi,

    I just tried all the buttons in the first post, however I couldn't get it to work. Does this solution still work with the latest HC2 software versions or was this only for the older ones?

    You should use the TCP version, LUA doesn't work anymore will update first post.

    Thanks, I added it, but I still can't get the text to speech to work. How do I initiate a play after the TCP command?

    You should make a scene which executes two buttons, first the text-2-speech and next the play button. (till a LUA option is available again).

    Is there any way to make the sonos continue playing what it was prior to the T2S command? It works that way in Vera but would rather use the HC2 for it...

    Link to comment
    Share on other sites

    • 0
    Guest deraaij
  • Inquirer
  • Hi,

    I just tried all the buttons in the first post, however I couldn't get it to work. Does this solution still work with the latest HC2 software versions or was this only for the older ones?

    You should use the TCP version, LUA doesn't work anymore will update first post.

    Thanks, I added it, but I still can't get the text to speech to work. How do I initiate a play after the TCP command?

    You should make a scene which executes two buttons, first the text-2-speech and next the play button. (till a LUA option is available again).

    Is there any way to make the sonos continue playing what it was prior to the T2S command? It works that way in Vera but would rather use the HC2 for it...

    We need to wait for we get header support in lua (now os.execute is not working), we can retrieve the value of what is playing and store it in a global. I have made a feature request for it.

    Link to comment
    Share on other sites

    • 0

    Hi Deraaij,

    and thanx for your work on the Sonos system, it works great. I'm now using the TCP commands as described in third post (on top of v3.548); however I had to perform some small changes for the group/ungroup: the message length wasn't correct and thus the command wasn't executed:

    Group to zone : Content-Length: 377

    Ungroup zone option 2 : Content-Length: 344

    Using currently 2 play3 devices (and soon a connect), I wish there were a way to create template for virtual devices as their content is the same (excepted the IP address or the group/ungroup ID). More, it would be awesome to have native support !!!

    Regards,

    yorik

    Link to comment
    Share on other sites

    • 0
    I wish there were a way to create template

    We are all waiting for that ....http://bugzilla.fibaro.com/view.php?id=450

    Link to comment
    Share on other sites

    • 0
    Guest deraaij
  • Inquirer
  • Hi Deraaij,

    and thanx for your work on the Sonos system, it works great. I'm now using the TCP commands as described in third post (on top of v3.548); however I had to perform some small changes for the group/ungroup: the message length wasn't correct and thus the command wasn't executed:

    Group to zone : Content-Length: 377

    Ungroup zone option 2 : Content-Length: 344

    Using currently 2 play3 devices (and soon a connect), I wish there were a way to create template for virtual devices as their content is the same (excepted the IP address or the group/ungroup ID). More, it would be awesome to have native support !!!

    Regards,

    yorik

    thnx! Changed the initial post accordingly.

    Link to comment
    Share on other sites

    • 0
    Guest PJ
  • Inquirer
  • I have one question regarding your code for playing example radio:

    Please login or register to see this code.

    It works, but what (and how) do I have to change if I want to play another station? :-> And is it possible to play radio straight from the list of radio stations from Sonos library?

    Link to comment
    Share on other sites

    • 0
    Guest deraaij
  • Inquirer
  • I have one question regarding your code for playing example radio:

    Please login or register to see this code.

    It works, but what (and how) do I have to change if I want to play another station? :-> And is it possible to play radio straight from the list of radio stations from Sonos library?

    You have to change

    Please login or register to see this code.

    to the correct radio station. If you still have questions I will give more guidance when I have time.

    Link to comment
    Share on other sites

    • 0
    Guest PJ
  • Inquirer
  • Thanks, but how should I find exact type of link to put in there?

    Let's say I want to play this radio -

    Please login or register to see this link.

    - how should I create link of the type you used?

    And one more question - I noticed there are several times used word "rincon" in this code. Does it have any connection to the link of the radio station? Does it need to be changed to?

    Link to comment
    Share on other sites

    • 0
    Guest deraaij
  • Inquirer
  • Thanks, but how should I find exact type of link to put in there?

    Let's say I want to play this radio -

    Please login or register to see this link.

    - how should I create link of the type you used?

    And one more question - I noticed there are several times used word "rincon" in this code. Does it have any connection to the link of the radio station? Does it need to be changed to?

    Ok, to get the correct url 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.

    Good luck!

    Link to comment
    Share on other sites

    • 0
    Guest PJ
  • Inquirer
  • Great, it works:) Thanks

    But.... there seems to be some problem with HC2 and virtual buttons. I managed to create button like this:

    Please login or register to see this code.

    And it worked, but only for the first time I pushed it. Later it didn't work and I noticed, that HC2 shortened my virtual button code to this:

    Please login or register to see this code.

    Which is about 150 characters shorter. I Thought I made mistake and copied wrong code, but I've done this several more times and it was the same everytime. Is it working for you everytime? I've got the same for exact your command playing example radio station.

    Link to comment
    Share on other sites

    • 0
    Guest deraaij
  • Inquirer
  • Great, it works:) Thanks

    But.... there seems to be some problem with HC2 and virtual buttons. I managed to create button like this:

    Please login or register to see this code.

    And it worked, but only for the first time I pushed it. Later it didn't work and I noticed, that HC2 shortened my virtual button code to this:

    Please login or register to see this code.

    Which is about 150 characters shorter. I Thought I made mistake and copied wrong code, but I've done this several more times and it was the same everytime. Is it working for you everytime? I've got the same for exact your command playing example radio station.

    Hi,

    It get's converted. So paste it and save it and never change it again (if you save it again it won't work again). Be aware that there is also a bug when deleting buttons. If you did that please start with a new virtual device.

    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...