Announcement

Collapse
No announcement yet.

PI Script?

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

    PI Script?

    Can anyone tell me how to get an instance of the PI for scripting?

    It use to be something like:

    Dim Sonos As Object = hs.plugin("SONOSCONTROLLER")

    But that is throwing an error "plugin not found". Any help would be appreciated.
    I am using v3.1.0.18

    Thanks,
    -Skybolt

    #2
    This is what works for me:

    hs.PluginFunction("Sonos", RoomUDN, "PlayMusic", {"", "", Station,"","","","","","","",false,0})

    Comment


      #3
      Where did you find the function list or scripting functions etc?

      The help file doesn't mention anything on scripting.
      Thanks,

      EDIT: My bad. I see HS3 has new functions for plugins. Is there a function list or property list for this plugin?
      -Skybolt

      Comment


        #4
        Its not documented. I searched through all of the Sonos forum and found the function. There are several posts on using it.

        I also use this for changing the linkgroup:

        hs.pluginfunction("Sonos", "", "SetLinkgroupZoneDestination", {linkgroupname, linkstring})

        Some things can be controlled using CapiControl and not the plugin function, like player mute, volume.

        Comment


          #5
          Wow, that sucks that there is no information on this. Thanks for your reply's.
          -Skybolt

          Comment


            #6
            what are you trying to do? maybe I can help. I have several scripts working with Sonos plugin.

            Comment


              #7
              Thank you. It's so simple it's stupid.

              I am trying to check the volume level of a player and if it is lower then 30 set to 30.

              I had many scripts for Sonos, but since I switched to HS3 they don't work any more. I just need to figure out how to talk to the PI again. So far, not joy.

              Thanks,
              -Skybolt

              Comment


                #8
                That can be done using capi control and avoiding plugin interface. I will post the code after I get off work tonight.

                Comment


                  #9
                  We use the Sonos app and Alexa to operate the Sonos system. but we also have wall controllers to turn on speakers and select music stations and set the volume. But my wife's way of shutting off Sonos is turning the volume off, regardless of what room she is in. Short of getting divorced this is not going to change. So I need to set the volume when I am not using the app. Alexa doesn't return the volume level yet so I can't use that to check when nothing is working ...
                  -Skybolt

                  Comment


                    #10
                    Originally posted by prsmith777 View Post
                    That can be done using capi control and avoiding plugin interface. I will post the code after I get off work tonight.
                    I tried CAPI, it returned the wrong volume level. But maybe I was using it wrong. Thank you.
                    -Skybolt

                    Comment


                      #11
                      Try this:

                      Code:
                      Dim room_name as string
                      Dim vol_high as integer
                      Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(hs.GetDeviceRefByName("Sonos " & room_name & " Volume"), True, "Volume (value)%", False, False)
                      
                      cc.ControlValue = vol_high
                      
                      Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)

                      Comment


                        #12
                        Originally posted by prsmith777 View Post
                        Try this:

                        Code:
                        Dim room_name as string
                        Dim vol_high as integer
                        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(hs.GetDeviceRefByName("Sonos " & room_name & " Volume"), True, "Volume (value)%", False, False)
                        
                        cc.ControlValue = vol_high
                        
                        Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
                        First of all, Thank you for taking the time and posting this.

                        Couple of questions:

                        What is this parameter supposed to be?
                        "Volume (value)%"

                        Also what does this do?
                        Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)

                        I couldn't get any of this to work though. Kept getting Object not set errors.

                        This is what I ran:
                        Code:
                        Dim room_name as string = "Office"
                        Dim vol_high as integer
                        
                        Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(hs.GetDeviceRefByName("Sonos " & room_name & " Volume"), True, "Volume (value)%", False, False)
                        
                        hs.writelog("Sonos Script",cc.ControlValue.ToString)

                        Thanks again
                        -Skybolt

                        Comment


                          #13
                          sorry "value" is the variable to insert there, not vol_high. I lifted it from my script and didnt edit it correctly.

                          you need to add the room name in there for which room you want to control.

                          the other line is for the return value, which may or may not be needed and doesnt really do anything otherwise.

                          so to change the volume in a room office to volume 50 you would do this:

                          Code:
                          Dim room_name as string = "Office"
                          Dim value as integer = 50
                          Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(hs.GetDeviceRefByName("Sonos " & room_name & " Volume"), True, "Volume (value)%", False, False)
                          
                          cc.ControlValue = value
                          
                          Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)

                          Comment


                            #14
                            Thank you again for posting this code.

                            Again, the CC object is not getting initialized. Still getting Object not set errors. Sorry.

                            I used your post exactly.
                            -Skybolt

                            Comment


                              #15
                              Are you adding the sub lines in there? This works for me.

                              Code:
                              Public Sub Main(ByVal parms As String)
                              Dim room_name as string = "Office"
                              Dim value as integer = 50
                              Dim cc As HomeSeerAPI.CAPI.CAPIControl = hs.CAPIGetSingleControl(hs.GetDeviceRefByName("Sonos " & room_name & " Volume"), True, "Volume (value)%", False, False)
                              
                              cc.ControlValue = value
                              
                              Dim cr As HomeSeerAPI.CAPI.CAPIControlResponse = hs.CAPIControlHandler(cc)
                              End Sub

                              Comment

                              Working...
                              X