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


Recommended Posts

Posted (edited)

Here is a code lib to control Sonos - it's under development.

The goal is to have a code base that's easy to integrate in other projects or build custom QAs.

Please login or register to see this link.

 

It's based on the local LAN API and using websockets listening for Sonos status changes - no polling(!)

 

Sonos commands

Please login or register to see this code.

 

Example of use:

Please login or register to see this code.

 

The sonos object when created does some initialization and when ready call a callback function, in this case the main of the example, logging and testing functionality.

More to come...

 

Here is an example of a QA that uses the library. The QA is very reactive on changes in the system.

Because the current HC3 UI model is a mess this QA is just a proof-of-concept.

The QA's type is com.fibaro.player which doesn't render in the mobile app withe the new UI...

However, it works in the web UI.

Switching to the old UI model makes the interface a bit ugly as drop-downs miss labels etc...

In the future it will hopefully be possible to create more beautiful app compatible QAs...

It's also hardcoded to the IP of my sonos, so it requires some coding to get running on your system 😉

 

Please login or register to see this attachment.

Please login or register to see this code.

Support will be added for grouping of players. The logic is there but not connected to the UI. The family is using the Sonos player at the moment so I'm not allowed to play with them to verify the code... ;.-) 

Edited by jgab
added playModes
  • Like 4
  • Topic Author
  • Posted (edited)

    Here is a super simple way to integrate the library in a QA. The previous example relied on a callback function and can be a bit trickier to integrate with...

    First install 

    Please login or register to see this link.

     in a separate QA file in your QA

    ...and then we define 

    Please login or register to see this code.

    on top-level in our main QA file, and if everything goes fine we have an initialized self.sonos object when QuickApp:onInit() is called.

    The value assigned is a table with the ip address. Before :onInit() is called it can be difficult to get the ip from the QA's quickAppVariables.

    Thus if the value starts with "qvar:", the other part will be assumed to be the quickAppVariable where the ip address is stored. "ip" in this example.

     

    Please login or register to see this code.

    For now it really relies that everything is setup (that the qvar exists etc). Will add some better error handling in the future...

    Edited by jgab
    • Thanks 1
    Posted

    Great work @jgab

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