Announcement

Collapse
No announcement yet.

Set volume level with script

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

    Set volume level with script

    Hi,

    I would like to set the volume level for a sonos zone to a specific value using script. ie set zone xx to volume level 50. I can do it using an event, but I need to script it so I can pass a value from Hstouch.

    Is this possible?

    Cheers,
    Rob

    P.S It's looking good since i last used your test version a year ago!

    #2
    Hi Rob,

    check the help file at the end for all the API information. Your script would look something like this:

    Public Sub SetYourVolume (ZoneNameOrIndex As String, NewVolume As Integer)
    Dim pi As Object
    pi = hs.Plugin("SONOSCONTROLLER")
    If pi Is Nothing Then
    hs.writelog("Script", "empty")
    Exit Function
    End If
    Dim MusicAPI
    MusicAPI = pi.GetMusicAPI(ZoneNameOrIndex)
    MusicAPI.Volume(NewVolume)
    End Sub

    Let me know if you have other questions

    Dirk

    Comment


      #3
      Thanks Dirk,

      I didn't realise .Volume was able to set the value. I thought it just returned it. Doh!

      Rob

      Comment


        #4
        Originally posted by starker View Post
        I didn't realise .Volume was able to set the value. I thought it just returned it. Doh!
        Indeed help file not clear on this. Updated help file, will be released together with next beta.

        Thanks

        Dirk

        Comment


          #5
          Dirk, how would you call the above in HS touch? I think I'm doing something wrong. I assumed it was the following but I suppose not?
          Code:
          &hs.runex("NameOfVBscripthere.vb","NameofSubHere","ZoneName","VolumeLevel")
          Thanks!

          Edit: regardless of the way it's called I get an error in the End Function routine stating that this is the wrong place for it? It works (well, I still can't pass it the right parameters) if I remove the 'End Function' in that if loop.
          Last edited by manxam; January 27, 2013, 03:01 PM.

          Comment


            #6
            Originally posted by manxam View Post
            Dirk, how would you call the above in HS touch? I think I'm doing something wrong. I assumed it was the following but I suppose not?
            Code:
            &hs.runex("NameOfVBscripthere.vb","NameofSubHere","ZoneName","VolumeLevel")
            Thanks!

            Edit: regardless of the way it's called I get an error in the End Function routine stating that this is the wrong place for it? It works (well, I still can't pass it the right parameters) if I remove the 'End Function' in that if loop.
            Not sure I'm following on your remark about "End Function"? Can you post the script here as well. Seem to remember there is a limitation on the # of parameters you pass into a script. If you are over the limit of parameters, pass then as a string separated by lets say "|" characters and do a split inside the script.

            I'm this week on the road so I have no access to pretty much anything.

            Dirk

            Comment


              #7
              The script is one that you posted a couple of posts up.
              I tried to change it to a (ByVar parms) and split the parms. I then used "Zonename;VolumeLevel" in my runex but that failed too.

              Ahh well, I'll keep tinkering

              Thanks!

              Comment


                #8
                EDIT: I get the following error with the second script. it's a long string that includes "Parameter count mismatch"..
                I get the following error in my script "Overload resolution failed because no accessible 'Volume' accepts this number of arguments."


                Here's my attempt with splitting the parms but I can't get it to work either. Called with:
                Code:
                &hs.runex("NameOfVBscripthere.vb","SetVolume","ZoneName;50")
                Code:
                Public Sub SetVolume(ByVal parm)
                	Dim pi As Object
                	pi = hs.Plugin("SONOSCONTROLLER")
                	If pi Is Nothing Then
                		hs.writelog("Script","empty")
                	End If
                	Dim Parms() = {}
                	Dim ZoneName, NewVolume
                	Try
                        Parms = Split(Parm, ";")
                    Catch ex As Exception
                        hs.writelog("Sonos Controller Script", "1 - Error in SetVolume with error = " & Ex.Message)
                        Exit Sub
                    End Try	
                	Dim MusicAPI
                	ZoneName = Parms(0)
                	NewVolume = Parms(1)
                Try
                	MusicAPI = pi.GetMusicAPI(ZoneName)
                	MusicAPI.Volume(NewVolume)
                    Catch ex As Exception
                        hs.writelog("Sonos Controller Script", "2 - Error in SetVolume with error = " & Ex.Message)
                        Exit Sub
                    End Try
                End Sub
                The script that you posted was much simpler and I'd like to use it. Called with:
                Code:
                &hs.runex("NameOfVBscripthere.vb","SetVolume","ZoneName","50")
                Code:
                Public Sub SetVolume (ZoneNameOrIndex As String, NewVolume As Integer)
                Dim pi As Object 
                pi = hs.Plugin("SONOSCONTROLLER")
                If pi Is Nothing Then
                hs.writelog("Script", "empty")
                Exit Function
                End If
                Dim MusicAPI 
                MusicAPI = pi.GetMusicAPI(ZoneNameOrIndex)
                MusicAPI.Volume(NewVolume)
                End Sub
                Last edited by manxam; January 27, 2013, 05:30 PM.

                Comment


                  #9
                  Originally posted by manxam View Post
                  EDIT: I get the following error with the second script. it's a long string that includes "Parameter count mismatch"..
                  I get the following error in my script "Overload resolution failed because no accessible 'Volume' accepts this number of arguments."


                  Here's my attempt with splitting the parms but I can't get it to work either. Called with:
                  Code:
                  &hs.runex("NameOfVBscripthere.vb","SetVolume","ZoneName;50")
                  Code:
                  Public Sub SetVolume(ByVal parm)
                      Dim pi As Object
                      pi = hs.Plugin("SONOSCONTROLLER")
                      If pi Is Nothing Then
                          hs.writelog("Script","empty")
                      End If
                      Dim Parms() = {}
                      Dim ZoneName, NewVolume
                      Try
                          Parms = Split(Parm, ";")
                      Catch ex As Exception
                          hs.writelog("Sonos Controller Script", "1 - Error in SetVolume with error = " & Ex.Message)
                          Exit Sub
                      End Try    
                      Dim MusicAPI
                      ZoneName = Parms(0)
                      NewVolume = Parms(1)
                  Try
                      MusicAPI = pi.GetMusicAPI(ZoneName)
                      MusicAPI.Volume(NewVolume)
                      Catch ex As Exception
                          hs.writelog("Sonos Controller Script", "2 - Error in SetVolume with error = " & Ex.Message)
                          Exit Sub
                      End Try
                  End Sub
                  The script that you posted was much simpler and I'd like to use it. Called with:
                  Code:
                  &hs.runex("NameOfVBscripthere.vb","SetVolume","ZoneName","50")
                  Code:
                  Public Sub SetVolume (ZoneNameOrIndex As String, NewVolume As Integer)
                  Dim pi As Object 
                  pi = hs.Plugin("SONOSCONTROLLER")
                  If pi Is Nothing Then
                  hs.writelog("Script", "empty")
                  Exit Function
                  End If
                  Dim MusicAPI 
                  MusicAPI = pi.GetMusicAPI(ZoneNameOrIndex)
                  MusicAPI.Volume(NewVolume)
                  End Sub
                  Declare the newVolume variable as an Integer and convert input parm from string to integer.

                  If that still doesn't work, check the help file for correct syntax. As I wrote in the older post .... "would look something like this"

                  Dirk

                  Comment


                    #10
                    Thanks Dirk but unfortunately I'm met with the same error:
                    Code:
                    SetVolume with error = Overload resolution failed because no accessible 'Volume' accepts this number of arguments.
                    The help file merely states the below in the MusicAPI sub-heading:
                    Public Property Volume As Integer ’Set/Returns the current volume setting of the player from 0 to 100.

                    I have no idea what the hell I'm doing wrong

                    EDIT, I wrote the parms to the log just to see their values after the changes and I'm getting a proper Integer (20) for 'NewVolume' and a proper Zonename for 'ZoneName'..
                    Last edited by manxam; January 27, 2013, 07:07 PM.

                    Comment


                      #11
                      Originally posted by manxam View Post
                      Thanks Dirk but unfortunately I'm met with the same error:
                      Code:
                      SetVolume with error = Overload resolution failed because no accessible 'Volume' accepts this number of arguments.
                      when everything else fails .... put in some debug log statements. Print out variables zonename and newvolume, are they what you think they are?
                      If you read the volume in your script, does that work?
                      Dirk

                      Comment


                        #12
                        Haha, got it by reading the Homeseer SDK.. Volume is not "Volume(parm)" it's "Volume = parm"

                        Thanks for your help Dirk!

                        Comment


                          #13
                          Originally posted by manxam View Post
                          Haha, got it by reading the Homeseer SDK.. Volume is not "Volume(parm)" it's "Volume = parm"
                          oops ..... had my disclaimer it was "something like that" . Hate it when code is so strict

                          Dirk

                          Comment


                            #14
                            Yeah, you're fired...

                            Comment

                            Working...
                            X