Reply To: Homeseer and EZIO8SA 2017-12-21T12:26:59+00:00

HOME Forums Input/Output EZIOxx Homeseer and EZIO8SA Reply To: Homeseer and EZIO8SA

Anonymous
Post count: 35

More (this is quite annoying):



'
'
helper function: returns numeric code meaning "on" or "off"
'

Private Function EZIOOnOffCode (ByVal Code as Byte) as Byte
If Code Then
EZIOOnOffCode = 2 ' on
Else
EZIOOnOffCode = 3 ' off
End If
End Function

'
'
helper function: returns string representing device status
'

Private Function EZIODevStatus (ByVal Code as Byte,ByVal DC as Integer) as String
Select Case DC ' NOTE: This is the DC, which is one more than the "real" device number!
Case 1,2 ' relays
Select Case Code
Case 2: EZIODevStatus = "Moving"
Case 3: EZIODevStatus = "Stopped"
Case Else: EZIODevStatus = "Unknown"
End Select

Case Else ' garage door sensors and fence gate sensors
Select Case Code
Case 2: EZIODevStatus = "Closed"
Case 3: EZIODevStatus = "Open"
Case Else: EZIODevStatus = "Unknown"
End Select
End Select
End Function

Private Function EZIODevValue (ByVal Code as Byte) As Long
If Code = 2 Then
EZIODevValue = 1
ElseIf Code = 3 Then
EZIODevValue = 0
Else
EZIODevValue = 999
End If
End Function

Private Function EZIODevString(ByVal Code as Byte,DC as Integer) As String
Select Case DC ' NOTE: This is the DC, which is one more than the "real" device number!
Case 1,2 ' relays
Select Case Code
Case 2: EZIODevString = "Moving"
Case 3: EZIODevString = "Stopped"
Case Else: EZIODevString = "Unknown"
End Select
Case 3,4 ' garage door sensors
Select Case Code
Case 2: EZIODevString = "Door Closed at " & Now
Case 3: EZIODevString = "Door Open at " & Now
Case Else: EZIODevString = "Unknown Status at " & Now
End Select
Case Else ' fence gate sensors
Select Case Code
Case 2: EZIODevString = "Gate Closed at " & Now
Case 3: EZIODevString = "Gate Open at " & Now
Case Else: EZIODevString = "Unknown Status at " & Now
End Select
End Select
End Function

'
'
helper routine: changes virtual devices (only if new value differs from old value)
'

Private Sub EZIOSetIfChanged(ByVal HC as String,ByVal DC as String,ByVal NewCode as Byte)
Dim OldCode as Byte
Dim OldStatus as String
Dim NewStatus as String
Dim NewValue as Long
Dim NewString as String

OldCode = hs.DeviceStatus(HC & DC)
OldStatus = EZIODevStatus (OldCode,DC)

If OldCode NewCode Then
NewStatus = EZIODevStatus (NewCode,DC)
NewValue = EZIODevValue (NewCode)
NewString = EZIODevString (NewCode,DC)

hs.WriteLog(g_szScriptName,"EZIO " & HC & DC & " changed from " & OldStatus & " to " & NewStatus & "")
hs.SetDeviceStatus(HC & DC,NewCode)
hs.SetDeviceString(HC & DC,NewString,False)
hs.SetDeviceValue (HC & DC,NewValue)
ElseIf g_bDebug Then
hs.WriteLog(g_szScriptName,"EZIO " & HC & DC & " was already " & OldStatus & "; no change")
End If
End Sub

'
'
helper routine: processes EZIO device change status messages
'

Private Sub EZIOProcessStatus(ByVal Status As Byte)
If g_bDebug Then hs.WriteLog(g_szScriptName,"EZIOProcessStatus(): " & Hex$(Status))

Try
g_bEZIO_Busy = True

If (Status > 127) Then
EZIOSetIfChanged(g_szEZIO_HouseCode,(g_dwEZIO_FirstDeviceCode + 0).ToString,EZIOOnOffCode(Status AND 1))
EZIOSetIfChanged(g_szEZIO_HouseCode,(g_dwEZIO_FirstDeviceCode + 1).ToString,EZIOOnOffCode(Status AND 2))
Else
EZIOSetIfChanged(g_szEZIO_HouseCode,(g_dwEZIO_FirstDeviceCode + 2).ToString,EZIOOnOffCode(Status AND 1))
EZIOSetIfChanged(g_szEZIO_HouseCode,(g_dwEZIO_FirstDeviceCode + 3).ToString,EZIOOnOffCode(Status AND 2))
EZIOSetIfChanged(g_szEZIO_HouseCode,(g_dwEZIO_FirstDeviceCode + 4).ToString,EZIOOnOffCode(Status AND 4))
EZIOSetIfChanged(g_szEZIO_HouseCode,(g_dwEZIO_FirstDeviceCode + 5).ToString,EZIOOnOffCode(Status AND 8))
End If

Catch ex As Exception
hs.WriteLog(g_szScriptName,"Error in EZIOProcessStatus: " & ex.ToString)
End Try

g_bEZIO_Busy = False
End Sub