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


Question

Posted

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

Recommended Posts

  • 0
Posted

@Danielos,

 

Regarding the addition of the radio you must add it to the list of favorites in the application SONOS. Virtual device can play the first (maximum 5 currently)

  • Thanks 1
  • 0
  • Inquirer
  • Posted

    @Krikroff It works and that's great. Thank you again!! :-)

     

    • Like 1
    • 0
    Posted

    @Danielos, enjoy :D

    • 0
    Posted (edited)

    Hi @Krikroff,

    first of all my best congratulations for this nice VD.

    It works pretty well and it's quite intuitive.

    I have few questions and I would be pleased if you can kindly give me some advices:

     

    1.is there any documentation available in regards with the VD? I was seeking for something explaining all the functionalities and how to make them work properly but i couldn't find it. Sorry if this is already available and I just couldn't retrieve it.

    2. I'm looking for implementing a feature where i can stream a Playlist from my NAS. It seems that the file extension of the radio station is m3u (as for the playlists) but if i send a playlist in streaming, it doesn't work. Testing this option I've basically frozen the VD and I had to uninstall and reinstall the VD to get it back on his full functionality. Any clue? Is there any  Character limitation? (I had few blank spaces and or underscore).

    3.Is it possible to stream a Spotify playlist/song? Should it be done through URI or url? 

    4. From my understanding, once duration (of stream or TTS) is set and a command is launched, the VD cannot receive any overriding command. Meaning that it has to complete the previous command before receiving a new one. Is there any way to override this behavior? I was using the stream script to play specific songs, but i would like this to be paused by any TTS command.

    Also if i leave the duration in "auto" or I skip it, the song doesn't play for more than a fixed amount of time while I would need it to play until a new event is triggered. Any suggestion?

     

    Again thanks for the amazing job

    Best

    Whixter

     

    EDIT: I just found most of the answers on another post within the Forum:

     

    Sorry for posting here but i got confused with the different open topics.

    I found there that there is a mod from Drboss to make the VD play playlists or file without time limit (I understood that the time limit is a feature developed on purpose for TTS reasons so it should be feasible through this mod).

    Thanks anyway.

     

    Edited by Whix
    adding few details
    • 0
  • Inquirer
  • Posted

    @Krikroff Unfortunately a new problem came up..... the TTS script worked, but now, when I start, I receive this error:

     

    Quote

    [DEBUG] 14:19:33: Unable to process data, check variable
    [DEBUG] 14:19:33: 2019-01-27 14:19:33.682032 [ fatal] Unknown exception: /opt/fibaro/scenes/36.lua:26: attempt to index local 'f' (a nil value)

     

    And the script is that:

     

    Please login or register to see this code.

    And the error comes from this part: "local _f = fibaro" . 

     

    How can I fix that?

     

    thank you again. ;-)

     

    Dan

    • 0
    Posted (edited)

    Hello, can you confirm that the VD (sonos  remote) still works? or it does not work anymore since ...

    Edited by Krikroff
    • 0
  • Inquirer
  • Posted

    @Krikroff Oh no... it really doesn't work again even I didn't change something. :-( 

    • 0
    Posted

    @Danielos, hum... variable seems to be corrupted, but I don’t know why.

    Solution :  could you follow the procedure I gave previously

     

    what I know is that some actions from the variables panel corrupt them :(

    • 0
  • Inquirer
  • Posted

    @Krikroff: thank you for the answer. I mean as I saw, there are other script using variables can a script from there be the problem? Honestly speaking, I can't trust something which corrupts so often and I can't repair easy..... every time removing everything, adding all VD's and changing the scripts and scenes can't be the real solution. 

    • 0
    Posted

    Hi @Danielos, I agree with you this is not usable if you have to reinstall permanently!

    The VD is used by many users without problems, I use it daily without special maintenance. I would like to understand what is problematic in your case in order to find a solution ;) .

    how does the VD over a few days in basic use(Play, stop etc), without doing TTS?

    • 0
    Posted

    Hello
    Is there also the possibility with the Sonos Remote VD to play an mp3 from a Nas?

    • 0
    Posted

    You can try 

     

    Please login or register to see this code.

     

     

     

    • Like 1
    • 0
    Posted

    Hello! can i brrow this thread, I have almost same problem.

     

    My problem is that TTS to my sonos is kinda working. I use the sonos remote 1.01 and I can see "transitioning" when TTS is playing like "dinner at 20:00" but no volume??? Its like its on mute or something? Im running latest firmware on sonos. Think its like version 10.

     

    what is wrong with the setup? everything worked fine until like 2-3 weeks ago after updating fibaro to latest and sonos to lates firmware. 

     

    anyone else having same issue?

     

    so Im not getting any error messages, TTS is playing but seems like sonos speaker is on mute or something becuse no sound. 

     

    bets regards K

    • 0
    Posted

    First of all, my sincere thanks to @Krikroff for the VD and a great implementation.

    I have just got my Sonos One, and the TTS is working pretty well. I was wondering if I could find out if it is possible to auto resume the music that was playing (e.g. music from Spotify) before the TTS?

     

    Thank-you!

    • 0
    Posted

    Hi, I'm having the same issue with that plugin and my brief investigation suggests that the problem can arise from usage of two instances of the plugin for two different sonos players. In my case there are two. And, I believe that's crucial, the x_sonos_object global variable can not be properly shared between the two.

     

    That's just my brief opinion

    • 0
    Posted

    Hi, both Sonos  player are having different ID, so if you want on both copy the rule and modify ID number.

    I have one Sonos wit two numbers see local

    If there is a play list

    This will resume playing on Sonos just one song then finished

    local    SonosPlayer                    =    212
    local    SonosPlayerKrikrof                =    249
    if
     ( tonumber(fibaro:getGlobalValue("Dummy")) == tonumber("0") )
      then
     
     

      ------

    local sid, bid = 249, 28
    -- Create TTS params object
    local params = {
      -- TTS Message
      message = "Hallo, Saartje zegt de deurbel gaat er staat iemand aan de deur te bellen",  
      duration = 'auto',    -- Duration: "auto", xx seconds
      language = "nl-nl",    -- Language: fr-FR
      volume = 65            -- Volume
    }
    local _f = fibaro
    local _x ={root="x_sonos_object",load=function(b)local c=_f:getGlobalValue(b.root)if string.len(c)>0 then local d=json.decode(c)if d and type(d)=="table"then return d else _f:debug("Unable to process data, check variable")end else _f:debug("No data found!")end end,set=function(b,e,d)local f=b:load()if f[e]then for g,h in pairs(d)do f[e][g]=h end else f[e]=d end;_f:setGlobal(b.root,json.encode(f))end,get=function(b,e)local f=b:load()if f and type(f)=="table"then for g,h in pairs(f)do if tostring(g)==tostring(e or"")then return h end end end;return nil end}
    -- Make a request to the remote to process params object instantly
    _x:set(tostring(sid), { tts = params })
    _f:call(sid, "pressButton", bid)

     
           fibaro:call(SonosPlayer, "pressButton", "9");
     
    ----

     

    .

    • 0
    Posted
    On 5/12/2019 at 7:56 PM, Vadim Krasnoslobodtsev said:

    Hi, I'm having the same issue with that plugin and my brief investigation suggests that the problem can arise from usage of two instances of the plugin for two different sonos players. In my case there are two. And, I believe that's crucial, the x_sonos_object global variable can not be properly shared between the two.

     

    That's just my brief opinion

     

    Hi @Vadim Krasnoslobodtsev ,

     

    I have 3 sonos Play 1 and one Sonos Play 3 speakers. For each of them I installed @Krikroff Sonos Remote VD v1.0.1 and use them without any problems. Global variable x_sonos_object can store data from all four VD's.

    I suggest to use fibaro:sleep(X) function between commands sending to Sonos speakers where X depends on many factors, but usually 2000 (it is 2 seconds) works perfectly fine.

     

    BTW both my HC2 and Sonos speakers are on the latest non beta firmware.

     

    If you don't hear TTS message then please check your VOICERSS api_key that you setup on VD. Last month also there was some outages on their servers and TTS didn't work for several days.

     

    • 0
    Posted
    25 minutes ago, Sankotronic said:

     

    Hi @Vadim Krasnoslobodtsev ,

     

    I have 3 sonos Play 1 and one Sonos Play 3 speakers. For each of them I installed @Krikroff Sonos Remote VD v1.0.1 and use them without any problems. Global variable x_sonos_object can store data from all four VD's.

    I suggest to use fibaro:sleep(X) function between commands sending to Sonos speakers where X depends on many factors, but usually 2000 (it is 2 seconds) works perfectly fine.

     

    BTW both my HC2 and Sonos speakers are on the latest non beta firmware.

     

    If you don't hear TTS message then please check your VOICERSS api_key that you setup on VD. Last month also there was some outages on their servers and TTS didn't work for several days.

     

    Hi,

     

    Good to know that there might be many VDs simultaneously. And thanks so much for "sleep" highlight.

    • 0
  • Inquirer
  • Posted

    I'm playing an MP3 file (ALARM). Unfortunately, even after virtually pushing the stop-button (after the sleep timer), it takes normally aroung 5-10 secs until it really stops. Any ideas? Thank you for the help!!

     

    Please login or register to see this code.

     

    • 0
    Posted

    Hi everybody,

     

    Can you investigate the use of the Fibaro Sonos plugin instead of the VD. With the plugin one can uese the following commands :

    • fibaro:call(device_id, "pause");  

    • fibaro:call(device_id, "play"); 

    • fibaro:call(device_id, "stop");  

    • fibaro:call(device_id, "next");
    • fibaro:call(device_id, "prev");
    • fibaro:call(device_id, "turnOff");

    • fibaro:call(device_id, "turnOn");

    • fibaro:getvalue(device_id, "state");

     

    Where "device_id" is the id of the plugin.

    The plugin shows a list of available playlists. Does anyone know how to preselect a playlist before sending the play command ?
    For your information, I did not acquire any Sonos for now but I am just investigating their implementation. I don't want to go with any heavy coded VD done by many persons but simple official plug-in commands. With the plug-in, no need to create variables and maintain them. See how the commands above are simple. They turn you to the use of the VD, which is more complicated !

     

    Can you please install the plugin and follow this link "http://<HC2IP>/api/devices/<device_id>" Where "<HC2IP>" is the IP adress of your fibaro HC2 and "<device_id>" is the id of the Sonos plugin, analyse it and then tell me if one can select a playlist or a radio station via a command before executing the play command ?

     

    Thank you.

     

    • Like 1

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