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

Is there anyway to control Sonos Plugin via scenes ?


developertas
 Share

Question

Hello friends,

 

I would like to control my sonos devices via scenes. It seems not possible to do that with common ways. So maybe someone in this forum already did that via http methods, rest apis etc. Would be great help if someone has any idea about that.

 

Thanks in advance.

Link to comment
Share on other sites

18 answers to this question

Recommended Posts

  • 0

I think you can call buttons on the virtual device that is availble in the forum, but not on the plugin.

Link to comment
Share on other sites

  • 0
  • Inquirer
  • I think you can call buttons on the virtual device that is availble in the forum, but not on the plugin.

    Yea that's why I'm looking for it. My plan is creating a virtual device then call buttons.. Not possible to call plugin's button.  

    Link to comment
    Share on other sites

    • 0

    Hello friends,

     

    I would like to control my sonos devices via scenes. It seems not possible to do that with common ways. So maybe someone in this forum already did that via http methods, rest apis etc. Would be great help if someone has any idea about that.

     

    Thanks in advance.

     

    Here you can see sample of such code for SONOS plugin:

    You can control your SONOS by interface in two ways:

    1) Create a virtual device and create in it appropriate for you number of buttons.

    The example code for button “play” below:

    HC2 = Net.FHttp(“192.168.80.85”) IP of HC

    HC2:setBasicAuthentication(“admin”,“admin”) —change your credentials

    response = HC2:GET ( "/api/plugins/callUIEvent?deviceID=140&elementName=play_Button&eventType=onReleased ") This code you can achieve by plugin “Firebug” which is add to web browser.

    The IP Address: 127.0.0.1

    TCP Port: 11111

    You can add other buttons in the same way, change only last line: “/api/plugins/callUIEvent?deviceID=140&elementName=play_Button&eventType=onReleased”.

    Then you can control your virtual devices by a scene. It can be a block scene.

    2) You can create a LUA scene which will be control your SONOS.

    An example for push the “pause” button is below:

    -[[

    % properties

    % globals

    -]]

    local function updateDevice(successCallback, errorCallback)

    local http = net.HTTPClient() http:request(‘

    Please login or register to see this link.

    ’, { options = { method = ‘GET’ }, success = successCallback, error = errorCallback })

    end

    deviceId = updateDevice(function(resp)

    print("Status: " .. resp.status)

    end,

    function(err)

    print(‘error’ .. err)

    end

    )

    Link to comment
    Share on other sites

    • 0

    Dont complicate things, unless you want to that is 

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />
     
    Use the built in Fibaro Sonos plugin and do simple LUA scenes that you then call.

    Gets rid of all the virtual device hassles and code. 

     

    Then call the scenes you want.

    Please login or register to see this code.

    Or if you want to use a virtual device slider for ex the volume then just add a slider and then place this code in the slider:

    Please login or register to see this code.

    Done!

    Link to comment
    Share on other sites

    • 0

    Or look at the link in the address bar of your plugin.

    Go to your device and then check the address bar.

    XYZ Will be your device id.

    Please login or register to see this link.

    IP/fibaro/en/devices/plugins.html?id=XYZ

    Link to comment
    Share on other sites

    • 0

     

    Here you can see sample of such code for SONOS plugin:

     

    Your code got me inspired!

    Thank you for this way of controlling Sonos, that was nice, clean and simple!

     

    So i made a scene so you can control Sonos from a regular button and sceneActivation using the S2 button.

    (or use the same code in any VD och scene you want for simple Sonos control)

     

    Using only 1 S2 button you can Play, Pause, Next song, Prev song and volume upp + down.

     

     1 click = Play and Pause

     2 click = Next song

     3 click = Prev song

     Press and hold = Volume change upp and down (works just like a dimmer)

    Please login or register to see this code.

    *added small bugfixes and stuff..

    Link to comment
    Share on other sites

    • 0

    I have a question about this. I'm trying to create a lua-scene where I would like to turn my Sonos off. I use the following command:

     

    fibaro:call(134, "turnOff")

     

    But I can't get it to work. To see if there was something wrong with the plugin I used the command fibaro:call(134, "setVolume", "30") to change the volume, and that works fine.

     

    And I have no problem controlling it with the plugin-interface.

     

    Does anyone have any idea what could be the problem? Has anyone encountered the same problem?

    Link to comment
    Share on other sites

    • 0
    On 2016-04-07 at 9:37 PM, pomfritz said:

    fibaro:call(134, "turnOff")

     

    I'm so happy for finding this. You are all incredibly talented.

     

    I had the same problem as you pomfritz and could also change the volume just like you. I experimented with pause and play instead of turnOff and turnOn and got them to work as they should. Maybe Fibaro has done some changes to the plugin from on version to another? (I run 4.100)

     

    fibaro:call(134, "pause");  

    fibaro:call(134, "play");  

     

     

    Link to comment
    Share on other sites

    • 0
    35 minutes ago, abigbear said:

     

    I'm so happy for finding this. You are all incredibly talented.

     

    I had the same problem as you pomfritz and could also change the volume just like you. I experimented with pause and play instead of turnOff and turnOn and got them to work as they should. Maybe Fibaro has done some changes to the plugin from on version to another? (I run 4.100)

     

    fibaro:call(134, "pause");  

    fibaro:call(134, "play");  

     

     

     

    HC never show all commands and functions that are available in particular plugin. Since there is never any help or short description of the plugin only what you can do is play with it. That is really lame. So I played and except "pause" and "play" you have also commands "stop", "next", "prev" and by the way mute is not working on my HC2 4.100 with plugin!

     

    Link to comment
    Share on other sites

    • 0

     

    1 hour ago, Sankotronic said:

    HC never show all commands and functions that are available in particular plugin. Since there is never any help or short description of the plugin only what you can do is play with it. That is really lame. So I played and except "pause" and "play" you have also commands "stop", "next", "prev" and by the way mute is not working on my HC2 4.100 with plugin!

     

    Great, even though strange with the mute thing. I tried variants like muteOn and muteon but those did not work either. 

     

    Any ideas on how to determine if the player is playing or if it's paused or stopped? I've tried the simple ones in case there were fields for Status and status and Time, time, timeRun, timerun but with no luck.

    Link to comment
    Share on other sites

    • 0

     

    1 hour ago, Sankotronic said:

    HC never show all commands and functions that are available in particular plugin. Since there is never any help or short description of the plugin only what you can do is play with it. That is really lame. So I played and except "pause" and "play" you have also commands "stop", "next", "prev" and by the way mute is not working on my HC2 4.100 with plugin!

     

    Great, even though strange with the mute thing.  

     

     

    I just found some documentation (very cryptic) on http://<HC2IP>/api/devices/<deviceid> and when I put my deviceid in there with the correct IP address I got a long JSON feed where I found more variables. Like state which tells if the player is playing or not. Could not get mute to work with this information either though. But state works fine.

     

    local state = fibaro:getValue(id,'state')

     

     

    Link to comment
    Share on other sites

    • 0
    48 minutes ago, abigbear said:

     

     

    Great, even though strange with the mute thing. I tried variants like muteOn and muteon but those did not work either. 

     

    Any ideas on how to determine if the player is playing or if it's paused or stopped? I've tried the simple ones in case there were fields for Status and status and Time, time, timeRun, timerun but with no luck.

    Hi @abigbear,

     

    Bellow ones are actually listed :-) Just use and you will get answer like "PLAYING" or "STOPPED".

    Please login or register to see this code.

    to check if it is muted it returns 1 for muted and 0 for not

    Please login or register to see this code.

    If you want to now volume that is set then use

    Please login or register to see this code.

    For the rest you can play yourself. Sonos plugin was first thing I installed almost a year ago but I wasn't so happy with it. Then I replace it with virtual device Sonos remote made by Krikroff. It is also not perfect but it has ability to play TTS messages what I found very handy so that my HC2 can tell me some notifications. There is also one very nice solution for controlling Sonos speakers but requires small server like raspberry PI and some software for which I can't find at the moment

    Link to comment
    Share on other sites

    • 0

    Hi,

     

    Thank you all for this. I prefer to go with the plugin, easier to use. 

     

    Does anyone know what is the command for the Sonos plugin to preselect a playlist or radio station before sending the play command ?

     

    Thank you.

    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.

     Share

    ×
    ×
    • Create New...