Announcement

Collapse
No announcement yet.

Creating Devices

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

    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?
    Don

    #2
    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.
    HS4Pro Running on a Raspberry Pi4
    68 Z-Wave Nodes, 175 Events, 359 Devices
    UPB modules via OMNI plugin/panel
    Plugins: Z-Wave, OMNI, HSTouch, weatherXML, EasyTrigger
    HSTouch Clients: 3 Android, 1 Joggler

    Comment


      #3
      Thanks. That's a great help.

      Sent from my XT1080 using Tapatalk
      Don

      Comment


        #4
        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!

        Comment


          #5
          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) = 
          --
          Jeff Farmer
          HS 3, HSPhone
          My HS3 Plugins: CFHSExtras, Random, Restart, Tracker, WeatherXML, PanaBluRay
          Other Plugins In Use: APCUPSD, BLOnkyo, Device History, EasyTrigger, HSTouch Server, PHLocation2, Pushover, RFXCom, UltraGCIR3, UltraMon3, UltraPioneerAVR3, X10, Z-Wave

          Hardware: GoControl Irrigation Controler, Schlage Lever Lock, Schlage Deadbolt, Way2Call Hi-Phone, RFXCom RFXrec433 Receiver, WGL 800, TI-103, Z-Net, Pioneer 1120, Pioneer 1021, Pioneer LX302, Panasonic BDT-110, Panasonic BDT-210 x2

          Comment


            #6
            Thanks

            That did the trick, its getting more clear now.

            Comment

            Working...
            X