Announcement

Collapse
No announcement yet.

How to control Sonos Volume via a script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to control Sonos Volume via a script

    Hi,

    I'm trying to control the volume of a Sonos player by using hs.SetDeviceValueByRef(299, Volume_Parameter, True), but while that does change the Value of the device in the Device Management screen, the Volume of the Sonos Player itself does not change, i.e. there is not change in the actual volume of the device.

    Anyone a clue why this does not work or how to make it to work?

    Cheers,
    Jan

    #2
    Originally posted by janjanssen View Post
    Hi,

    I'm trying to control the volume of a Sonos player by using hs.SetDeviceValueByRef(299, Volume_Parameter, True), but while that does change the Value of the device in the Device Management screen, the Volume of the Sonos Player itself does not change, i.e. there is not change in the actual volume of the device.

    Anyone a clue why this does not work or how to make it to work?

    Cheers,
    Jan
    If you turn the PI's debug flag on and you run your script, do you see anything being logged? Something like:

    Jan-15 8:47:08 AM Sonos SetVolumeLevel called for ZonePlayer = Office2 with values Channel=Master Value=14
    Jan-15 8:47:08 AM
    Sonos TreatSetIOEx called for Zone = Office2 with Ref = 3671, Index 1, controlFlag = False, ControlString, ControlType = ValuesRangeSlider, ControlValue = 14, Label = Volume (value)%
    Jan-15 8:47:08 AM
    Sonos SetIOEx called for Ref = 3671, Index 1, controlFlag = False, ControlString, ControlType = ValuesRangeSlider, ControlValue = 14, Label = Volume (value)%
    Jan-15 8:47:08 AM
    Sonos SetIOMulti set value: 14->ref:3671
    Jan-15 8:47:08 AM
    Sonos SetIOMulti called
    Jan-15 8:47:08 AM
    Device Control Device: Sonos Office2 Volume to Volume (value)% (14) by/from: CAPI Control Handler

    If the PI isn't being called than there is something wrong with the script

    Dirk

    Comment


      #3
      I would think that using HS3, just changing the Device Value does not change the volume, you must use CAPI controls.

      I used tenScriptAid to generate the CAPI script statements to set the volume of my Offfice Sonos Player to 5.

      An image is attached that shows the generated code. With tenScriptAid, you can paste it directly into your script.

      tenholde
      Attached Files
      tenholde

      Comment


        #4
        is there a CAPIControl method or any other means to change the Sonos RADIOSTATION NAME device ? i do see ability to change volume, track position, etc, but when i select RADIOSTATION NAME, the CAPIControls listbox is blank. thanks
        Attached Files

        Comment


          #5
          Originally posted by heychristian View Post
          is there a CAPIControl method or any other means to change the Sonos RADIOSTATION NAME device ? i do see ability to change volume, track position, etc, but when i select RADIOSTATION NAME, the CAPIControls listbox is blank. thanks
          There are no control for that device, just a devicestring. Not sure what you are trying to do but I would suspect you simply need to change the devicestring.

          Dirk

          Comment


            #6
            i am trying to use a SCRIPT in HS3 to select a RADIOSTATION NAME. the picture below illustrates that action in the Events page of the web control, but i am trying to execute it via Script
            Attached Files

            Comment


              #7
              Originally posted by heychristian View Post
              i am trying to use a SCRIPT in HS3 to select a RADIOSTATION NAME. the picture below illustrates that action in the Events page of the web control, but i am trying to execute it via Script
              I see ....

              There are no HS devices that you could use to select content, that was supposed to be part of the MediaAPI in HS3 (MusicAPI in HS2). Sadly after more than 4 years that API never worked for multiple instance types of PIs and I've given up.

              If you are good at scripting, you should use Visual Studio, import the hspi_sonos.exe and browse its objects. Don't ask me to document the API, I don't have time for that nor will I guarantee that the functions will never change but this would be the method to call

              Public Sub PlayMusic(ByVal Artist As String, Optional ByVal Album As String = "", Optional ByVal PlayList As String = "", Optional ByVal Genre As String = "", Optional ByVal Track As String = "", Optional ByVal StartWithArtist As String = "", Optional ByVal StartWithTrack As String = "", Optional ByVal TrackMatch As String = "", Optional ByVal AudioBook As String = "", Optional ByVal PodCast As String = "", Optional ByVal ClearPlayerQueue As Boolean = False, Optional QueueAction As QueueActions = QueueActions.qaDontPlay)

              Put the RadioStations name in the "Playlist" variable, all else leave blank.

              Search the forum how you make calls to a MultipleInstanceSingleEXE plug-in.

              Dirk

              Comment


                #8
                thank you for your advice--i will explore it. for the short term, i will create an event for each radiostation name i want to select ie "turn on" , and have my vb.net script use the HS.TriggerEvent method.

                Comment


                  #9
                  Has anyone got this to work? I am trying to use a script to set different volume levels on a player. I cant seem to find where the volume parameter fits in

                  Comment


                    #10
                    Originally posted by prsmith777 View Post
                    Has anyone got this to work? I am trying to use a script to set different volume levels on a player. I cant seem to find where the volume parameter fits in
                    Per earlier post, the following works for me, and came from tenScriptAid:

                    Code:
                     Public Sub Main(ByVal Parms As Object)
                            Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(hs.GetDeviceRefByName("Sonos Office Volume"), True, "Volume (value)%", False, False)
                            cc.ControlValue = 10
                            Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
                        End Sub
                    This sets the volume of my Office Player to 10.

                    tenholde
                    tenholde

                    Comment


                      #11
                      Thanks. That script works for me .

                      Comment


                        #12
                        This Easy Trigger event is fired via a Minimote button. Works great...

                        Attached Files

                        Comment


                          #13
                          I'm actually trying to do something similar. I am trying to use one minimote button (others are already in use) to toggle Sonos between On volume low - volume med -volume high - Off. I've got the volume part down now (thanks tenholde), but am having trouble getting the CapiControl for turning the Sonos on and off. I've been guessing so far using ContolValue 1 or 2 and ControlString "Stopped", "Playing" with no luck. Guess I'll need to use tenScripting to see the exact phrasing.

                          Comment


                            #14
                            There is a play-pause device that toggles between the two...

                            Attached Files

                            Comment

                            Working...
                            X