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
  • oke, this is not efficient!

    i am trying to get all those nice code to work. But is difficult with some spaces and stuff.

    Can someone export their virtual device and post it?

    Oh by the way. Got my set yesterday

    Please login or register to see this image.

    /emoticons/default_biggrin.png" alt=":D" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" /> Works perfect!

    [ Added: 2014-01-30, 16:32 ]

    Does someone have an updated version of the LUA code to make the sonos talk? as the Os.execute versions don't work anymore.

    [ Added: 2014-01-30, 16:57 ]

    I can't seem to get it to work. Does anyone know if it is possible to do it or to calculate the content length?

    Then you could adjust them in code...

    I used use the len function in excel

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

    Link to comment
    Share on other sites

    • 0

    Yeah, but if I change the content of a string by a lua code. For instance for TTS with different temps or weather. And the HC2 doesn't have excel

    Please login or register to see this image.

    /emoticons/default_wink.png" alt=";)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    Link to comment
    Share on other sites

    • 0

    stevenvd, I release soon my complete virtual device with advanced properties

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

    for TTS you can try for example:

    put your IP and port in your VD and copy the code in a button to play...

    Please login or register to see this code.

    ex: playTTS(strLang, strMessage, nil, intVolume) you can replace nil by integer value to set duration. nil = auto stop mode.

    Please login or register to see this image.

    /emoticons/default_icon_biggrin.gif" alt=":-D" />

    Link to comment
    Share on other sites

    • 0

    Holly *! This is some coding man in LUA

    Please login or register to see this image.

    /emoticons/default_biggrin.png" alt=":D" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" /> I can code but I am still learning lua

    Please login or register to see this image.

    /emoticons/default_wink.png" alt=";)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    It worked directly! and in the way I hoped to get it to work eventually.

    Please login or register to see this image.

    /emoticons/default_biggrin.png" alt=":D" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    Now combine it with getting your preset notifications and you have your message spelled out!

    Had to try it (A)

    here you can get the notification :

    Please login or register to see this code.

    if you now set the id of the notification in a global variable. You can change it, run the virtual device button and it will speak a different preset notification

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    Change the Function call into:

    playTTS("nl", getNotification( fibaro:getGlobalValue("NotificationId") ), nil, 12);

    Thanks krikroff! without you I wouldn't have gotten it to work like this

    Please login or register to see this image.

    /emoticons/default_biggrin.png" alt=":D" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    [ Added: 2014-01-31, 08:20 ]

    Will make it better when I have more time.

    You would want to convert the condition into a sentance.

    Please login or register to see this code.

    Link to comment
    Share on other sites

    • 0

    stevenvd, this is exactly why I made SONOS TTS

    Please login or register to see this image.

    /emoticons/default_icon_biggrin.gif" alt=":-D" /> , i think you'll be happy with my virtual device

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

    Link to comment
    Share on other sites

    • 0

    Haha Cool

    Please login or register to see this image.

    /emoticons/default_biggrin.png" alt=":D" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" /> looking forward to it! This is partly why I bought Sonos

    Please login or register to see this image.

    /emoticons/default_wink.png" alt=";)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    Link to comment
    Share on other sites

    • 0

    To speed it up, you could actually just save a few of them on your server. The static ones...

    And for the non static ones, like weather. It is not such a problem for me that it takes a little longer.

    Link to comment
    Share on other sites

    • 0

    Ahh i see save the generated mp3 file to server and play that instead

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" /> doh!

    Link to comment
    Share on other sites

    • 0

    I have to say, before posting this I had never though about it before either

    Please login or register to see this image.

    /emoticons/default_tongue.png" alt=":P" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    Link to comment
    Share on other sites

    • 0

    soon...

    Please login or register to see this image.

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

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0
    soon...

    Please login or register to see this image.

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

    I can't wait, I started to build my own but when I saw yours I stopped working on mine.

    Any ETA?

    Link to comment
    Share on other sites

    • 0
    soon...

    Please login or register to see this image.

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

    I can't wait, I started to build my own but when I saw yours I stopped working on mine.

    Any ETA?

    Wow, awesome, i can't wait!!!!

    Please login or register to see this image.

    /emoticons/default_icon_mrgreen.gif" alt=":mrgreen:" />

    Please login or register to see this image.

    /emoticons/default_icon_mrgreen.gif" alt=":mrgreen:" />

    Please login or register to see this image.

    /emoticons/default_icon_mrgreen.gif" alt=":mrgreen:" />

    Link to comment
    Share on other sites

    • 0
    WOW! Nice coding!

    Just a damn shame GoogleTTS cannot respond as quick as we would like!

    But regardless ***** 5-Star!

    Created this.

    Using an alternative service (

    Please login or register to see this link.

    ) as well as a php script to proxy only the mp3 file you could get a much faster response!

    Please login or register to see this code.

    Let me know what you guys think.

    [ Added: 2014-02-14, 21:45 ]

    I am looking for a way to use Sonos to announce events. What I am thinking is that I need to:

    save each devices queue to a variable and the different group states and volumes.

    Then initiate party mode (all devices in one zone), set the volume, disable repeat and

    play the message.

    After complete, restore the devices to their previous state.

    There may be a better way to do this, as what I am trying to achieve is to have Sonos act as an Public Announcement system.

    Do you think this would be possible through code you've already written Kirkroff?

    Link to comment
    Share on other sites

    • 0

    So guys, I've been spending the past two days trying to solve this Sonos Text-to-Speech.

    I have decided to move it out of HC2 into a Node.JS app as I found a good API I could build upon.

    The work can be found at:

    Please login or register to see this link.

    Currently we have a proof of concept where the player name is hardcoded (Living Room in the commit on line # 276).

    Usage is: localhost:5005/ttsall/text+to+speech

    Doing a HTTP get from HC2 on events is simple so that's no problem.

    This would get livingroom to speech a voice from Google's TTS engine saying "Text to speech". If a speech already has been downloaded it would not have to download it again.

    Later on in the project I believe I will run this on a server where it downloads the messages to a CIFS share as Sonos seem to be slow to start Radio streams.

    Link to comment
    Share on other sites

    • 0
    soon...

    Please login or register to see this image.

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

    Any progress? I really need that

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

    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...