Announcement

Collapse
No announcement yet.

create device vbscript

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

  • create device vbscript

    hello, fist time for me here, i'm a french user of homeseer, not familiar with expert boards or developpementso i wish you could help me for something that you will probably find very easy.
    When i start this vb script i've found in other thread :

    <code>
    Sub Main(params As Object)
    Dim dv As Scheduler.Classes.DeviceClass = Nothing
    dv = hs.NewDeviceRef("Toon Test apparaat")
    If dv IsNot Nothing Then
    dv.Device_Type_String(hs) = "Joe Bazooka Bubble Gum"
    hs.WriteLog("apparaat referentie", dv.ref(hs))
    End If
    End Sub
    </code>

    i have this error :

    Error 1

  • #2
    Hi, Oenic

    My script to create devices for ECODEVICE
    Sub Create_Devices(ByVal Cpt As Object)
    'Dim CurrRef As Integer = 0
    Dim BaseRef As Integer = 0
    Dim dv As Scheduler.Classes.DeviceClass = Nothing
    Dim root_dv As Scheduler.Classes.DeviceClass = Nothing
    Dim z As Integer
    Dim DAddS As String = Cpt
    If Cpt = "Cpt_1 Tempo" Then
    Try
    If Debug <> 0 Then
    Log("Les devices n'existent pas - Cr&eacute;ation " & Cpt)
    End If


    z = 3 'Cpt = CPt_1 Tempo

    For i As Byte = 0 To z 'Creation de 4 devices Si Cpt_1 Tempo
    Select Case i
    Case 0
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(DAddS & " Root Device"))
    dv.Address(hs) = DAddS & "-Root"
    BaseRef = dv.Ref(hs)

    Dim DT As New DeviceTypeInfo
    DT.Device_API = DeviceTypeInfo.eDeviceAPI.NO_API
    DT.Device_Type = DeviceTypeInfo.eDeviceType_GenericRoot
    DT.Device_SubType_Description = ""
    DT.Device_SubType = 0
    dv.DeviceType_Set(hs) = DT
    dv.Device_Type_String(hs) = DAddS & "_Device"
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
    Case 1
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(" Couleur Jour"))
    dv.Address(hs) = DAddS & "-PTEC"
    dv.MISC_Set(hs, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE)
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
    Case 2
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(" Periode"))
    dv.Address(hs) = DAddS & "-PTEP"
    dv.MISC_Set(hs, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE)
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
    Case 3
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(" DEMAIN"))
    dv.Address(hs) = DAddS & "-DEMAIN"
    dv.MISC_Set(hs, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE)
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)


    End Select

    dv.Location2(hs) = "Ecodevice"
    dv.location(hs) = DAddS

    hs.DeviceVGP_ClearAll(dv.Ref(hs), True)
    If Debug <> 0 Then
    Log("Device Ref " & Cpt & " " & dv.ref(hs))
    End If



    If i = 0 Then 'set up the relationships between the devices
    root_dv = dv
    dv.Relationship(hs) = Enums.eRelationship.Parent_Root
    Else
    If root_dv IsNot Nothing Then root_dv.AssociatedDevice_Add(hs, dv.Ref(hs))
    dv.Relationship(hs) = Enums.eRelationship.Child
    dv.AssociatedDevice_Add(hs, BaseRef)
    End If

    Select Case i

    Case 0
    hs.SetDeviceString(dv.Ref(hs), "No Status", True)
    dv.ImageLarge(hs) = "images\Ecodevice\ecodevices.png"
    dv.Image(hs) = "images\Ecodevice\ecodevices.png"

    Case 1
    dv.ImageLarge(hs) = "images\Ecodevice\ecodevices.png"
    dv.Image(hs) = "images\Ecodevice\ecodevices.png"
    hs.SetDeviceString(dv.Ref(hs), "", True)
    hs.SetDeviceValue(dv.Ref(hs), "0")
    Dim SPair As VSPair
    Dim GPair As VGPair

    SPair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
    SPair.PairType = VSVGPairType.SingleValue
    SPair.Value = 1
    SPair.Status = "Jour BLEU"
    hs.DeviceVSP_AddPair(dv.Ref(hs), SPair)

    GPair = New VGPair
    GPair.PairType = VSVGPairType.SingleValue
    GPair.Set_Value = 1
    GPair.Graphic = "/images/Ecodevice/boule_Bleue.png"
    hs.DeviceVGP_AddPair(dv.Ref(hs), GPair)

    SPair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
    SPair.PairType = VSVGPairType.SingleValue
    SPair.Value = 2
    SPair.Status = "Jour BLANC"
    hs.DeviceVSP_AddPair(dv.Ref(hs), SPair)

    GPair = New VGPair
    GPair.PairType = VSVGPairType.SingleValue
    GPair.Set_Value = 2
    GPair.Graphic = "/images/Ecodevice/boule_Blanche.png"
    hs.DeviceVGP_AddPair(dv.Ref(hs), GPair)

    SPair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
    SPair.PairType = VSVGPairType.SingleValue
    SPair.Value = 3
    SPair.Status = "Jour ROUGE"
    hs.DeviceVSP_AddPair(dv.Ref(hs), SPair)

    GPair = New VGPair
    GPair.PairType = VSVGPairType.SingleValue
    GPair.Set_Value = 3
    GPair.Graphic = "/images/Ecodevice/boule_Rouge.png"
    hs.DeviceVGP_AddPair(dv.Ref(hs), GPair)

    Case 2
    dv.ImageLarge(hs) = "images\Ecodevice\ecodevices.png"
    dv.Image(hs) = "images\Ecodevice\ecodevices.png"
    hs.SetDeviceString(dv.Ref(hs), "", True)
    hs.SetDeviceValue(dv.Ref(hs), "0")
    Dim SPair As VSPair
    Dim GPair As VGPair

    SPair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
    SPair.PairType = VSVGPairType.SingleValue
    SPair.Value = 1
    SPair.Status = "Jour BLEU HP"
    hs.DeviceVSP_AddPair(dv.Ref(hs), SPair)

    GPair = New VGPair
    GPair.PairType = VSVGPairType.SingleValue
    GPair.Set_Value = 1
    GPair.Graphic = "/images/Ecodevice/boule_Bleue_HP.png"
    hs.DeviceVGP_AddPair(dv.Ref(hs), GPair)

    SPair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
    SPair.PairType = VSVGPairType.SingleValue
    SPair.Value = 2
    SPair.Status = "Jour BLEU HC"
    hs.DeviceVSP_AddPair(dv.Ref(hs), SPair)

    GPair = New VGPair
    GPair.PairType = VSVGPairType.SingleValue
    GPair.Set_Value = 2
    GPair.Graphic = "/images/Ecodevice/boule_Bleue_HC.png"
    hs.DeviceVGP_AddPair(dv.Ref(hs), GPair)

    SPair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
    SPair.PairType = VSVGPairType.SingleValue
    SPair.Value = 3
    SPair.Status = "Jour BLANC HP"
    hs.DeviceVSP_AddPair(dv.Ref(hs), SPair)

    GPair = New VGPair
    GPair.PairType = VSVGPairType.SingleValue
    GPair.Set_Value = 3
    GPair.Graphic = "/images/Ecodevice/boule_Blanche_HP.png"
    hs.DeviceVGP_AddPair(dv.Ref(hs), GPair)

    SPair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
    SPair.PairType = VSVGPairType.SingleValue
    SPair.Value = 4
    SPair.Status = "Jour BLANC HC"
    hs.DeviceVSP_AddPair(dv.Ref(hs), SPair)

    GPair = New VGPair
    GPair.PairType = VSVGPairType.SingleValue
    GPair.Set_Value = 4
    GPair.Graphic = "/images/Ecodevice/boule_Blanche_HC.png"
    hs.DeviceVGP_AddPair(dv.Ref(hs), GPair)

    SPair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
    SPair.PairType = VSVGPairType.SingleValue
    SPair.Value = 5
    SPair.Status = "Jour ROUGE HP"
    hs.DeviceVSP_AddPair(dv.Ref(hs), SPair)

    GPair = New VGPair
    GPair.PairType = VSVGPairType.SingleValue
    GPair.Set_Value = 5
    GPair.Graphic = "/images/Ecodevice/boule_Rouge_HP.png"
    hs.DeviceVGP_AddPair(dv.Ref(hs), GPair)

    SPair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
    SPair.PairType = VSVGPairType.SingleValue
    SPair.Value = 6
    SPair.Status = "Jour ROUGE HC"
    hs.DeviceVSP_AddPair(dv.Ref(hs), SPair)

    GPair = New VGPair
    GPair.PairType = VSVGPairType.SingleValue
    GPair.Set_Value = 6
    GPair.Graphic = "/images/Ecodevice/boule_Rouge_HC.png"
    hs.DeviceVGP_AddPair(dv.Ref(hs), GPair)

    Case 3
    dv.ImageLarge(hs) = "images\Ecodevice\ecodevices.png"
    dv.Image(hs) = "images\Ecodevice\ecodevices.png"
    hs.SetDeviceString(dv.Ref(hs), "", True)
    hs.SetDeviceValue(dv.Ref(hs), "0")
    Dim SPair As VSPair
    Dim GPair As VGPair

    SPair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
    SPair.PairType = VSVGPairType.SingleValue
    SPair.Value = 0
    SPair.Status = "----"
    hs.DeviceVSP_AddPair(dv.Ref(hs), SPair)

    GPair = New VGPair
    GPair.PairType = VSVGPairType.SingleValue
    GPair.Set_Value = 0
    GPair.Graphic = "/images/Ecodevice/5-x-5_trans_spacer.gif"
    hs.DeviceVGP_AddPair(dv.Ref(hs), GPair)

    SPair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
    SPair.PairType = VSVGPairType.SingleValue
    SPair.Value = 1
    SPair.Status = "Jour BLEU"
    hs.DeviceVSP_AddPair(dv.Ref(hs), SPair)

    GPair = New VGPair
    GPair.PairType = VSVGPairType.SingleValue
    GPair.Set_Value = 1
    GPair.Graphic = "/images/Ecodevice/boule_Bleue.png"
    hs.DeviceVGP_AddPair(dv.Ref(hs), GPair)

    SPair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
    SPair.PairType = VSVGPairType.SingleValue
    SPair.Value = 2
    SPair.Status = "Jour BLANC"
    hs.DeviceVSP_AddPair(dv.Ref(hs), SPair)

    GPair = New VGPair
    GPair.PairType = VSVGPairType.SingleValue
    GPair.Set_Value = 2
    GPair.Graphic = "/images/Ecodevice/boule_Blanche.png"
    hs.DeviceVGP_AddPair(dv.Ref(hs), GPair)

    SPair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
    SPair.PairType = VSVGPairType.SingleValue
    SPair.Value = 3
    SPair.Status = "Jour ROUGE"
    hs.DeviceVSP_AddPair(dv.Ref(hs), SPair)

    GPair = New VGPair
    GPair.PairType = VSVGPairType.SingleValue
    GPair.Set_Value = 3
    GPair.Graphic = "/images/Ecodevice/boule_Rouge.png"
    hs.DeviceVGP_AddPair(dv.Ref(hs), GPair)

    End Select

    If Debug <> 0 Then
    Log("VGP Count: " & hs.DeviceVGP_Count(dv.Ref(hs)))
    End If
    hs.SaveEventsDevices
    Next

    If Debug <> 0 Then
    Log("Fin de la cr&eacute;ation des devices " & Cpt)
    End If

    Catch ex As Exception
    If Debug <> 0 Then
    Log("Erreur lors de la cr&eacute;ation des Devices: " & ex.message.tostring)
    End If

    End Try
    ElseIf Cpt = "Cpt_1" Or Cpt = "Cpt_2" Then
    Try
    If Debug <> 0 Then
    Log("Les devices n'existent pas - Cr&eacute;ation " & Cpt)
    End If
    z = 2 'Cpt = Cpt_1 ou Cpt_2

    For i As Byte = 0 To z 'Creation de 3 devices
    Select Case i
    Case 0
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(DAddS & " Root Device"))
    dv.Address(hs) = DAddS & "-Root"
    BaseRef = dv.Ref(hs)

    Dim DT As New DeviceTypeInfo
    DT.Device_API = DeviceTypeInfo.eDeviceAPI.NO_API
    DT.Device_Type = DeviceTypeInfo.eDeviceType_GenericRoot
    DT.Device_SubType_Description = ""
    DT.Device_SubType = 0
    dv.DeviceType_Set(hs) = DT
    dv.Device_Type_String(hs) = DAddS & "_Device"
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
    Case 1
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(" Puissance Apparente"))
    dv.Address(hs) = DAddS & "-PAPP"
    dv.MISC_Set(hs, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE)
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
    Case 2
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(" Intensit&eacute; Instantan&eacute;e"))
    dv.Address(hs) = DAddS & "-IINST"
    dv.MISC_Set(hs, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE)
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)


    End Select

    dv.Location2(hs) = "Ecodevice"
    dv.location(hs) = DAddS

    hs.DeviceVGP_ClearAll(dv.Ref(hs), True)
    If Debug <> 0 Then
    Log("Device Ref " & Cpt & " " & dv.ref(hs))
    End If



    If i = 0 Then 'set up the relationships between the devices
    root_dv = dv
    dv.Relationship(hs) = Enums.eRelationship.Parent_Root
    Else
    If root_dv IsNot Nothing Then root_dv.AssociatedDevice_Add(hs, dv.Ref(hs))
    dv.Relationship(hs) = Enums.eRelationship.Child
    dv.AssociatedDevice_Add(hs, BaseRef)
    End If

    Select Case i

    Case 0
    hs.SetDeviceString(dv.Ref(hs), "No Status", True)
    dv.ImageLarge(hs) = "images\Ecodevice\Ecodevices.png"
    dv.Image(hs) = "images\Ecodevice\Ecodevices.png"
    Case 1
    dv.ImageLarge(hs) = "images\Ecodevice\Ecodevices.png"
    dv.Image(hs) = "images\Ecodevice\Ecodevices.png"
    Dim SPair As VSPair
    Dim GPair As VGPair

    SPair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
    SPair.PairType = VSVGPairType.Range
    SPair.RangeStart = 0
    SPair.RangeEnd = 10900
    SPair.RangeStatusPrefix = ""
    SPair.RangeStatusSuffix = " VA"
    hs.DeviceVSP_AddPair(dv.Ref(hs), SPair)

    GPair = New VGPair
    GPair.PairType = VSVGPairType.Range
    GPair.RangeStart = 0
    GPair.RangeEnd = 10900
    GPair.Graphic = "/images/Ecodevice/Electricity.png"
    hs.DeviceVGP_AddPair(dv.Ref(hs), GPair)

    hs.SetDeviceString(dv.Ref(hs), "", True)
    hs.SetDeviceValue(dv.Ref(hs), "0")

    Case 2
    dv.ImageLarge(hs) = "images\Ecodevice\Ecodevices.png"
    dv.Image(hs) = "images\Ecodevice\Ecodevices.png"
    Dim SPair As VSPair
    Dim GPair As VGPair

    SPair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
    SPair.PairType = VSVGPairType.Range
    SPair.RangeStart = 0
    SPair.RangeEnd = 48
    SPair.RangeStatusPrefix = ""
    SPair.RangeStatusSuffix = " A"
    SPair.RangeStatusDecimals = 2
    hs.DeviceVSP_AddPair(dv.Ref(hs), SPair)

    GPair = New VGPair
    GPair.PairType = VSVGPairType.Range
    GPair.RangeStart = 0
    GPair.RangeEnd = 48
    GPair.Graphic = "/images/Ecodevice/Electricity.png"
    hs.DeviceVGP_AddPair(dv.Ref(hs), GPair)

    hs.SetDeviceString(dv.Ref(hs), "", True)
    hs.SetDeviceValue(dv.Ref(hs), "0")

    End Select
    If Debug <> 0 Then
    Log("VGP Count: " & hs.DeviceVGP_Count(dv.Ref(hs)))
    End If


    Next
    hs.SaveEventsDevices
    If Debug <> 0 Then
    Log("Fin de la cr&eacute;ation des devices " & Cpt)
    End If

    Catch ex As Exception
    Log("Erreur lors de la cr&eacute;ation des Devices: " & ex.message.tostring)
    End Try

    ElseIf Cpt = "Cpt_1_Jour" Or Cpt = "Cpt_2_Jour" Then
    Try
    If Debug <> 0 Then
    Log("Les devices n'existent pas - Cr&eacute;ation - " & Cpt)
    End If

    z = 6

    For i As Byte = 0 To z 'Creation de 7 devices
    Select Case i
    Case 0
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(DAddS & " Root Device"))
    dv.Address(hs) = DAddS & "-Root"
    BaseRef = dv.Ref(hs)

    Dim DT As New DeviceTypeInfo
    DT.Device_API = DeviceTypeInfo.eDeviceAPI.NO_API
    DT.Device_Type = DeviceTypeInfo.eDeviceType_GenericRoot
    DT.Device_SubType_Description = ""
    DT.Device_SubType = 0
    dv.DeviceType_Set(hs) = DT
    dv.Device_Type_String(hs) = DAddS & "_Device"
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
    Case 1
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(" Jour Bleu HC"))
    dv.Address(hs) = DAddS & "-HCJB"
    dv.MISC_Set(hs, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE)
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
    Case 2
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(" Jour Bleu HP"))
    dv.Address(hs) = DAddS & "-HPJB"
    dv.MISC_Set(hs, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE)
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
    Case 3
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(" Jour Blanc HC"))
    dv.Address(hs) = DAddS & "-HCJW"
    dv.MISC_Set(hs, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE)
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
    Case 4
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(" Jour Blanc HP"))
    dv.Address(hs) = DAddS & "-HPJW"
    dv.MISC_Set(hs, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE)
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
    Case 5
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(" Jour Rouge HC"))
    dv.Address(hs) = DAddS & "-HCJR"
    dv.MISC_Set(hs, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE)
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
    Case 6
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(" Jour Rouge HP"))
    dv.Address(hs) = DAddS & "-HPJR"
    dv.MISC_Set(hs, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE)
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)


    End Select

    dv.Location2(hs) = "Ecodevice"
    dv.location(hs) = DAddS

    hs.DeviceVGP_ClearAll(dv.Ref(hs), True)
    If Debug <> 0 Then
    Log("Device Ref " & Cpt & " " & dv.ref(hs))
    End If



    If i = 0 Then 'set up the relationships between the devices
    root_dv = dv
    dv.Relationship(hs) = Enums.eRelationship.Parent_Root
    Else
    If root_dv IsNot Nothing Then root_dv.AssociatedDevice_Add(hs, dv.Ref(hs))
    dv.Relationship(hs) = Enums.eRelationship.Child
    dv.AssociatedDevice_Add(hs, BaseRef)
    End If

    Select Case i

    Case 0
    hs.SetDeviceString(dv.Ref(hs), "No Status", True)
    dv.ImageLarge(hs) = "images\Ecodevice\Ecodevices.png"
    dv.Image(hs) = "images\Ecodevice\Ecodevices.png"

    Case 1, 2, 3, 4, 5, 6
    hs.SetDeviceString(dv.Ref(hs), "", True)
    hs.SetDeviceValue(dv.Ref(hs), "0")
    dv.ImageLarge(hs) = "images\Ecodevice\ecodevices.png"
    dv.Image(hs) = "images\Ecodevice\ecodevices.png"
    Dim SPair As VSPair
    Dim GPair As VGPair

    SPair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
    SPair.PairType = VSVGPairType.Range
    SPair.RangeStart = 0
    SPair.RangeEnd = 100
    SPair.RangeStatusPrefix = ""
    SPair.RangeStatusSuffix = " Kw"
    SPair.RangeStatusDecimals = 3
    hs.DeviceVSP_AddPair(dv.Ref(hs), SPair)

    GPair = New VGPair
    GPair.PairType = VSVGPairType.Range
    GPair.RangeStart = 0
    GPair.RangeEnd = 100
    GPair.Graphic = "/images/Ecodevice/Electricity.png"
    hs.DeviceVGP_AddPair(dv.Ref(hs), GPair)

    hs.SetDeviceString(dv.Ref(hs), "", True)
    hs.SetDeviceValue(dv.Ref(hs), "0")

    End Select
    If Debug <> 0 Then
    Log("VGP Count: " & hs.DeviceVGP_Count(dv.Ref(hs)))
    End If


    Next
    hs.SaveEventsDevices
    If Debug <> 0 Then
    Log("Fin de la cr&eacute;ation des devices " & Cpt)
    End If

    Catch ex As Exception
    Log("Erreur lors de la cr&eacute;ation des Devices: " & ex.message.tostring)
    End Try

    Else
    Try
    If Debug <> 0 Then
    Log("Les devices n'existent pas - Cr&eacute;ation - " & Cpt)
    End If


    If Cpt = "Cpt_1_Mois" Then
    z = 6
    ElseIf Cpt = "Cpt_1_An" Then
    z = 6
    ElseIf Cpt = "Cpt_2_Mois" Then
    z = 6
    ElseIf Cpt = "Cpt_2_An" Then
    z = 6
    End If

    For i As Byte = 0 To z 'Creation de 7 devices
    Select Case i
    Case 0
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(DAddS & " Root Device"))
    dv.Address(hs) = DAddS & "-Root"
    BaseRef = dv.Ref(hs)

    Dim DT As New DeviceTypeInfo
    DT.Device_API = DeviceTypeInfo.eDeviceAPI.NO_API
    DT.Device_Type = DeviceTypeInfo.eDeviceType_GenericRoot
    DT.Device_SubType_Description = ""
    DT.Device_SubType = 0
    dv.DeviceType_Set(hs) = DT
    dv.Device_Type_String(hs) = DAddS & "_Device"
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
    Case 1
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(" Jour Bleu HC"))
    dv.Address(hs) = DAddS & "-HCJB"
    dv.MISC_Set(hs, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE)
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
    Case 2
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(" Jour Bleu HP"))
    dv.Address(hs) = DAddS & "-HPJB"
    dv.MISC_Set(hs, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE)
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
    Case 3
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(" Jour Blanc HC"))
    dv.Address(hs) = DAddS & "-HCJW"
    dv.MISC_Set(hs, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE)
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
    Case 4
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(" Jour Blanc HP"))
    dv.Address(hs) = DAddS & "-HPJW"
    dv.MISC_Set(hs, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE)
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
    Case 5
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(" Jour Rouge HC"))
    dv.Address(hs) = DAddS & "-HCJR"
    dv.MISC_Set(hs, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE)
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)
    Case 6
    dv = hs.GetDeviceByRef(hs.NewDeviceRef(" Jour Rouge HP"))
    dv.Address(hs) = DAddS & "-HPJR"
    dv.MISC_Set(hs, Enums.dvMISC.SET_DOES_NOT_CHANGE_LAST_CHANGE)
    dv.MISC_Set(hs, Enums.dvMISC.STATUS_ONLY)


    End Select

    dv.Location2(hs) = "Ecodevice"
    dv.location(hs) = DAddS

    hs.DeviceVGP_ClearAll(dv.Ref(hs), True)
    If Debug <> 0 Then
    Log("Device Ref " & Cpt & " " & dv.ref(hs))
    End If



    If i = 0 Then 'set up the relationships between the devices
    root_dv = dv
    dv.Relationship(hs) = Enums.eRelationship.Parent_Root
    Else
    If root_dv IsNot Nothing Then root_dv.AssociatedDevice_Add(hs, dv.Ref(hs))
    dv.Relationship(hs) = Enums.eRelationship.Child
    dv.AssociatedDevice_Add(hs, BaseRef)
    End If

    Select Case i

    Case 0
    hs.SetDeviceString(dv.Ref(hs), "No Status", True)
    dv.ImageLarge(hs) = "images\Ecodevice\Ecodevices.png"
    dv.Image(hs) = "images\Ecodevice\Ecodevices.png"

    Case 1, 2, 3, 4, 5, 6
    hs.SetDeviceString(dv.Ref(hs), "", True)
    hs.SetDeviceValue(dv.Ref(hs), "0")
    dv.ImageLarge(hs) = "images\Ecodevice\ecodevices.png"
    dv.Image(hs) = "images\Ecodevice\ecodevices.png"
    'Dim SPair As VSPair
    Dim GPair As VGPair

    'SPair = New VSPair(HomeSeerAPI.ePairStatusControl.Status)
    'SPair.PairType = VSVGPairType.Range
    'SPair.RangeStart = 0
    'SPair.RangeEnd = 100
    'SPair.Value = ""
    'SPair.RangeStatusSuffix = " Kw"
    'SPair.RangeStatusDecimals = 3
    'hs.DeviceVSP_AddPair(dv.Ref(hs), SPair)

    GPair = New VGPair
    GPair.PairType = VSVGPairType.Range
    GPair.RangeStart = 0
    GPair.RangeEnd = 10000
    GPair.Graphic = "/images/Ecodevice/edf.jpg"
    hs.DeviceVGP_AddPair(dv.Ref(hs), GPair)

    hs.SetDeviceString(dv.Ref(hs), "", True)
    hs.SetDeviceValue(dv.Ref(hs), "0")

    End Select
    If Debug <> 0 Then
    Log("VGP Count: " & hs.DeviceVGP_Count(dv.Ref(hs)))
    End If

    Next
    hs.SaveEventsDevices
    If Debug <> 0 Then
    Log("Fin de la cr&eacute;ation des devices " & Cpt)
    End If

    Catch ex As Exception
    Log("Erreur lors de la cr&eacute;ation des Devices: " & ex.message.tostring)
    End Try
    End If
    End Sub
    Jean-Francois.

    Comment


    • #3
      Thx JF, but it is for the moment too complicated for me to understand your code, i just need to create a simple device with location by script i have found in another thread and i don't understand why i have this error...

      Comment


      • #4
        UP PLZ

        Comment


        • #5
          Originally posted by onetic View Post
          hello, fist time for me here, i'm a french user of homeseer, not familiar with expert boards or developpementso i wish you could help me for something that you will probably find very easy.
          When i start this vb script i've found in other thread :

          <code>
          Sub Main(params As Object)
          Dim dv As Scheduler.Classes.DeviceClass = Nothing
          dv = hs.NewDeviceRef("Toon Test apparaat")
          If dv IsNot Nothing Then
          dv.Device_Type_String(hs) = "Joe Bazooka Bubble Gum"
          hs.WriteLog("apparaat referentie", dv.ref(hs))
          End If
          End Sub
          </code>

          i have this error :

          Error 1
          Try changing your assignment of dv to:
          dv = hs.GetDeviceByRef(hs.NewDeviceRef("Toon Test apparaat"))

          I would also recommend that you visit the TenScripting site. It is a very useful tool for writing VB scripts for HS.
          Mike____________________________________________________________ __________________
          HS3 Pro Edition 3.0.0.500

          HW: Stargate | NX8e | CAV6.6 | Squeezebox | PCS | WGL 800RF, Rain8Net+ | RFXCOM | QSE100D | Vantage Pro | Green-Eye | X10: XTB-232, -IIR | Edgeport/8 | Way2Call | Ecobee3

          Comment

          Working...
          X