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
Posted

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]

Recommended Posts

  • 0
Guest berga_s
  • Inquirer
  • Posted
    New version 0.0.8 at the bottom of my message.

    Hi, I'm trying to use the PayTTS function (rel. 0.0.8).

    I get successful with "short" string, but with a longer one, no audio is played from Sonos.

    For example, I'm able to play this string:

    "Questo è un test per vedere quanto puo essere lungo il messaggio che deve essere trasmesso"

    but If I add some more, no audio from Sonos, for example:

    "Questo è un test per vedere quanto puo essere lungo il messaggio che deve essere trasmesso tramite la Playbar Sonos di sala"

    I would like to play the actual and forecast weather but it's a string longer than my examples...

    Any suggestion?

    • 0
    Posted

    Can anyone help with these questions:

    CHANGING VOLUME FROM SCENE

    I have setup a wall switch (Fibaro Dimmer) to start and stop playing music on my Sonos, but I am struggling to get the volume change to work from a scene.

    I am using TCP Post that deeraij shared. The volume slider works perfectly when you physically move it, but when I try to change the volume from a scene the slider reflects the change in volume but the volume doesn't actually change. Any ideas?

    PLAYING PLAYLISTS

    I am sure it has been asked before, but is there a way to play a Sonos playlist through a scene? If the answer is no, that's fine it would just be good to know if it's possible or not.

    Cheers

    Aleks

    • 0
    Posted

    Krikroff,

    Just installed my first Sonos.Play.1 - now I can control it with HC2.

    Thank you and everyone else's for a great job

    Please login or register to see this image.

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

    Please login or register to see this image.

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

    Please login or register to see this image.

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

    • 0
    Posted

    richo, great!

    Have fun

    Please login or register to see this image.

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

    • 0
    Guest berga_s
  • Inquirer
  • Posted

    Hi Krikoff,

    do you have any suggestion for the problem showed 4 post previous?

    Thanks!

    • 0
    Posted

    amilanov and others,

    If you are using Krikroff's virtual device, you can use the following code in a scene to change the volume of the sonos player:

    Please login or register to see this code.

    Happy Automating,

    Adam Bewsher

    • 0
    Posted

    Krikroff, thanks for the device, it is a very useful piece.

    berga_s,

    I get successful with "short" string, but with a longer one, no audio is played from Sonos.

    Try to set the duration manually. I have realized that the auto option fails sometimes.

    And avoid to insert any "apice" in the string. The TTS traslator will not understand them, at least the Google one (americans do not use apices...

    Please login or register to see this image.

    /emoticons/default_icon_razz.gif" alt=":-P" /> )

    [ Added: 2014-10-13, 13:41 ]

    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!

    Anyone managed to retrieve the mp3 file from Google translator and store it in HD?

    • 0
    Posted

    Wow! Thanks a lot for the TCP calls! They work great. Just copy and paste to HCL, and there you go, but. I can't figure out:

    "Remark: adjust lenght accoring to Soap body."

    How can i calculate the the body length. It doesn't seem to be characters nor hex, nor ASCII? Any input?

    Thanks!

    --------------------

    edit1

    @Brick

    Just use wget or curl to download the file.

    • 0
    Posted

    diderik,

    It is the length in characters. But, keep in mind that:

    - any characters in the format 0x?? are in HEX will be counted as only 1 character. (So 0x0D0x0A0x0D0x0A is 4 characters long.)

    - Not all the characters in the post are counted. For example:

    POST /MediaRenderer/AVTransport/Control HTTP/1.1

    Content-Length: 266

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

    010x0D0x0A0x0D0x0A

    Only the characters in bold are counted - there are 266 of them.

    Happy automating,

    Adam Bewsher

    • 0
    Posted

    Thanks, a lot Adam! That got me on the roght track!

    • 0
    Posted

    Any solution in how to play an existing MP3 on a server?

    [ Added: 2015-01-10, 22:57 ]

    I Also hope someone could help out with a button to group all devices. It would help a lot upon triggering an alarm TTS, or playing radio in whole house when entering home.

    • 0
    Posted

    Having a lot's off fun with this great Virtual device --> great work, Thank you!.

    Did anyone manage to play a Spotify playlist using this Virtual device?

    • 0
    Posted

    real shame we cannot bypass the 3 second main loop delay as it really does spoil this VD...

    A.Socha or anyone? can we have an option to bypass for specific scenarios? maybe introduce a warning to state this is running with no delay for debugging purposes should any instability occur? or even give access to .Net under scenes EVEN BETTER

    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" />

    • 0
    Posted
    real shame we cannot bypass the 3 second main loop delay as it really does spoil this VD...

    A.Socha or anyone? can we have an option to bypass for specific scenarios? maybe introduce a warning to state this is running with no delay for debugging purposes should any instability occur? or even give access to .Net under scenes EVEN BETTER

    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" />

    Have you tried .net in scenes recently :->

    • 0
    Posted

    i have robmac unless i used it incorrectly!? !? don't anti-climax me! lol

    • 0
    Posted

    Sorry did not mean to show you any disrespect.

    • 0
    Posted

    no not at all but you did get me all excited!

    [ Added: 2015-01-13, 22:25 ]

    please if i have missed something i would like to know? but i assumed it was currently and has been for a while a NO-GO with scenes?

    • 0
    Posted

    How to create a VD in LUA to change the volume in a SONOS speaker?

    Id like to add that feature to my TV device.

    Please!

    • 0
    Posted

    create a slider and use the code on approx page 4/5/6 on this thread

    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" />

    [ Added: 2015-01-13, 23:02 ]

    page 4!

    --------

    tcpSocket = Net.FTcpSocket("192.168.1.17", 1400)

    payload = [[post /MediaRenderer/RenderingControl/Control HTTP/1.1

    Content-Length: 290

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

    0Master0x0D0x0A0x0D0x0A]]

    bytes, errorcode = tcpSocket:write(payload)

    if errorcode == 0 then

    state = tcpSocket:read()

    local volume = state:match("(.+)")

    fibaro:debug(volume)

    fibaro:log(volume)

    end

    tcpSocket:disconnect()

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