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


TUTORIAL - Sonos Remote VD (using node-sonos-api)


Recommended Posts

On 1/28/2017 at 7:21 PM, AutoFrank said:

Hi All,

 

I switched over to using AWS Polly TTS and the voice is good bit better.

 

I have to update the settings.json file on the api to reflect the new TTS service

 

The format for VoiceRSS is 

Please login or register to see this code.

 

The format for AWS Polly is  

Please login or register to see this code.

 

I also upgraded the latest api (version": "1.2.6") and between both changes encoding the string by replacing a space with a + is no longer working as it speaks the plus sign so I needed a new encoding solution and this what I'm now using.

 

Please login or register to see this code.

AWS Polly also requires the name of the voice before the volume (Amy above)

 

Did also switch over from voicerss to AWS policy and i must say it much cleaner sound. Works really good with swedish language.

Link to comment
Share on other sites

  • Topic Author
  • 1 minute ago, jompa68 said:

    Did also switch over from voicerss to AWS policy and i must say it much cleaner sound. Works really good with swedish language.

     

    @jompa68

     

    Its great that it available where you are.The voice is much more natural sounding :-)

     

    Link to comment
    Share on other sites

    • 3 weeks later...
  • Topic Author
  • Hi API users,

     

    Something new for you.

     

    Do you ever wish that you could display the radio station of that line in selection instead of the plain static icon of a music symbol or a sonos player.

    Well now you can ... :D

     

    sonos-blu.PNG.73d6d461070fa035fcb938e2f8051112.PNG sonos-calm.PNG.6d272533b99b674ff63dec472001214c.PNG

     

    It also looks equally well on your phone or viewing the VD controls in the WEB UI

     

    Please login or register to see this attachment.

    Please login or register to see this attachment.

     

    Here we go..... There is a little work with this one as you need to create and upload some icons but not too much if you use @Sankotronic recent icon viewer VD and GIMP to make/steal borrow the icons

    I'd put this at a medium difficulty, you will probably need an hour and 2 cups of coffee :D

     

    The code is two tables and two if loops to figure out the correct icon to display. This goes into the main loop of the VD that you are running at the moment 

    (I'll upload the VD I used to develop and test this bit of code for a complete solution)

     

    Please login or register to see this code.

    The tables hold the key - the rest of the lua is just a little decision making

     

    Line in options

    Please login or register to see this code.

    The number is the icon id when you upload it

    the text is the name of the title in as it is in the sonos json state request

    Please login or register to see this attachment.

    It needs to match exactly

     

    You will need one icon for each line-in you have and one extra one in case it can't match to what you have

    Here are my 4 and the extra one at the end is the generic sonos line-in icon

    58f3d44212419_AndroidOS-100.png.07401137795c004ef91a1cde8578137a.pngSatTV.png.9968eabb3db50736c186810b3f21ff6e.png58f3d4429d885_BluRayDiscPlayer-100.png.cfa02c6ea9d778006b59ed87051f97d5.png58f3d442c9ca7_Bluetooth2-100.png.63f5739bb19a4893c63095136815a468.png                         linin.png.f723112c31a19d4c9d87a52d91a9a61b.png

     

    the ID of the last icon needs to be added to the following line at the start of the code

    Please login or register to see this code.

    It also uses the generic one when it is transitioning from one line in or radio option to the other.

     

    Radio Favorite options

    Please login or register to see this code.

    Same here as with the line in

    The number is the icon id when you upload it

    the text is the name of the artist as it is in the sonos json state request

    Please login or register to see this attachment.

    It needs to match exactly

     

    Again like line-in you will need one icon for each radio station (make your own) and one extra generic one at the end

     

    4fm.png.312fc5dd63f674749e97c59c18b96e93.pngheart.png.18c6daddeb1c20b6ac9bd171b2c240af.pngcalm.png.69c60e1c198bfb724617f194637545b6.png                           58f3d5a7330f7_Radio2-100.png.ec0e1b27970f46789d353cd8e740ee92.png

     

    the ID of the last icon needs to be added to the following line at the start of the code

    Please login or register to see this code.

     

    and that's it

    Full VD is attached but it won't work out of the box as you will need to upload your own icons that match you sonos favorites and line-in options

    Please login or register to see this attachment.

     

    Enjoy !!

     

    Some more screenshots 

    Line in

    sonos-blu.PNG.d89263cb22fe894a574e6f36ab33c070.PNGsono-satTV.PNG.16fc925710bfe104d9f0ce624af9fd81.PNG

    sonos-droid.PNG.51f9bb61ca899263149209f6d8a03d63.PNGsonos-bt.PNG.09cecea58a59f841c118f8949a3115ac.PNG

     

    Radio

    sonos-calm.PNG.6d272533b99b674ff63dec472001214c.PNGsonos-4fm.PNG.b2b980730efae13b8708e206bede3d63.PNG

    sonos-96fm.PNG.91f093e563ff84d5ade621f454fa1e2d.PNGsonos-heart.PNG.2bfaa510228170f0086a8365f5ae94b2.PNG

    VD from the web UI

    Please login or register to see this attachment.

     

     

     

     

     

     

     

    Please login or register to see this attachment.

    Edited by AutoFrank
    Link to comment
    Share on other sites

  • Topic Author
  • 11 minutes ago, gobbli said:

    Hi @autofrank, thank you. Will try it this week. Have a nice easter monday.

     

    Thanks @gobbli

    Let me know how it goes...

     

    -f

    Link to comment
    Share on other sites

    @AutoFrank,

     

    I am trying to get this functioning however after getting the API running and testing the http commands actually work I am unable to get your VD to control my Sonos. when I debug the main loop I get the message  [ERROR] 23:22:10: line 9: Expected value but found T_END at character 1

     

    Have you seen this before?

     

     
    Link to comment
    Share on other sites

  • Topic Author
  • 14 minutes ago, Robert Folbigg said:

    @AutoFrank,

     

    I am trying to get this functioning however after getting the API running and testing the http commands actually work I am unable to get your VD to control my Sonos. when I debug the main loop I get the message  [ERROR] 23:22:10: line 9: Expected value but found T_END at character 1

     

    Have you seen this before?

     

     

     

    hi @Robert Folbigg

     

    Could you post your main loop code

    BTW - do you use a hometable ?

    Link to comment
    Share on other sites

    @AutoFrank

     

    Thanks for the prompt response however right after I posted I found the answer!! it was the SPACE in my zone name "Living Room" that cause the problem.

     

    all fixed and working now :-)

    Link to comment
    Share on other sites

  • Topic Author
  • Just now, Robert Folbigg said:

    @AutoFrank

     

    Thanks for the prompt response however right after I posted I found the answer!! it was the SPACE in my zone name "Living Room" that cause the problem.

     

    all fixed and working now :-)

     

    Great @Robert Folbigg

     

    Glad it's sorted :D

    Link to comment
    Share on other sites

    Hello AutoFrank,

     

    thanks for sharing your work!! I really appreciate that. One idea or better question that comes up to my mind. I'm using your vol fading up buttons, what is really nice. Do you think there is an option to do it the other way around? To fade down the volume before the speakers turn off? That would be awesome.  

    Link to comment
    Share on other sites

  • Topic Author
  • 2 hours ago, Eldar said:

    Hello AutoFrank,

     

    thanks for sharing your work!! I really appreciate that. One idea or better question that comes up to my mind. I'm using your vol fading up buttons, what is really nice. Do you think there is an option to do it the other way around? To fade down the volume before the speakers turn off? That would be awesome.  

    @Eldar

     

    Thanks and I'm glad you fifind it helpful.

    're the volume reducing thst should be easy enough to do 

    Where I have for i=1,10 

    Replace it with 

    for I =10,0

     

    And there should be a counter 

    I=i+1

    Replace that with 

    I=i-1

     

    And that should work if you want you want to give it be go .....

     

     

     

     

    Link to comment
    Share on other sites

    44 minutes ago, AutoFrank said:

    @Eldar

     

    Thanks and I'm glad you fifind it helpful.

    're the volume reducing thst should be easy enough to do 

    Where I have for i=1,10 

    Replace it with 

    for I =10,0

     

    And there should be a counter 

    I=i+1

    Replace that with 

    I=i-1

     

    And that should work if you want you want to give it be go .....

     

     

     

     

     

    Well, that helps a bit. I replaced the v= 0, 12 with v= 12, 0 in the button code but I don't have a clue what to change in the primary loop. It says:

     

    local device = fibaro:getSelfId();
    local zonename = fibaro:getName(device);
    local ipaddress = fibaro:getValue(device, "IPAddress");
    local port = fibaro:getValue(device, "TCPPort");
    sonos = Net.FHttp(ipaddress, port);

    local z = 0
    local a = 0

    players = {"Kueche", "Bad", "Wohnzimmer", "Schlafzimmer", "Feline"}

    for k,v in pairs(players) do 
      response = sonos:GET("/"..v.."/state")
      jsonTable = json.decode(response);
      if jsonTable.playbackState == "PLAYING" then 
          z = z + 1 
      end
      a = k + 1
      fibaro:call(device,"setProperty","ui.Label"..a..".value",""..jsonTable.playbackState.."");

      fibaro:setGlobal("ActiveMusicZones", z);
      fibaro:call(device,"setProperty","ui.Label1.value",z)
    end

     

    Would be nice if I could use the same VD and don't have to make a new one. So that you got 2 buttons for each room. One fading in and one fading out the volume.

    Link to comment
    Share on other sites

  • Topic Author
  • 1 minute ago, Eldar said:

     

    Well, that helps a bit. I replaced the v= 0, 12 with v= 12, 0 in the button code but I don't have a clue what to change in the primary loop. It says:

     

    local device = fibaro:getSelfId();
    local zonename = fibaro:getName(device);
    local ipaddress = fibaro:getValue(device, "IPAddress");
    local port = fibaro:getValue(device, "TCPPort");
    sonos = Net.FHttp(ipaddress, port);

    local z = 0
    local a = 0

    players = {"Kueche", "Bad", "Wohnzimmer", "Schlafzimmer", "Feline"}

    for k,v in pairs(players) do 
      response = sonos:GET("/"..v.."/state")
      jsonTable = json.decode(response);
      if jsonTable.playbackState == "PLAYING" then 
          z = z + 1 
      end
      a = k + 1
      fibaro:call(device,"setProperty","ui.Label"..a..".value",""..jsonTable.playbackState.."");

      fibaro:setGlobal("ActiveMusicZones", z);
      fibaro:call(device,"setProperty","ui.Label1.value",z)
    end

     

    Would be nice if I could use the same VD and don't have to make a new one. So that you got 2 buttons for each room. One fading in and one fading out the volume.

     

    Hi @Eldar

     

    Sorry about that - I was answering from my phone while I was out and didnt have the code in front of me :-(

     

    Nothing to change in main loop

     

    Could you post the full code from the button where you changed i = 12,0 and I'll tell you what to change

     

    Sorry again for the confusion

     

    -f 

    Link to comment
    Share on other sites

    1 minute ago, AutoFrank said:

     

    Hi @Eldar

     

    Sorry about that - I was answering from my phone while I was out and didnt have the code in front of me :-(

     

    Nothing to change in main loop

     

    Could you post the full code from the button where you changed i = 12,0 and I'll tell you what to change

     

    Sorry again for the confusion

     

    -f 

     

    You don't have to be sorry! Thanks for your support! Button code is:

     

    local device = fibaro:getSelfId();
    local zonename = fibaro:getName(device);
    local ipaddress = fibaro:getValue(device, "IPAddress");
    local port = fibaro:getValue(device, "TCPPort");
    sonos = Net.FHttp(ipaddress, port);

    for v = 12, 0 do
        response = sonos:GET("/Wohnzimmer/volume/"..v.."")
        fibaro:debug("vol= "..v.."")
        fibaro:sleep(300)
    end

    Link to comment
    Share on other sites

  • Topic Author
  • 1 minute ago, Eldar said:

     

    You don't have to be sorry! Thanks for your support! Button code is:

     

    local device = fibaro:getSelfId();
    local zonename = fibaro:getName(device);
    local ipaddress = fibaro:getValue(device, "IPAddress");
    local port = fibaro:getValue(device, "TCPPort");
    sonos = Net.FHttp(ipaddress, port);

    for v = 12, 0 do
        response = sonos:GET("/Wohnzimmer/volume/"..v.."")
        fibaro:debug("vol= "..v.."")
        fibaro:sleep(300)
    end

     

    Hi @Eldar

    That should work, I was getting it mixed up with another part where I increment with a counter but here it is a for v = 12,0 and it will decrement itself. 

     

    give that a go...

     

    The only other suggestion I'd make is to increase the sleep perhaps to 500ms or even 1 second

    at 300 ms and 12steps it will go from vol 12 to vol 0 in just under 4 seconds ( 300ms x 12) and you might not notice the fade out. On my systems I cant hear the sonos under vol = 4

     

    -f

     

    Link to comment
    Share on other sites

    5 minutes ago, AutoFrank said:

     

    Hi @Eldar

    That should work, I was getting it mixed up with another part where I increment with a counter but here it is a for v = 12,0 and it will decrement itself. 

     

    give that a go...

     

    The only other suggestion I'd make is to increase the sleep perhaps to 500ms or even 1 second

    at 300 ms and 12steps it will go from vol 12 to vol 0 in just under 4 seconds ( 300ms x 12) and you might not notice the fade out. On my systems I cant hear the sonos under vol = 4

     

    -f

     

     

    Tried this:

     

    local device = fibaro:getSelfId();
    local zonename = fibaro:getName(device);
    local ipaddress = fibaro:getValue(device, "IPAddress");
    local port = fibaro:getValue(device, "TCPPort");
    sonos = Net.FHttp(ipaddress, port);

    for v = 12, 1 do
        response = sonos:GET("/Wohnzimmer/volume/"..v.."")
        fibaro:debug("vol= "..v.."")
        fibaro:sleep(1000)
    end

     

    Doesn't work for me. Other way around it works perfectly... :( 

    Link to comment
    Share on other sites

  • Topic Author
  • 9 minutes ago, Eldar said:

     

    Tried this:

     

    local device = fibaro:getSelfId();
    local zonename = fibaro:getName(device);
    local ipaddress = fibaro:getValue(device, "IPAddress");
    local port = fibaro:getValue(device, "TCPPort");
    sonos = Net.FHttp(ipaddress, port);

    for v = 12, 1 do
        response = sonos:GET("/Wohnzimmer/volume/"..v.."")
        fibaro:debug("vol= "..v.."")
        fibaro:sleep(1000)
    end

     

    Doesn't work for me. Other way around it works perfectly... :( 

    @Eldar

    I'll try it later on my system and figure out what's wrong 

    Will be in touch 

    Link to comment
    Share on other sites

  • Topic Author
  • 1 hour ago, Eldar said:

     

    Well, that helps a bit. I replaced the v= 0, 12 with v= 12, 0 in the button code but I don't have a clue what to change in the primary loop. It says:

     

    local device = fibaro:getSelfId();
    local zonename = fibaro:getName(device);
    local ipaddress = fibaro:getValue(device, "IPAddress");
    local port = fibaro:getValue(device, "TCPPort");
    sonos = Net.FHttp(ipaddress, port);

    local z = 0
    local a = 0

    players = {"Kueche", "Bad", "Wohnzimmer", "Schlafzimmer", "Feline"}

    for k,v in pairs(players) do 
      response = sonos:GET("/"..v.."/state")
      jsonTable = json.decode(response);
      if jsonTable.playbackState == "PLAYING" then 
          z = z + 1 
      end
      a = k + 1
      fibaro:call(device,"setProperty","ui.Label"..a..".value",""..jsonTable.playbackState.."");

      fibaro:setGlobal("ActiveMusicZones", z);
      fibaro:call(device,"setProperty","ui.Label1.value",z)
    end

     

    Would be nice if I could use the same VD and don't have to make a new one. So that you got 2 buttons for each room. One fading in and one fading out the volume.

     

    Hi @Eldar

     

    Sorted, I had the syntax wrong

    This will work 

    Please login or register to see this code.

    I was short the -1 in the for loop :-(

     

    Please login or register to see this attachment.

     

    Give that a whirl and let me know how you get on...

     

    -f

     

     

    Link to comment
    Share on other sites

    5 minutes ago, AutoFrank said:

     

    Hi @Eldar

     

    Sorted, I had the syntax wrong

    This will work 

    Please login or register to see this code.

    I was short the -1 in the for loop :-(

     

    Please login or register to see this attachment.

     

    Give that a whirl and let me know how you get on...

     

    -f

     

     

     

    Works perfectly! Thanks a lot :) 

    Link to comment
    Share on other sites

  • Topic Author
  • 8 minutes ago, Eldar said:

     

    Works perfectly! Thanks a lot :) 

     

    @Eldar

     excellent - is it having the effect you thought ?

    I never tried it but it sounds like a nice idea

    I could use a fade down followed by a pause all as part of my leaving home scene

    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
    Reply to this topic...

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