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

Here’s more of the script:


'
'
Poll EZIO (may be called from external scripts or from within HomeSeer)
'

Public Sub EZIOPollDevices(parms as object)
Try
If g_bEZIO_Enabled Then
hs.plugin("Insteon").ExtDev_TransmitToExternalDevice(g_szEZIO_DevName,&H7,&H49,0)
if g_bDebug Then hs.WriteLog(g_szScriptname,"EZIOPollDevices: Sending 0x49 to request report")
End If

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

'
'
The Insteon plug-in calls this routine every time there's data from our device
'

Public Sub EZIOReceiveData(ByVal InsteonData As String)
Dim Data() As String
Dim Flags As Long
Dim Status As Long
Dim MsgType As Long

Try
If g_bDebug Then hs.WriteLog(g_szScriptName,"Received Insteon Data: " & InsteonData & "")
Data = Split(InsteonData, " ")

If Data(0) = "ACK" Then ' This was an ACK response to a prior command. There is extra data here. The standard ACK will also be sent

Select Case Val("&h" & Data(1))
Case &H49 ' Ack was to a Sensor Report command
if g_bDebug Then EZIOSensorReport(Val("&h" & Data(2)), Val("&h" & Data(12)))
End Select

Else ' This is a standard Insteon message

Flags = CLng("&H" & Data(7))
If g_bDebug Then hs.WriteLog(g_szScriptName,"FlagsRaw=" & Hex$(Flags) & ", masked=" & Hex$(Flags AND &hE0))

Select Case (Flags AND &hE0)

Case &h80 ' Broadcast transmissions from our device
MsgType = CLng("&h" & Data(8)) ' 0x27 means input sensor status change
Status = CLng("&h" & Data(9)) ' bit-mapped, 0=all off, 1=1 on, 2=2 on, 3=1 and 2 on, etc.
If MsgType = &H27 Then
If g_bDebug Then hs.WriteLog(g_szScriptName,"Got broadcast from our device: MsgType=" & Hex$(MsgType) & ", Status=" & Hex$(Status) & "")
EZIOProcessStatus(Status) ' Input sensor change status report
End If

Case &h20 ' Ack replies from our device to any other device
MsgType = CLng("&h" & Data(8))
Status = CLng("&h" & Data(9)) ' bit-mapped, 0=all off, 1=1 on, 2=2 on, 3=1 and 2 on, etc.
If MsgType = &H49 Or MsgType = &h45 OR MsgType = &h46 Then
If g_bDebug Then hs.WriteLog(g_szScriptName,"Got ACK from command to our device: MsgType=" & Hex$(MsgType) & ", BitMap=" & Hex$(Status) & "")
EZIOProcessStatus(Status) ' Input sensor change status report
End If

Case &hC0 ' Group control broadcast commands from our device
MsgType = CLng("&h" & Data(6))
Status = CLng("&h" & Data(8))
If g_bDebug Then hs.WriteLog(g_szScriptName,"Got group broadcast from our device: Group=" & Hex$(MsgType) & ", Cmd=" & Hex$(Status) & "")
EZIOProcessBroadcast(MsgType,Status)

Case &hA0 ' Nak replies from our device to any other device
If g_bDebug Then hs.WriteLog(g_szScriptName,"NAK from our device to some other device")

Case &h00 ' Direct commands from our device to any other device
If g_bDebug Then hs.WriteLog(g_szScriptName,"Direct from our device to some other device")

Case &h40 ' Group control clean-up commands from our device
MsgType = CLng("&h" & Data(6))
Status = CLng("&h" & Data(8))
If g_bDebug Then hs.WriteLog(g_szScriptName,"Got group cleanup from our device: Group=" & Hex$(MsgType) & ", Cmd=" & Hex$(Status) & "")
EZIOProcessBroadcast(MsgType,Status)

Case &h60 ' Ack replies from our device to group clean-up commands from any device
If g_bDebug Then hs.WriteLog(g_szScriptName,"ACK to group cleanup")

Case &hE0 ' Nak replies from our device to group clean-up commands from any device
If g_bDebug Then hs.WriteLog(g_szScriptName,"NAK to group cleanup")
End Select

End If

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

'
'
Create input and output virtual devices (only if they don't already exist)
'

Private Sub EZIOCreateDevices()
Dim Lp As Integer
Dim Ref As Long
Dim dv As Object
Dim dc As String
Dim DevName As String
Dim Button As String
Dim Label As String

if g_bDebug Then hs.WriteLog(g_szScriptName,"EZIOCreateDevices(): Starting")

Try
g_bEZIO_Busy = True

For Lp = 0 To 5
dc = (g_dwEZIO_FirstDeviceCode + Lp).ToString
If hs.DeviceExists(g_szEZIO_HouseCode & dc) = -1 Then
Select Case Lp
Case 0,1
DevName = "Garage Opener " & (Lp + 1).ToString
Button = g_szScriptName & "(""EZIOOperateRelay"",""" & Lp + 1 & """)"
Label = "Operate"
Case Else
DevName = "Garage Door " & (Lp - 2 + 1).ToString
Button = g_szScriptName & "(""EZIOPollDevices"",""0"")"
Label = " Verify "
End Select
Ref = hs.NewDeviceRef (DevName)
dv = hs.GetDeviceByRef(Ref)
dv.hc = g_szEZIO_HouseCode
dv.dc = dc
dv.can_dim = False
dv.location = g_szEZIO_DevLocation
dv.location2 = "auto-created"
dv.misc = &h10
dv.dev_type_string = "Status Only"
hs.SetDeviceValue (DevName,0)
hs.SetDeviceString (DevName,"Unverified",False)
hs.SetDeviceStatus (DevName,3)
hs.SaveEventsDevices()
hs.DeviceButtonAdd (g_szEZIO_HouseCode & dc,Button,Label)
hs.WriteLog (g_szScriptName,"Created device " & DevName & " as " & g_szEZIO_HouseCode & dc)
End If
Next

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

g_bEZIO_Busy = False
if g_bDebug Then hs.WriteLog(g_szScriptName,"EZIOCreateDevices(): Finished")
End Sub