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


  • 0

Sonos Speaker Plugin - "Play" / "Resume" with LUA script


Danielos

Question

Dear all,

 

I'm using the normal "Sonos Speaker" Plugin from the Fibaro Marketplace. I'm struggeling with a simple LUA script to simulate a push "resume" / "play" button on a specified sonos speaker. Can someone help me, how I can realize that? I just want a script to unpause the music, not more.. ;-)

 

Thank you very much for your help.

 

Dan

Link to comment
Share on other sites

Recommended Posts

  • 1

Hi @Danielos, seems to me an old or corrupted version. 

 

Please try with the following:

 

1. Remove your SONOS Remote VD from your HC2

2. Go to http://YOUR_IP/fibaro/en/panels/variables.html and delete the variable x_sonos_object

3. Import 

Please login or register to see this attachment.

4. Configure the VD with port 1400 and Main IP used by your SONOS in case of stereo pair or just the SONOS IP if it is alone.


let me know if the problem is gone ;)

  • Thanks 3
Link to comment
Share on other sites

  • 0

Hello Dan,

 

I have this LUA code for the play button in the VD.

 

Please login or register to see this code.

 

 

You only need to adjust the SonosLastCmdEetkam text to the name you called your variable, exactly the same with capitals and everything.

 

Hope this helps. I can't write LUA code but just copied it from my VD.

 

Kevin

Edited by kevin
Link to comment
Share on other sites

  • 0
  • Inquirer
  • Thank you very much. Unfortunatley, it doesn't work.. I receive this error message:

     

    Please login or register to see this code.

    Any idea?

     

    Thank you very much!

     

    Dan

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Btw, here is a printscreen of my module. What I need is a LUA script to virtually push the "Play" button.

     

    Please login or register to see this image.

    /monthly_2019_01/image.png.5564f79498fbda908c49ac80093e7815.png" alt="image.png.5564f79498fbda908c49ac80093e7815.png" />

    Link to comment
    Share on other sites

    • 0

    See the attachment for my VD. I have changed it for you so a lot of buttons are not visible.:-D

     

    You first need to create a variable with no value. It's important to remember the name of the variable exactly(with capitals) because you need it in the VD(See screenshot)

    Please login or register to see this attachment.

     

     

     

    Now import my VD. Fill in the padres of your Sonos speaker with port 1400.

    Please login or register to see this attachment.

     

     

     

    Go to the advanced tab and you need to replace the XXXXX in each LUA code of each button with the name of the variable you just created. Remember the name has to be exactly with what you have noted in the variable panel.

    Please login or register to see this attachment.

     

     

     

    Now the VD remote should work. I have a Sonos Play 5 2nd gen, so I can only test it with this unit.

    These buttons/labels are in the VD.

    2068026415_Schermafbeelding2019-01-12om11_00_16.png.d93bda9161ed50de4264984a8a1363dd.png

     

     

    Hope this helps you, otherwise I have no idea what it is. I'm (sadly) no expert in LUA:-(

     

    Please login or register to see this attachment.

    Edited by kevin
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Thank you very much... unfortunatley, it doesn't work (without an error). Perhaps, because the Sonos is already linked to the official Sonos Plugin. So is there no way to virtually push the "Play"-Button on the official plugin?

    Link to comment
    Share on other sites

    • 0

    What is the version you use ?

     

    To virtually push play buton the correct way is 

     

    Please login or register to see this code.

    Please try with this code

    • Like 1
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • @Krikroff SONOS_Remote_v1.0.0 vfib . I can't find an newer one to download. I saw that there should be a 1.0.1, but no download link. Perhaps that's the problem?

    Link to comment
    Share on other sites

    • 0

    Ok this is the lastest public version available at time. could you try the code given just before ?

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • @Krikroff Thank you. I reinstalled and added the code. If I push start, nothing happens...

     

    Please login or register to see this image.

    /monthly_2019_01/image.png.bb2781c88ad6dbd1e4a9f5fd9b856a97.png" alt="image.png.bb2781c88ad6dbd1e4a9f5fd9b856a97.png" />

     

    image.png.8fe7f9011f6fbc45a1a76303617a49e5.png

     

    image.png.f3d682bce788bd261e34b29451179142.png

     

    image.png.c3c489cabd9d87c860657e6f90c7def8.png

     

     

    And even in the GUI it's not possible to push play..... but in the official plugin of sonos (with the same IP) it works perfect as you see.

     

    Hmm, strange. Any idea?

     

    Thank you very much for your help!!!

     

    image.png.4c3c0041709b8aad9da674d2b141a24a.png

    Link to comment
    Share on other sites

    • 0

    can you look in the "Main Loop" debug,

    => buton "debug" and then buton "start"

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • 4 hours ago, Krikroff said:

    can you look in the "Main Loop" debug,

    => buton "debug" and then buton "start"

     

    @Krikroff: this is the error message:

     

    [ERROR] 23:21:19: line 5: bad argument #1 to 'len' (string expected, got nil)

    Link to comment
    Share on other sites

    • 0

    in the debug of your "play buton" or debug of Sonos VD ?

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • @Krikroff No, in the script. In the debug mode I receive that:

     

    Please login or register to see this image.

    /monthly_2019_01/image.png.d0ba5712e3441ca6f769fd2b503cd8d2.png" alt="image.png.d0ba5712e3441ca6f769fd2b503cd8d2.png" />

     

    Thank you for your help!

     

    Dan

    Link to comment
    Share on other sites

    • 0

    Hum if i put the following code in a new button in a VD it work like a charm, replace 408 with your sonos remove vd ID

    Please login or register to see this code.


    Does the play button on the SONOS Remote VD work?

     

    If not trying that:

     

    1. In the variables panel, delete the variable x_sonos_object

    2.  In Sonos Remote VD,  click on save (the small floppy disk on the right) to force the creation of the variable.

     

     

    Link to comment
    Share on other sites

    • 0

    @Danielos, could you send me your VD for further investigation please ?

     

    Regards,

    • Thanks 1
    Link to comment
    Share on other sites

    • 0

    @Krikroff

     

    I also use the Sonos remote VD. On this remote I also have 5 buttons for my favorite radiostations. Now I want more then 5 button for radiostations, so i added a new row of buttons, copy/paste the LUA code and change de label ID and some numbers in de LUA code for that specifik button. Sadly it doens’t work that way. 

     

    I think there should also a change in the main loop, do you know what to change/add?

     

    kevin

    Link to comment
    Share on other sites

    • 0

    I Just repeated the step Krikroff said above and then loaded the VD 

    On 1/15/2019 at 12:17 PM, Krikroff said:

    Hi @Danielos, seems to me an old or corrupted version. 

     

    Please try with the following:

     

    1. Remove your SONOS Remote VD from your HC2

    2. Go to http://YOUR_IP/fibaro/en/panels/variables.html and delete the variable x_sonos_object

    3. Import 

    Please login or register to see this attachment.

    4. Configure the VD with port 1400 and Main IP used by your SONOS in case of stereo pair or just the SONOS IP if it is alone.


    let me know if the problem is gone ;)

    I had the same problem.

     

    Just followed Krikroffs steps above, and loaded the VD he attached.

    It worked directly like a charm

     

    I Hope it continues that way. :)

    So far so good!

     

    Thankyou Krikroff!

     

    Regards

     

    Andreas

    • Like 1
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • @Krikroff yeeahhhhhhh, it works!!!! You're brillant, thank you very much!!! :-)

     

    Now I tried your script above:

     

    Please login or register to see this code.

    (28 is my VD-ID). And the following error is shown: 

     

    Quote

    [DEBUG] 20:55:19: 2019-01-16 20:55:19.343511 [ fatal] Unknown exception: /opt/fibaro/scenes/34.lua:13: attempt to call method 'log' (a nil value)

     

    I mean I commented out the two lines with the log-variable, but I'm sure there is an idea behind them.  :-) 

     

    And could you also tell me how I can save which stream / playlist is playing right now in a variable? My idea behind that is, that I want to start my Sonos in the morning with a specific radio station. So first I need to know the official url with the radio stream and afterwards, I want to set the radio station in Sonos VD.

     

    Once again a big thank you. I'm so happy that it works and I can start using Sonos in Scripts, too.... yeahhh...

     

    Dan

    Edited by Danielos
    • Like 1
    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...