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

Hi Mark,

I don't suppose you've got a bit of Lua code that could fibaro:debug out the response from the Sonos do you? I'm just trying to list of the full response but just adding fibaro:debug(state) after the :read call doesn't work - presumably because there are new line / special chars in the response?

Thanks!

Link to comment
Share on other sites

  • 0

Can't get it working... Tried the TCP version with/without spaces, newlines, counting the payload etcetera. Hard to debug. I'm clueless... Can't use wireshark since I am on a dumb switch without port monitoring

Please login or register to see this image.

/emoticons/default_icon_sad.gif" alt=":-(" />

The LUA version barks when I use io.open. Says it's nil. My limited lua knowledge says it's either an issue with file permissions (so i tried different paths, no luck), or the io library has been removed. Anyway... since os.execute has been or will be removed, this is a dead end too, isn't it? Is this the case in 3.570?

Please "Enlighten" me

Please login or register to see this image.

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

Link to comment
Share on other sites

  • 0

It would be nice if you could select a Spotify playlist in Sonos by using a virtual device in HC2, anyone know if it's possible?

Link to comment
Share on other sites

  • 0
Guest deraaij
  • Inquirer
  • Hi Mark,

    I don't suppose you've got a bit of Lua code that could fibaro:debug out the response from the Sonos do you? I'm just trying to list of the full response but just adding fibaro:debug(state) after the :read call doesn't work - presumably because there are new line / special chars in the response?

    Thanks!

    Had the same issue. You are not looking for a specific value?

    [ Added: 2013-11-06, 12:00 ]

    Can't get it working... Tried the TCP version with/without spaces, newlines, counting the payload etcetera. Hard to debug. I'm clueless... Can't use wireshark since I am on a dumb switch without port monitoring

    Please login or register to see this image.

    /emoticons/default_icon_sad.gif" alt=":-(" />

    The LUA version barks when I use io.open. Says it's nil. My limited lua knowledge says it's either an issue with file permissions (so i tried different paths, no luck), or the io library has been removed. Anyway... since os.execute has been or will be removed, this is a dead end too, isn't it? Is this the case in 3.570?

    Please "Enlighten" me

    Please login or register to see this image.

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

    You should use the TCP version, LUA is not working. What is the error you are getting?

    Link to comment
    Share on other sites

    • 0

    @Adv.Usr.deraaij tnx for asking. As a newbie, I had a difficult time piecing it all together. But now I have 'Play' and 'Pause' working. I concentrated on debugging virtual devices, so code is bloated. I also used wireshark to confirm the command. So here it is... All comments appreciated!

    Please login or register to see this code.

    For 'Pause' you replace the variable 'payload' like this:

    Please login or register to see this code.

    Edit: I know I'm not consistent with using 'local' for variables declaration. As mentioned before, copy pasting this script adds trailing spaces at line endings. But this lua-version is immune to that.

    Link to comment
    Share on other sites

    • 0

    I can't get the TCP script working yet. Do I need to do something before to pair the system up with the sonos? When I type in the ipadres with:1400 in my browser I get a 403 access forbidden error.

    update1: on another sonos I am getting a response in the browser now, so I entered the code (without the extra spaces on the end of the lines) in the string section of my virtual device with the same settings. Unfortunately I can't control the sonos system yet. Any tips?

    update2: it didn't work because the sonos was paired to form a stereo pair. On the ip of the other device Play/pause/stop works. text2speach not yet...

    update3: text2speach also works now. Probably I didn't hear it before because of low volume (kids in bed) or because of the delay (it takes a couple of seconds before the message plays, any ways to speed that up?)

    Link to comment
    Share on other sites

    • 0

    Don't know what I did wrong the first time, but now i've got the TCP ("string") version working too. For clarity: I copy/pasted the string from the forum into notepad++ and set the editor to display line endings. Then I removed 3 spaces (as per instructions on this forum), one at the end of each of the first three lines. Clearly, line four is blank and has to stay that way. Then I removed the "0x0D0x0A0x0D0x0A" at the end, which seems unneeded to me. And: voilà. Of course, the right IP (from sonos diagnostics) and port 1400 has to be configured in the virtual device...

    Link to comment
    Share on other sites

    • 0

    I want to buy a Sonos system for my house. Can someone maybe post a small demo of the Text to speech for the Sonos? I am very interested in how this sounds and if it works any good...

    Link to comment
    Share on other sites

    • 0
    Guest deraaij
  • Inquirer
  • I want to buy a Sonos system for my house. Can someone maybe post a small demo of the Text to speech for the Sonos? I am very interested in how this sounds and if it works any good...

    You mean a video?

    Link to comment
    Share on other sites

    • 0

    Something like that would be great

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

    Link to comment
    Share on other sites

    • 0

    Hello,

    Do you have an example on how to "initiate play" after choosing a radiostation?

    Today I fist need to press the radio station I want to listen to, and then play... But how do you combine these 2 buttons in one?

    Link to comment
    Share on other sites

    • 0

    Guys,

    A really small thing - I modified the original code slightly so the volume feedback actually assigns to the Slider. Otherwise the slider gets out of sync when you change volume with the Sonos App.

    Basically you just have to define the variables first (outside the if statement) and then add the line of code at the end. Obviously you need to chance IPs and Device ID's to match your system.

    Please login or register to see this code.

    Link to comment
    Share on other sites

    • 0

    I can't get the volume slider to work with LUA. I got it with tcp but want it with lua.

    This is my code

    Please login or register to see this code.

    I have looked throw it over and over but can't seem to find the problem. Anyone has a LUA code ready already or can see the error in my code?

    Link to comment
    Share on other sites

    • 0
    Guest deraaij
  • Inquirer
  • I can't get the volume slider to work with LUA. I got it with tcp but want it with lua.

    This is my code

    Please login or register to see this code.

    I have looked throw it over and over but can't seem to find the problem. Anyone has a LUA code ready already or can see the error in my code?

    Hi,

    _sliderValue_ cannot be between quotes, and i do not know for sure it even works in lua. If it works it should be something like"

    ".." .. _sliderValue_ .. ".."

    Link to comment
    Share on other sites

    • 0

    No that didn't do the trick. Why aren't you sure it will work? All the rest like Play and Stop and so on works just fine with LUA. What is the difference?

    Link to comment
    Share on other sites

    • 0

    Hi, i was trying to implement your great code but with no succeed i keep receiving this error

    [ERROR] line 18: attempt to index global 'io' (a nil value)

    Do you have any idea what did I miss!

    As I tried 100 times to play any sound from network using LUA code, but also with no succeed!!

    Please login or register to see this image.

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

    Link to comment
    Share on other sites

    • 0
    Guest deraaij
  • Inquirer
  • No that didn't do the trick. Why aren't you sure it will work? All the rest like Play and Stop and so on works just fine with LUA. What is the difference?

    Those are not using a variable from the virtual device in order to work.

    [ Added: 2014-01-14, 18:51 ]

    Hi, i was trying to implement your great code but with no succeed i keep receiving this error

    [ERROR] line 18: attempt to index global 'io' (a nil value)

    Do you have any idea what did I miss!

    As I tried 100 times to play any sound from network using LUA code, but also with no succeed!!

    Please login or register to see this image.

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

    IO has been depreciated. You need to use the TCP version or use LUA and the Net.FTcpSocket. If you tell me what you want to achieve I can point you in the right direction.

    Link to comment
    Share on other sites

    • 0

    Thanks for your swift reply , actually i have sonos play 3

    And I was trying to make a scene that can play a sound from the network !!

    Because i want my Sonos to play this sound during a fire alarm scene, so is that possible ?!

    Link to comment
    Share on other sites

    • 0
    Guest deraaij
  • Inquirer
  • Thanks for your swift reply , actually i have sonos play 3

    And I was trying to make a scene that can play a sound from the network !!

    Because i want my Sonos to play this sound during a fire alarm scene, so is that possible ?!

    yes.

    you can use tcp:

    Please login or register to see this code.

    obviously replace the CurrentURI, set the correct sonos IP and port (1400) and update the Content-Length accordingly.

    Link to comment
    Share on other sites

    • 0

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

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