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

Controlling Sonos audio devices on the HC2


budda
 Share

Question

I've built a simple PHP based Sonos controller which can take a list of commands (a macro) and perform them on a specified Sonos device on your network.

This is all done over a HTTP GET request. It works great from a browser, and I've tried to get it working via the HC2 Virtual Devices functionality.

Attached is a screenshot showing how i've configured the HC2 Virtual Device (based on some

Please login or register to see this link.

regarding the "HTTP/1.10x0D0x0A0x0D0x0A" string at the end).

However sadly it is not yet working. Changing the volume slider in HC2 doesn't make a change in the Sonos remote control app. Doing it from a web browser does update the Sonos controller app nearly instantly.

Any ideas / suggestions to make this work? Or should I wait for this LUA scripting in the new HC2 update due out ?

Please login or register to see this image.

/emoticons/default_icon_mrgreen.gif" alt=":mrgreen:" />

Please login or register to see this attachment.

Link to comment
Share on other sites

Recommended Posts

  • 0
  • Inquirer
  • To add to this, if I telnet to my webserver which runs the Sonos controller script I can control the Sonos device fine too.

    Please login or register to see this code.

    I see the volume slider in the Sonos controller jump to the specified 50% point. Perfect.

    Now to make HC2 send the same request...

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Success - didn't need the hex junk at the end of the GET request, just a newline adding. See attached screenshot for the working volume slider config.

    Shame there is no current way to use the GetVolume() from the Sonos device and set the HC2 slider to the same value when the virtual device is first displayed. Feature request for HC2 maybe ?

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I've now got my Sonos Play:5 working with play, stop, mute toggle (and specified mute state), volume slider, previous, next, shuffle mode, repeat mode.

    The layout of the virtual device buttons isn't very flexible (see attached) but at least it works - a step forward!

    What wasn't so nice to see is that there's no UI in the iOS app to interact with the virtual devices set up in HC2, nor is there a way to activate any of my virtual device buttons from a scene - so no turning on my Sonos after a movement sensor is triggered or a time of the day is met. Bah.

    Please login or register to see this attachment.

    Link to comment
    Share on other sites

    • 0

    Awesome. Love the icon

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    I'm going to get one of these sent to me to setup in my office. I'll more than likely come to you directly if I run into any trouble.

    I'm confident the development of the virtual devices is being optimised alongside a native iPad application. The buttons can still be used in scenes so possibly (as a current alternative) build a scene button for each and control the virtual device through the scene interface on your iOS app? I believe you can create your own icons for scenes now too

    Link to comment
    Share on other sites

    • 0
    Guest GrZeCh

    Hello,

    does your Sonos allows to control it using UPnP? I've managed to start controlling my Sony STR-DA3600ES tuner without anything in the middle. So far I can't do this without using PHP because some special headers must be set but I think if someone from Fibaro dev team could take a look at it maybe it would start working.

    My PHP code:

    $soap_do = curl_init();

    $xml = '0Master0';

    $headers = array(

    "Content-type: text/xml;charset=\"utf-8\"",

    "SOAPAction: \"urn:schemas-upnp-org:service:RenderingControl:1#SetMute\"",

    "Content-length: ".strlen($xml),

    );

    curl_setopt($soap_do, CURLOPT_HTTPHEADER, $headers);

    curl_setopt($soap_do, CURLOPT_URL, "http://ADRESIPTUNERA:PORT/upnp_control_2" );

    curl_setopt($soap_do, CURLOPT_POST, true );

    curl_setopt($soap_do, CURLOPT_POSTFIELDS, $xml);

    Software which allowed me to discover all functions which can be runned on my Sony tuner:

    Please login or register to see this link.

    Screens:

    Please login or register to see this link.

    /screens

    If only Fibaro HC2 would able to control UPnP devices it would be great.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hello,

    does your Sonos allows to control it using UPnP? I've managed to start controlling my Sony STR-DA3600ES tuner without anything in the middle. So far I can't do this without using PHP because some special headers must be set but I think if someone from Fibaro dev team could take a look at it maybe it would start working.

    My PHP code:

    $soap_do = curl_init();

    $xml = '0Master0';

    $headers = array(

    "Content-type: text/xml;charset=\"utf-8\"",

    "SOAPAction: \"urn:schemas-upnp-org:service:RenderingControl:1#SetMute\"",

    "Content-length: ".strlen($xml),

    );

    curl_setopt($soap_do, CURLOPT_HTTPHEADER, $headers);

    curl_setopt($soap_do, CURLOPT_URL, "http://ADRESIPTUNERA:PORT/upnp_control_2" );

    curl_setopt($soap_do, CURLOPT_POST, true );

    curl_setopt($soap_do, CURLOPT_POSTFIELDS, $xml);

    Software which allowed me to discover all functions which can be runned on my Sony tuner:

    Please login or register to see this link.

    Screens:

    Please login or register to see this link.

    /screens

    If only Fibaro HC2 would able to control UPnP devices it would be great.

    Yes the Sonos devices are all controlled via UPnP.

    I was thinking/hoping that one day the HC2 will allow uploading the PHP code i've written directly on to the HC2 hardware, seeing as it also runs on PHP. Until then i'm running the PHP middleware on my NAS box.

    As for sending a UPnP command directly from HC2, the packet would look like:

    Please login or register to see this code.

    The above would set the mute function to on '1'.

    I've not tried, but that could possibly be pasted in to the virtual device button 'string to send'.

    I didn't both doing this for my Sonos integration as I wanted to have the ability to send a string of control commands from one Virtual device button.

    Link to comment
    Share on other sites

    • 0
    Guest GrZeCh

    Not working. I think:

    POST /MediaRenderer/RenderingControl/Control HTTP/1.1

    should be more like

    POST /upnp_control_2 HTTP/1.1

    and HOST: 192.168.88.141:1400 should contain my tuner IP address with 8888 port? I'm wondering if quotation marks shouldn't be escaped.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • yeah the post above is my upnp call to one of my sonos devices. so it's my IP and port for the sonos device. You'd need to amend and try

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    Link to comment
    Share on other sites

    • 0
    Guest GrZeCh

    I'll try to solve this when beta virtual device edition form will be fixed.

    Can you explain a little:

    "I didn't both doing this for my Sonos integration as I wanted to have the ability to send a string of control commands from one Virtual device button."

    ?

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • I'll try to solve this when beta virtual device edition form will be fixed.

    Can you explain a little:

    "I didn't both doing this for my Sonos integration as I wanted to have the ability to send a string of control commands from one Virtual device button."

    ?

    To send a control command to my Sonos devices I call my PHP script along the lines of:

    Please login or register to see this code.

    The cmd=mute:0,play bit allows me to string together a series of commands to send to the Sonos via UPnP one after another. In the above example I un-mute the device and play whatever is in the list.

    Other command "macros" might be to select a radio station, set volume level, and play at a certain time of the day and/or when motion is detected in a certain room, for example.

    Link to comment
    Share on other sites

    • 0
    Guest GrZeCh

    So it looks like good feature request

    Please login or register to see this image.

    /emoticons/default_smile.png" alt=":)" srcset="https://forum.fibaro.com/uploads/emoticons/[email protected] 2x" width="20" height="20" />

    Link to comment
    Share on other sites

    • 0
    Guest deraaij

    Please login or register to see this code.

    The above would set the mute function to on '1'.

    I've not tried, but that could possibly be pasted in to the virtual device button 'string to send'.

    I didn't both doing this for my Sonos integration as I wanted to have the ability to send a string of control commands from one Virtual device button.

    Hi Budda could you check if this works for you (I couldn't get it to work but I am not that familiar with it)?

    Thanx in advance!

    Link to comment
    Share on other sites

    • 0
    Guest GrZeCh
    yeah the post above is my upnp call to one of my sonos devices. so it's my IP and port for the sonos device. You'd need to amend and try

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    Hello,

    have you tried to run any action on your upnp device directly from HC2 without using your "proxy" connection? I'm having problems with even monitoring any connection from HC2 to my Sony tuner.

    Sony runs on 8888 port and in Wireshark I've set filtering to:

    tcp.port == 8888 and ip.dst_host == SONYIPADDRESS

    and when I'm executing comands from my desktop from PHP script Wireshark captures all connections but when I'm trying to make any connection from HC2 Virtual Device there is literally nothing in Wireshark which makes me wonder if Virtual Device implementation on HC2 expects maybe some proper response from destination host before it start connecting. Any ideas?

    Thanks

    EDIT: Quick info: when I've used putty set to telnet and connected to my localhost webserver it just disconnected me right away but when I've tried to connect to my Sony tuner connection window didn't dissapeared right away after establishing connection and waited for some action from my side. Window dissapears after pressing any character on keyboard. Can this cause any problems with connectivity from HC2 side?

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Please login or register to see this code.

    The above would set the mute function to on '1'.

    I've not tried, but that could possibly be pasted in to the virtual device button 'string to send'.

    I didn't both doing this for my Sonos integration as I wanted to have the ability to send a string of control commands from one Virtual device button.

    Hi Budda could you check if this works for you (I couldn't get it to work but I am not that familiar with it)?

    Thanx in advance!

    after trying a number of combinations with the headers i got no success on the 2.138 beta.

    mute via my php script (GET request) was still working on the same virtual devices though.

    Maybe somebody at Fibaro can confirm how a POST request can be formatted in the UI?

    Link to comment
    Share on other sites

    • 0
    Guest GrZeCh

    Have you tried making POST to some PHP script or directly to UPnP device?

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Have you tried making POST to some PHP script or directly to UPnP device?

    The point was to try and avoid any php script running on another server.

    Link to comment
    Share on other sites

    • 0
    Guest GrZeCh
    Have you tried making POST to some PHP script or directly to UPnP device?

    The point was to try and avoid any php script running on another server.

    Yes I know but previously you was using proxy for your calls to HC2 with GET. Your information that you can't make POST was not clear if it is POST to your server or POST directly to UPnP device.

    Have you checked if connection is even made using Wireshark? I'm asking because I couldn't make (Wireshark was not getting anything) any (GET or POST) connection to my Sony tuner (UPnP). But when I've changed Virtual Device IP from Sony tuner to my desktop computer which is running IIS server Wireshark captured right away packets from HC2 so I have suspicion that my UPnP Sony tuner is somehow different than normal www server (for example when I'm trying to connect to it using telnet I must type anything to make telnet window dissapear but when I'm using telnet to my local desktop www server telnet window dissapears right away after making connection).

    Link to comment
    Share on other sites

    • 0

    Really exciting about how could we integrate our sonos devices into a HC2 "inteligence"...

    Do you have any good news about this integration or how LUA or new scripting improve to play certain songs after a certain event?

    Ideas:

    -.Wakeup music... Play certain list or songs starting at a very low volume and increasing...

    -.Alarm- To play a selfmade file (siren, speech ...), when certain event is positive

    -.Turn off play when you live out your home...

    Cheers!

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Because the beta v2 for HC2 didn't work with the Fibaro dimmer modules i've rolled back my HC2 to v1.x so no LUA/API to fiddle with for now.

    Currently the Sonos controller PHP scripts will need to be hosted elsewhere on the home network to interact with Sonos.

    I've been on holiday/busy so not done anything more since the previous forum posts.

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