Announcement

Collapse
No announcement yet.

Creating Devices

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

  • mhinke
    replied
    Thanks

    That did the trick, its getting more clear now.

    Leave a comment:


  • CFGuy
    replied
    if you already have the devices created, this code will create the parent child relationships.

    Run this in a vb.net script.

    PHP Code:
      
     Dim DV 
    As Classes.DeviceClass
     Dim parentDV 
    As Classes.DeviceClass
     
    ' Replace all the following nnn with the actual RefIDs
     Dim parentID As Int16 = nnn
     Dim childID1 As Int16 = nnn
     Dim childID2 As Int16 = nnn
     Dim childID3 As Int16 = nnn
     Dim childID4 As Int16 = nnn
      
     parentDV = hs.GetDeviceByRef(parentID)
     parentDV.Relationship(hs) = 2
     ' 
    The following 4 lines is just for an example of removing a child
     
    ' parentDV.AssociatedDevice_Remove(hs, childID1)
     ' 
    parentDV.AssociatedDevice_Remove(hschildID2)
     
    ' parentDV.AssociatedDevice_Remove(hs, childID3)
     ' 
    parentDV.AssociatedDevice_Remove(hschildID4)
      
     
    parentDV.AssociatedDevice_Add(hschildID1)
     
    parentDV.AssociatedDevice_Add(hschildID2)
     
    parentDV.AssociatedDevice_Add(hschildID3)
     
    parentDV.AssociatedDevice_Add(hschildID4)

     
    DV hs.GetDeviceByRef(childID1)
     
    DV.AssociatedDevice_Add(hsparentID)
     
    DV.Relationship(hs) = 4
      
     DV 
    hs.GetDeviceByRef(childID2)
     
    dv.AssociatedDevice_Add(hsparentID)
     
    DV.Relationship(hs) = 4
      
     DV 
    hs.GetDeviceByRef(childID3)
     
    dv.AssociatedDevice_Add(hsparentID)
     
    DV.Relationship(hs) = 4
      
     DV 
    hs.GetDeviceByRef(childID4)
     
    dv.AssociatedDevice_Add(hsparentID)
     
    DV.Relationship(hs) = 

    Leave a comment:


  • mhinke
    replied
    Child devices

    does anyone have a example of how to make an root device with one ore more child devices?

    I dont understand the homeseer help, it is to abstract for a beginner.

    Thanks in advance!

    Leave a comment:


  • donstephens
    replied
    Thanks. That's a great help.

    Sent from my XT1080 using Tapatalk

    Leave a comment:


  • rmasonjr
    replied
    Here's some code I use in one of my plugins. I removed some of the sensitive data, but it should be a good starting point:

    Code:
    Private Function CreateParentDevice() As Integer
            Dim ref As Integer
            Dim PData As clsPlugExtraData = Nothing
            Dim dv As Scheduler.Classes.DeviceClass
            Dim disp(1) As String
            Dim DT As New DeviceTypeInfo
            Dim ifl As String = "images/myimages"
    
            Try
                ref = hs.NewDeviceRef("Root Device")
                If (ref < 0) Then Return ref
                hs.SaveEventsDevices()
                dv = hs.GetDeviceByRef(ref)
                dv.Code(hs) = hs.GetNextVirtualCode
    
                ''store the plugin name in PED
                PData = New clsPlugExtraData
                PData.AddNamed("plugin", IFACE_NAME)
                dv.PlugExtraData_Set(hs) = PData
    
                ''create the rest of the parent device
                disp(0) = IFACE_NAME
                disp(1) = "version 1.0"
                dv.AdditionalDisplayData(hs) = disp
                dv.Address(hs) = ADDRESS
                dv.Device_Type_String(hs) = IFACE_NAME
                DT.Device_Type = DeviceTypeInfo.eDeviceAPI.Plug_In
                DT.Device_SubType_Description = "Root Device"
                dv.DeviceType_Set(hs) = DT
                dv.Interface(hs) = IFACE_NAME
                dv.InterfaceInstance(hs) = ""
                dv.Last_Change(hs) = Now()
                dv.Location(hs) = IFACE_NAME
                dv.Location2(hs) = IFACE_NAME
                dv.Image(hs) = ifl & "someimage.jpg"
                dv.ImageLarge(hs) = ifl & "someimage.jpg"
                dv.MISC_Set(hs, Enums.dvMISC.NO_LOG)
                dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES)
                dv.UserNote(hs) = "This device was built by the " & IFACE_NAME
                hs.SetDeviceString(ref, "Not Set", False)  ' this will override the name/value pairs
    
                Dim vgp As VGPair
                vgp = New VGPair
                vgp.PairType = VSVGPairType.SingleValue
                vgp.Set_Value = 0
                vgp.Graphic = ifl & "someimage.png"
                hs.DeviceVGP_AddPair(ref, vgp)
    
            Catch ex As Exception
                Throw New Exception("CreateParentDevice: " & ex.Message)
            End Try
            hs.SaveEventsDevices()
            hs.writeLog("Success!","Device " & ref & " was successfully created!")
            Return ref
        End Function
    note: IFACE_NAME is a global constant string that has the plugin name like "MYPLUGIN", etc.

    Leave a comment:


  • donstephens
    started a topic Creating Devices

    Creating Devices

    Got as far as the NewRef function. Now that I have a reference number for my device, how do I create the device and assign the various stuff to it?
Working...
X