Announcement

Collapse
No announcement yet.

Sample Creating a Device

Collapse
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #31
    Originally posted by Rick Tinker View Post
    I just mentioned those in the other thread... They are named differently and are not in a structure in .11 (and I think a release before that) but they have been there for a while. I added ColumnSpan, and when I did that I shortened the names and put all 3 inside a structure. So other than that, the code will work.

    The new feature that caused the change in those is a ColumnSpan giving you more control over the placement of the controls (buttons, sliders, drop-lists) generated from the value/status pairs.

    The render type ValuesSlider I think is in .11 as well - you might like that - especially for relatively low ranges of values (e.g. 0 to 100) it draws a slider rather than drop-downs for selecting dim levels, and in your case, volume levels!
    OK, here is my code and see below how it renders .... Note that the row/column don't seem to do anything.
    I'll do a second posting on a "status device" with a picture of how it renders

    PHP Code:
        Private Function SonosCreatePlayerDevice(ByVal HSRef As IntegerByVal ZoneName As StringZoneModel As StringNewDevice As Boolean) As Integer
            SonosCreatePlayerDevice 
    = -1
            Dim dv 
    As Scheduler.Classes.DeviceClass
            Dim DevName 
    As String ZoneName " - Player"
            
    Dim dvParent As Scheduler.Classes.DeviceClass Nothing
            
    Try
                If 
    HSRef = -1 Then
                    HSRef 
    hs.NewDeviceRef(DevName)
                    
    Log("SonosCreatePlayerDevice: Created device " DevName " with reference " HSRef.ToString " and ZoneModel = " ZoneModelLogType.LOG_TYPE_INFO)
                    
    ' Force HomeSeer to save changes to devices and events so we can find our new device
                    hs.SaveEventsDevices()
                End If
                dv = hs.GetDeviceByRef(HSRef)
                dv.Interface(hs) = tIFACE_NAME
                If NewDevice Then
                    dv.Location(hs) = "Sonos" '
    IFACE_NAME
                    dv
    .Location2(hs) = ZoneName 'IFACE_NAME & InstanceFriendlyName.ToString
                    dv.Device_Type_String(hs) = SonosHSDevices.Player.ToString
                    dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES)
                    dv.Can_Dim(hs) = False
                    dv.Image(hs) = ""
                    dv.Buttons(hs) = ""
                    dv.OLD_Values(hs) = ""
                    Dim DT As New DeviceTypeInfo
                    DT.Device_API = DeviceTypeInfo.eDeviceAPI.Media
                    DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Root
                    DT.Device_SubType_Description = "Sonos Player Master Control"
                    dv.DeviceType_Set(hs) = DT
                    dv.Status_Support(hs) = True
                    hs.SetDeviceString(HSRef, "", False)
                    ' 
    This device is a child devicethe parent being the root device for the entire security system
                    
    ' As such, this device needs to be associated with the root (Parent) device.
                    dvParent = hs.GetDeviceByRef(MasterHSDeviceRef)
                    If dvParent.AssociatedDevices_Count(hs) < 1 Then
                        ' 
    There are none addedso it is OK to add this one.
                        
    dvParent.AssociatedDevice_Add(hsHSRef)
                    Else
                        
    Dim Found As Boolean False
                        
    For Each ref As Integer In dvParent.AssociatedDevices(hs)
                            If 
    ref HSRef Then
                                Found 
    True
                                
    Exit For
                            
    End If
                        
    Next
                        
    If Not Found Then
                            dvParent
    .AssociatedDevice_Add(hsHSRef)
                        Else
                            
    ' This is an error condition likely as this device's reference ID should not already be associated.
                        
    End If
                    
    End If

                    
    ' Now, we want to make sure our child device also reflects the relationship by adding the parent to
                    '   
    the child's associations.
                    dv.AssociatedDevice_ClearAll(hs)  ' 
    There can be only one parentso make sure by wiping these out.
                    
    dv.AssociatedDevice_Add(hsdvParent.Ref(hs))
                    
    hs.DeviceVSP_ClearAll(HSRefTrue)
                
    End If

                
    hs.DeviceVSP_ClearAll(HSRefTrue)
                
    Dim ValuePairs As Integer hs.DeviceVGP_Count(HSRef)
                
    Log("Test in SonosCreatePlayerDevice counting value/graphics pairs. Count =  " ValuePairs.ToStringLogType.LOG_TYPE_INFO)
                
    hs.DeviceVGP_ClearAll(HSRefTrue)

                
    Dim Pair As VSPair
                Pair 
    = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                
    Pair.PairType VSVGPairType.SingleValue
                
    'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
                Pair.Value = 1
                Pair.Status = "Play"
                Pair.Render = VSVGPairRender.Button
                Pair.ButtonRender_Row = 0
                Pair.ButtonRender_Column = 0
                hs.DeviceVSP_AddPair(HSRef, Pair)

                Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                Pair.PairType = VSVGPairType.SingleValue
                '
    Pair.ProtectionSet ePairProtection.Do_Not_Delete
                Pair
    .Value 2
                Pair
    .Status "Stop"
                
    Pair.Render VSVGPairRender.Button
                Pair
    .ButtonRender_Row 0
                Pair
    .ButtonRender_Column 1
                hs
    .DeviceVSP_AddPair(HSRefPair)

                
    Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                
    Pair.PairType VSVGPairType.SingleValue
                
    'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
                Pair.Value = 3
                Pair.Status = "Pause"
                Pair.Render = VSVGPairRender.Button
                Pair.ButtonRender_Row = 0
                Pair.ButtonRender_Column = 2
                hs.DeviceVSP_AddPair(HSRef, Pair)

                Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                Pair.PairType = VSVGPairType.SingleValue
                '
    Pair.ProtectionSet ePairProtection.Do_Not_Delete
                Pair
    .Value 5
                Pair
    .Status "Prev"
                
    Pair.Render VSVGPairRender.Button
                Pair
    .ButtonRender_Row 0
                Pair
    .ButtonRender_Column 3
                hs
    .DeviceVSP_AddPair(HSRefPair)

                
    Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                
    Pair.PairType VSVGPairType.SingleValue
                
    'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
                Pair.Value = 4
                Pair.Status = "Next"
                Pair.Render = VSVGPairRender.Button
                Pair.ButtonRender_Row = 0
                Pair.ButtonRender_Column = 4
                hs.DeviceVSP_AddPair(HSRef, Pair)

                If ZoneModel.ToUpper = "WD100" Then
                    Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                    Pair.PairType = VSVGPairType.SingleValue
                    '
    Pair.ProtectionSet ePairProtection.Do_Not_Delete
                    Pair
    .Value 6
                    Pair
    .Status "BuildDB"
                    
    Pair.Render VSVGPairRender.Button
                    Pair
    .ButtonRender_Row 0
                    Pair
    .ButtonRender_Column 5
                    hs
    .DeviceVSP_AddPair(HSRefPair)
                
    End If

                
    Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                
    Pair.PairType VSVGPairType.SingleValue
                
    'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
                Pair.Value = 7
                Pair.Status = "Shuffle"
                Pair.Render = VSVGPairRender.Button
                Pair.ButtonRender_Row = 1
                Pair.ButtonRender_Column = 0
                hs.DeviceVSP_AddPair(HSRef, Pair)

                Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                Pair.PairType = VSVGPairType.SingleValue
                '
    Pair.ProtectionSet ePairProtection.Do_Not_Delete
                Pair
    .Value 8
                Pair
    .Status "Repeat"
                
    Pair.Render VSVGPairRender.Button
                Pair
    .ButtonRender_Row 1
                Pair
    .ButtonRender_Column 1
                hs
    .DeviceVSP_AddPair(HSRefPair)

                
    Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                
    Pair.PairType VSVGPairType.SingleValue
                
    'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
                Pair.Value = 9
                Pair.Status = "Up"
                Pair.Render = VSVGPairRender.Button
                Pair.ButtonRender_Row = 2
                Pair.ButtonRender_Column = 0
                hs.DeviceVSP_AddPair(HSRef, Pair)

                Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                Pair.PairType = VSVGPairType.SingleValue
                '
    Pair.ProtectionSet ePairProtection.Do_Not_Delete
                Pair
    .Value 10
                Pair
    .Status "Dn"
                
    Pair.Render VSVGPairRender.Button
                Pair
    .ButtonRender_Row 2
                Pair
    .ButtonRender_Column 1
                hs
    .DeviceVSP_AddPair(HSRefPair)

                
    Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                
    Pair.PairType VSVGPairType.SingleValue
                
    'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
                Pair.Value = 11
                Pair.Status = "Mute"
                Pair.Render = VSVGPairRender.Button
                Pair.ButtonRender_Row = 2
                Pair.ButtonRender_Column = 2
                hs.DeviceVSP_AddPair(HSRef, Pair)

                Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                Pair.PairType = VSVGPairType.SingleValue
                '
    Pair.ProtectionSet ePairProtection.Do_Not_Delete
                Pair
    .Value 12
                Pair
    .Status "Left"
                
    Pair.Render VSVGPairRender.Button
                Pair
    .ButtonRender_Row 2
                Pair
    .ButtonRender_Column 3
                hs
    .DeviceVSP_AddPair(HSRefPair)

                
    Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                
    Pair.PairType VSVGPairType.SingleValue
                
    'Pair.ProtectionSet = ePairProtection.Do_Not_Delete
                Pair.Value = 13
                Pair.Status = "Right"
                Pair.Render = VSVGPairRender.Button
                Pair.ButtonRender_Row = 2
                Pair.ButtonRender_Column = 4
                hs.DeviceVSP_AddPair(HSRef, Pair)

                Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Control)
                Pair.PairType = VSVGPairType.SingleValue
                '
    Pair.ProtectionSet ePairProtection.Do_Not_Delete
                Pair
    .Value 14
                Pair
    .Status "Loudness"
                
    Pair.Render VSVGPairRender.Button
                Pair
    .ButtonRender_Row 2
                Pair
    .ButtonRender_Column 5
                hs
    .DeviceVSP_AddPair(HSRefPair)

                Return 
    HSRef
            
    Catch ex As Exception
                Log
    ("Error in SonosCreatePlayerDevice with Error =  " ex.MessageLogType.LOG_TYPE_ERROR)
            
    End Try
        
    End Function 
    Attached Files

    Comment


      #32
      Originally posted by Rick Tinker View Post
      I just mentioned those in the other thread... They are named differently and are not in a structure in .11 (and I think a release before that) but they have been there for a while. I added ColumnSpan, and when I did that I shortened the names and put all 3 inside a structure. So other than that, the code will work.

      The new feature that caused the change in those is a ColumnSpan giving you more control over the placement of the controls (buttons, sliders, drop-lists) generated from the value/status pairs.

      The render type ValuesSlider I think is in .11 as well - you might like that - especially for relatively low ranges of values (e.g. 0 to 100) it draws a slider rather than drop-downs for selecting dim levels, and in your case, volume levels!
      This is the second post. This is the code to create status devices and the attached picture shows the icons that I don't want

      PHP Code:
          Private Function CreateHSDevice(ByVal DeviceType As DeviceInfoIndexDevString As String) As Integer
              CreateHSDevice 
      = -1
              Dim dv 
      As Scheduler.Classes.DeviceClass
              Dim DevName 
      As String ZoneName " - " DevString
              Dim dvParent 
      As Scheduler.Classes.DeviceClass Nothing
              Dim HSRef 
      As Integer = -1
              
      Try
                  
      HSRef hs.NewDeviceRef(DevName)
                  If 
      g_bDebug Then Log("CreateHSDevice for Zone = " ZoneName " created deviceType " DeviceType.ToString " with Ref " HSRef.ToStringLogType.LOG_TYPE_INFO)
                  
      ' Force HomeSeer to save changes to devices and events so we can find our new device
                  hs.SaveEventsDevices()
                  dv = hs.GetDeviceByRef(HSRef)
                  dv.Interface(hs) = tIFACE_NAME

                  dv.Location(hs) = "Sonos" '
      IFACE_NAME
                  dv
      .Location2(hs) = ZoneName 'IFACE_NAME & InstanceFriendlyName.ToString
                  dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
                  dv.Can_Dim(hs) = False
                  dv.Image(hs) = ""
                  dv.Buttons(hs) = ""
                  dv.OLD_Values(hs) = ""
                  Dim DT As New DeviceTypeInfo
                  DT.Device_API = DeviceTypeInfo.eDeviceAPI.Media
                  Select Case DeviceType
                      Case DeviceInfoIndex.diTrackHSRef
                          dv.Device_Type_String(hs) = "Track"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Media_Track
                          DT.Device_SubType_Description = "Sonos Player Track Name"
                      Case DeviceInfoIndex.diNextTrackHSRef
                          dv.Device_Type_String(hs) = "Next Track"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Player_Status_Additional
                          DT.Device_SubType_Description = "Sonos Player Next Track Name"
                      Case DeviceInfoIndex.diArtistHSRef
                          dv.Device_Type_String(hs) = "Artist"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Media_Artist
                          DT.Device_SubType_Description = "Sonos Player Artist Name"
                      Case DeviceInfoIndex.diNextArtistHSRef
                          dv.Device_Type_String(hs) = "Next Artist"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Player_Status_Additional
                          DT.Device_SubType_Description = "Sonos Player Next Artist Name"
                      Case DeviceInfoIndex.diAlbumHSRef
                          dv.Device_Type_String(hs) = "Album"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Media_Album
                          DT.Device_SubType_Description = "Sonos Player Album Name"
                      Case DeviceInfoIndex.diNextAlbumHSRef
                          dv.Device_Type_String(hs) = "Next Album"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Player_Status_Additional
                          DT.Device_SubType_Description = "Sonos Player Next Album Name"
                      Case DeviceInfoIndex.diArtHSRef
                          dv.Device_Type_String(hs) = "Art"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Player_Status_Additional
                          DT.Device_SubType_Description = "Sonos Player AlbumArt URL"
                      Case DeviceInfoIndex.diNextArtHSRef
                          dv.Device_Type_String(hs) = "Next Art"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Player_Status_Additional
                          DT.Device_SubType_Description = "Sonos Player AlbumArt URL"
                      Case DeviceInfoIndex.diPlayStateHSRef
                          dv.Device_Type_String(hs) = "State"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Player_Status
                          DT.Device_SubType_Description = "Sonos Player State"
                      Case DeviceInfoIndex.diVolumeHSRef
                          dv.Device_Type_String(hs) = "Volume"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Player_Volume
                          DT.Device_SubType_Description = "Sonos Player Volume"
                      Case DeviceInfoIndex.diMuteHSRef
                          dv.Device_Type_String(hs) = "Mute"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Player_Status_Additional
                          DT.Device_SubType_Description = "Sonos Player Mute State"
                      Case DeviceInfoIndex.diLoudnessHSRef
                          dv.Device_Type_String(hs) = "Loudness"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Player_Status_Additional
                          DT.Device_SubType_Description = "Sonos Player Loudness State"
                      Case DeviceInfoIndex.diBalanceHSRef
                          dv.Device_Type_String(hs) = "Balance"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Player_Status_Additional
                          DT.Device_SubType_Description = "Sonos Player Balance State"
                      Case DeviceInfoIndex.diTrackLengthHSRef
                          dv.Device_Type_String(hs) = "Track Length"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Player_Status_Additional
                          DT.Device_SubType_Description = "Sonos Player Track Length"
                      Case DeviceInfoIndex.diTrackPosHSRef
                          dv.Device_Type_String(hs) = "Track Position"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Player_Status_Additional
                          DT.Device_SubType_Description = "Sonos Player Track Position"
                      Case DeviceInfoIndex.diRadiostationNameHSRef
                          dv.Device_Type_String(hs) = "Radiostation Name"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Player_Status_Additional
                          DT.Device_SubType_Description = "Sonos Player Radiostation Name"
                      Case DeviceInfoIndex.diTrackDescrHSRef
                          dv.Device_Type_String(hs) = "Track Descr"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Player_Status_Additional
                          DT.Device_SubType_Description = "Sonos Player Track Descriptor"
                      Case DeviceInfoIndex.diRepeatHSRef
                          dv.Device_Type_String(hs) = "Repeat"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Player_Repeat
                          DT.Device_SubType_Description = "Sonos Player Repeat State"
                      Case DeviceInfoIndex.diShuffleHSRef
                          dv.Device_Type_String(hs) = "Shuffle"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Player_Shuffle
                          DT.Device_SubType_Description = "Sonos Player Shuffle State"
                      Case DeviceInfoIndex.diGenreHSRef
                          dv.Device_Type_String(hs) = "Genre"
                          DT.Device_Type = DeviceTypeInfo.eDeviceType_Media.Media_Genre
                          DT.Device_SubType_Description = "Sonos Player Track Genre"
                  End Select

                  dv.DeviceType_Set(hs) = DT
                  dv.Status_Support(hs) = True
                  hs.SetDeviceString(HSRef, "", False)
                  ' 
      This device is a child devicethe parent being the root device for the entire security system
                  
      ' As such, this device needs to be associated with the root (Parent) device.
                  dvParent = hs.GetDeviceByRef(HSRefPlayer)
                  If dvParent.AssociatedDevices_Count(hs) < 1 Then
                      ' 
      There are none addedso it is OK to add this one.
                      
      dvParent.AssociatedDevice_Add(hsHSRef)
                  Else
                      
      Dim Found As Boolean False
                      
      For Each ref As Integer In dvParent.AssociatedDevices(hs)
                          If 
      ref HSRef Then
                              Found 
      True
                              
      Exit For
                          
      End If
                      
      Next
                      
      If Not Found Then
                          dvParent
      .AssociatedDevice_Add(hsHSRef)
                      Else
                          
      ' This is an error condition likely as this device's reference ID should not already be associated.
                      
      End If
                  
      End If

                  
      ' Now, we want to make sure our child device also reflects the relationship by adding the parent to
                  '   
      the child's associations.
                  dv.AssociatedDevice_ClearAll(hs)  ' 
      There can be only one parentso make sure by wiping these out.
                  
      dv.AssociatedDevice_Add(hsdvParent.Ref(hs))
                  
      hs.DeviceVSP_ClearAll(HSRefTrue)
                  
      WriteStringIniFile("UPnP HSRef to UDN"HSRefUDN)
                  Return 
      HSRef
              
      Catch ex As Exception
                  Log
      ("Error in CreateHSDevice with Error =  " ex.MessageLogType.LOG_TYPE_ERROR)
              
      End Try
          
      End Function 
      Attached Files

      Comment


        #33
        what's the trick for getting an On, Off and value list on the same device; similar to the current hs2 setup

        I can get either the on & off btn or the value list, but not both

        do i need to order the rendering or give them positions?
        Mark

        HS3 Pro 3.0.0.534
        Hardware: Insteon Serial PLM | AD2USB for Vista Alarm | HAI Omnistat2 | 1-Wire HA7E | RFXrec433 | Dahua Cameras | LiftMaster Internet Gateway
        Plugins: Insteon (mine) | Vista Alarm (mine) | Omnistat 3 (by Kirby) | Ultra1Wire3 | RFXCOM | NetCAM | MyQ | BLRadar | BLDenon | Jon00 Charting
        Platform: HP h8-1360t, Windows Server 2012 R2, i7-3.4GHz, 16GB memory

        Comment


          #34
          Is there another way to render the button?
          I've tried this(VB Code):

          Pair.Render = VSVGPairRender.Button

          But it says that VSVGPairRender is not defined.

          Since it was used back at 2013 and updates during the last 5 years, is there any other way to render a button?
          This may sound dumb but I am new to Homeseer by the way.

          Comment


            #35
            You have to add a reference to the HomeSeer objects (Scheduler, DLL, etc.) and then the Enums will have this. See the sample project (which I assume they still publish) and it should have it in the example.
            Regards,

            Rick Tinker (a.k.a. "Tink")

            Comment


              #36
              I've seen the sample. just I need to know what reference to add.
              Since I have included references: HomeSeerAPI, Scheduler, RssToolkit, HSCF, and HomeSeerUtil.

              Is there any other reference must add?

              Also I made a VSVGPairRender variable which is:

              Dim VSVGPairRender As Enums.CAPIControlType

              Still doesn't work.
              Sorry for bugging you just there is an assignment I need to get done.
              Last edited by alexz99; October 22, 2018, 06:33 PM.

              Comment


                #37
                Alex could you provide the full function that is failing and the actual error message you are seeing?

                Comment


                  #38
                  I'm writing a Venstar thermostat plugin and have all the API worked out, but am still struggling to create the devices in HS3. So far, I've used the examples to create the parent and child devices, have the value status and value graphic pairs all loading properly, but still have some problems.

                  I've found this thread and some other great examples, but my head is now a sufficient pulp from beating it on a wall that I feel I have to ask the experts that came before me.

                  How do I get something like the Heat Set Point to actually show the pull-down with the temps?

                  Here's what I have (C#). What am I missing to make the heating set point a control and show it as a pull-down?

                  Code:
                  devref = GlobalVar.hs.NewDeviceRef("Heat Set Point");
                  if (devref > 0)
                  {
                  string[] disp = new string[2]; myDevice = devref; dv = (DeviceClass)GlobalVar.hs.GetDeviceByRef(devref); dv.set_Address(GlobalVar.hs, "Venstar"); dv.set_Device_Type_String(GlobalVar.hs, "Heat Setpoint"); dv.set_Location(GlobalVar.hs, "Venstar"); DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo(); dt.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Thermostat; dt.Device_SubType = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceSubType_Setpoint .Heating_1; dv.set_DeviceType_Set(GlobalVar.hs, dt); dv.set_Interface(GlobalVar.hs, GlobalVar.IFACE_NAME); dv.set_InterfaceInstance(GlobalVar.hs, ""); dv.set_Status_Support(GlobalVar.hs, true); dv.MISC_Clear(GlobalVar.hs, Enums.dvMISC.STATUS_ONLY); dv.set_Relationship(GlobalVar.hs, HomeSeerAPI.Enums.eRelationship.Child); dv.AssociatedDevice_Add(GlobalVar.hs, parent); //setup value-status pairs GlobalVar.hs.DeviceVSP_ClearAll(devref, true); VSVGPairs.VSPair statusPair = new VSVGPairs.VSPair(ePairStatusControl.Both); statusPair.PairType = VSVGPairs.VSVGPairType.Range; statusPair.RangeStart = 00; statusPair.RangeEnd = 119; statusPair.RangeStatusPrefix = ""; statusPair.RangeStatusSuffix = "°F"; statusPair.HasScale = true; statusPair.Render_Location.Row = 0; statusPair.Render_Location.Column = 0; statusPair.Render = Enums.CAPIControlType.ValuesRange; statusPair.IncludeValues = true; statusPair.ControlUse = ePairControlUse._HeatSetPoint; GlobalVar.hs.DeviceVSP_AddPair(devref, statusPair); //setup value-graphics pairs GlobalVar.hs.DeviceVGP_ClearAll(devref, true); VSVGPairs.VGPair graphicsPair = new VSVGPairs.VGPair(); graphicsPair.PairType = VSVGPairs.VSVGPairType.Range; //we want temp ranges from 0-110 in groups of 10 int rangestart = 0; int rangestep = 10; for (int i = 0; i <= 11; i++) {
                  int rangelow = rangestart + rangestep* i; int rangehigh = rangestart + rangestep * (i + 1) - 1; graphicsPair.RangeStart = rangelow; graphicsPair.RangeEnd = rangehigh; graphicsPair.Graphic = @"images\HomeSeer\status\Thermometer-" + rangelow.ToString("00") + ".png"; GlobalVar.hs.DeviceVGP_AddPair(devref, graphicsPair);
                  } children.Add(devref);
                  }

                  If anyone can help, feel free to respond with VB example or lines, and I'll figure it out. Thanks!

                  Comment


                    #39
                    Question #2: I have the thermostat mode controls created using C# with the buttons Off, Heat, Cool, Auto displayed properly and the values 0-3, respectively. When I click the buttons they don't do anything.

                    By contrast, if I create a device manually on the device screen and add Value/Status pairs, the buttons will actually change the mode.

                    When creating devices with buttons via programming, is it necessary to write some kind of scripting to make the buttons actually function and change the mode, or is it something I may have forgotten to do when defining the control?

                    Here's my code for that device through the creation of the first "Off" button.

                    Code:
                    dv = (DeviceClass)GlobalVar.hs.GetDeviceByRef(devref);
                    dv.set_Address(GlobalVar.hs, "Venstar");
                    dv.set_Device_Type_String(GlobalVar.hs, "Mode");
                    //this is creating a new room for the device. Some users may not like it, but it can be changed.
                    dv.set_Location(GlobalVar.hs, "Venstar");
                    //set up the device type for later addition to the device
                    DeviceTypeInfo_m.DeviceTypeInfo dt = new DeviceTypeInfo_m.DeviceTypeInfo();
                    dt.Device_Type = (int)DeviceTypeInfo_m.DeviceTypeInfo.eDeviceAPI.Plug_In;
                    //no subtype
                    //dt.Device_SubType = (int)DeviceTypeInfo_m.DeviceTypeInfo.
                    dv.set_DeviceType_Set(GlobalVar.hs, dt);
                    
                    dv.set_InterfaceInstance(GlobalVar.hs, "");
                    //Show values, clear status only (both control & status), support triggers
                    dv.MISC_Set(GlobalVar.hs, Enums.dvMISC.SHOW_VALUES);
                    dv.MISC_Clear(GlobalVar.hs, Enums.dvMISC.STATUS_ONLY);
                    dv.MISC_Clear(GlobalVar.hs, Enums.dvMISC.NO_STATUS_TRIGGER);
                    dv.set_Status_Support(GlobalVar.hs, true);
                    //start in auto mode
                    GlobalVar.hs.SetDeviceValueByRef(devref, 3, true);
                    GlobalVar.hs.SetDeviceString(devref, "Auto", false);
                    
                    //make associations with parent
                    dv.AssociatedDevice_ClearAll(GlobalVar.hs);
                    dv.set_Relationship(GlobalVar.hs, HomeSeerAPI.Enums.eRelationship.Child);
                    dv.AssociatedDevice_Add(GlobalVar.hs, parent);
                    
                    
                    VSVGPairs.VSPair statusPair = new VSVGPairs.VSPair(ePairStatusControl.Both);
                    
                    GlobalVar.hs.DeviceVSP_ClearAll(devref, true);
                    statusPair.PairType = VSVGPairs.VSVGPairType.SingleValue;
                    statusPair.Value = 0;
                    statusPair.Status = "Off";
                    statusPair.Render_Location.Row = 0;
                    statusPair.Render_Location.Column = 0;
                    statusPair.StringListAdd = "Off";
                    statusPair.IncludeValues = true;
                    statusPair.ControlUse = ePairControlUse._ThermModeOff;
                    statusPair.Render = Enums.CAPIControlType.Button_Script; //this is what leads me to believe there may be a script necessary to make the button function
                    GlobalVar.hs.DeviceVSP_AddPair(devref, statusPair);
                    
                    GlobalVar.hs.DeviceVGP_ClearAll(devref, true);
                    VSVGPairs.VGPair graphicsPair = new VSVGPairs.VGPair();
                    graphicsPair.PairType = VSVGPairs.VSVGPairType.SingleValue;
                    graphicsPair.Set_Value = 0;
                    graphicsPair.Graphic = @"images\HomeSeer\status\off.gif";
                    GlobalVar.hs.DeviceVGP_AddPair(devref, graphicsPair);
                    If anyone can help, feel free to respond with VB example or lines, and I'll figure it out. Thanks!

                    Comment


                      #40
                      Originally posted by dzee View Post
                      When I click the buttons they don't do anything.
                      if I create a device manually on the device screen and add Value/Status pairs, the buttons will actually change the mode
                      It's described in SDK documentation, there two different ways to control the state, I was also struggling with this.
                      I created the base library for HS3 plugin: https://forums.homeseer.com/forum/de...plugin-library

                      The difference between two modes is that when you control your plugin device (i.e. click the button) - HS doesn't update the state straight away - instead it tells your plugin (via SetIOMulti) about the intent. Then your plugin should perform the action (i.e. control thermostat) - and if succeeded tell HS to update the device state (via SetDeviceValueByRef).
                      Kind of makes sense.

                      You can check my library DeviceBase.ValueChanged() - there are some comments explaining.

                      Comment

                      Working...
                      X