Class Import_HS2_Events_With_Some_Actions Dim con As New OleDb.OleDbConnection("PROVIDER=Microsoft.jet.oledb.4.0;Data Source = C:\Program Files (x86)\HomeSeer HS3\scripts\sample.mdb") 'Dim con As New OleDb.OleDbConnection("PROVIDER=Microsoft.jet.oledb.4.0;Data Source = " & My.Computer.FileSystem.SpecialDirectories.Desktop & "\sample.mdb") Const IniFile As String = "HS2_2_HS3_ref_map.ini" Public Sub Main(parm As Object) Dim sql As String Dim Cmd As OleDb.OleDbCommand Dim Reader As OleDb.OleDbDataReader Dim HS3EventRef As Long Dim HS2EventRef As String Try hs.WriteLog("HS2->HS3", "# Start Importing Events #") con.Open() sql = "Select * from Events" Cmd = New OleDb.OleDbCommand(sql, con) Reader = Cmd.ExecuteReader() Do While Reader.Read() 'hs.WriteLog("HS2-HS3", "Deleting event: " & Reader.Item("Name").ToString) 'hs.DeleteEvent(Reader.Item("Name").ToString) HS2EventRef = Reader.Item("EvRef").ToString HS3EventRef = hs.GetEventRefByNameAndGroup(Reader.Item("Name").ToString, Reader.Item("group").ToString) If HS3EventRef < 0 Then hs.WriteLog("HS2->HS3", "-> New Event: (" & Reader.Item("group").ToString & ")" & Reader.Item("Name").ToString) HS3EventRef = hs.NewEventGetRef(Reader.Item("Name").ToString, Reader.Item("group").ToString, "Imported From HS2") Else hs.WriteLog("HS2->HS3 Info", "Event Exists: " & Reader.Item("Name").ToString & " HS3EventRef=" & HS3EventRef) End If CreateActions(HS3EventRef, Reader) hs.SaveINISetting("Event Ref HS2 to HS3", HS2EventRef, HS3EventRef, IniFile) hs.SaveINISetting("Event Ref HS3 to HS2", HS3EventRef, HS2EventRef, IniFile) Loop hs.WriteLog("HS2->HS3", "# Finish Importing Devices #") Catch ex As Exception hs.WriteLog("HS2->HS3 Error", "Exception in script: " & ex.Message) End Try con.Close() End Sub Public Sub DeleteAllEvents() For Each e In Events() hs.DeleteEventByRef(e.Event_Ref) Next End Sub Public Function Events() As System.Collections.Generic.List(Of HomeSeerAPI.strEventData) Dim _events As New System.Collections.Generic.List(Of HomeSeerAPI.strEventData) For Each e As HomeSeerAPI.strEventData In hs.Event_Info_All _events.Add(e) Next Return _events End Function Public Sub CreateActions(ByVal EventReference As Long, ByVal EventReader As OleDb.OleDbDataReader) Dim sql As String Dim Cmd As OleDb.OleDbCommand Dim Reader As OleDb.OleDbDataReader 'Dim Requiredsetpoint As Double = 5 '?? sql = "Select * from EventActions WHERE action_type=1 AND evref = " & EventReader.Item("evref").ToString Cmd = New OleDb.OleDbCommand(sql, con) Reader = Cmd.ExecuteReader() Do While Reader.Read() Dim HS2devicerefs() As String = Reader.Item("device_refs").ToString.Split(",") For Each HS2DeviceRef As Integer In HS2devicerefs hs.WriteLog("HS2->HS3", "New Action: " & Reader.Item("Action_type").ToString & " DimVal:" & Reader.Item("device_dimval").ToString) Dim HS3DeviceRef As Integer = hs.GetINISetting("Ref HS2 to HS3", HS2DeviceRef, -1, IniFile) If HS3DeviceRef = -1 Then hs.WriteLog("HS2->HS3 Error", "HS2 Dev not found in Lookup file: " & HS2DeviceRef) Else Dim HS3Device As Scheduler.Classes.DeviceClass = hs.GetDeviceByRef(HS3DeviceRef) If HS3Device Is Nothing Then hs.WriteLog("HS2->HS3 Error", "HS3 Dev found in Lookup file, not found in HS3: " & HS3DeviceRef) Else Dim HS3DeviceName As String = HS3Device.Name(hs).ToString Dim add_action_return As String Dim CAPI As HomeSeerAPI.CAPIControl Select Case Reader.Item("device_dimval") Case 0 hs.WriteLog("HS2->HS3", "New Action: Turn OFF HS3 Dev: " & HS3DeviceName) CAPI = hs.CAPIGetSingleControlByUse(HS3DeviceRef, HomeSeerAPI.ePairControlUse._Off) add_action_return = hs.AddDeviceActionToEvent(EventReference, CAPI) Case 100 hs.WriteLog("HS2->HS3", "New Action: Turn ON HS3 Dev: " & HS3DeviceName) CAPI = hs.CAPIGetSingleControlByUse(HS3DeviceRef, HomeSeerAPI.ePairControlUse._On) add_action_return = hs.AddDeviceActionToEvent(EventReference, CAPI) Case Else hs.WriteLog("HS2->HS3", "New Action: Dim HS3 Dev: " & HS3DeviceName & " TO: " & Reader.Item("device_dimval").ToString) CAPI = hs.CAPIGetSingleControlByUse(HS3DeviceRef, HomeSeerAPI.ePairControlUse._Dim) CAPI.ControlValue = Reader.Item("device_dimval") CAPI.Label = "Dim " & CAPI.ControlValue & "%" add_action_return = hs.AddDeviceActionToEvent(EventReference, CAPI) End Select If add_action_return <> "" Then hs.WriteLog("HS2->HS3 Error", "AddDeviceAction ret val:" & add_action_return) End If End If End If Next Loop End Sub End Class