I have a working HS script. To be honest, I downloaded a HS3 OT script, but I don't know the source anymore. It is a modified version of the HS2 plugin from the opening post. I have attached this original HS script (OT_script_HS3.rar). All credits to the unknown author!
I experienced a lot of issues with the script. It uses the Telnet connection and it had a lot of timing problems. The data request from HS to the OTG interrupted the data flow in an uncontrolled manner and the wrong responses were evaluated by the script.
So I experimented (hence the extensive debugging lines in the script) and found a way to send a dummy request to prepair the OTG so that it will send the right response on the next request.
Furthermore there were some issues with type declaration (integer instead of float) and some other minor issues.
Install the contents of the attached OT_script_HS.rar in your Homeseer program folder and replace the code of BLB_OT_monitor.vb with my modified code:
Code: Select all
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Const INI_FILE As String = "hssi_BLB_OT_monitor.ini" ' name ini file
Sub Main(ByVal varParameters)
Dim Command As String = varParameters
Dim RemoteIP As String = hs.GetINISetting("Telnet", "TCPAddress", "", INI_FILE)
Dim PortNumber As String = hs.GetINISetting("Telnet", "TCPPort", "", INI_FILE)
Dim Debug As Integer = hs.GetINISetting("Debug", "Debug", "", INI_FILE)
Dim Reply As String
' start with a PS=1 command to stop the standard output of OT messages
Reply = SendDummy("PS=1",RemoteIP,PortNumber,Debug) ' Just a dummy to clear the buffers
Sleep(1000)
Reply = SendMessage("PS=1",RemoteIP,PortNumber,Debug)
If Reply <> "error" Then
If Command = "update"
If Debug > 0 Then hs.WriteLog("debugOTGW1","Main; Message Send: update - Now execute CreateTempDropDown")
CreateTempDropDown()
If Debug > 0 Then hs.WriteLog("debugOTGW1","Main; Message Send: update - Now execute PS_UpdateDevices")
PS_UpdateDevices(Reply,Debug)
If Debug > 0 Then hs.WriteLog("debugOTGW1","Main; Message Send: update - Now sleep 200 ms and execute PR_UpdateDevices")
Sleep(200)
PR_UpdateDevices(RemoteIP,PortNumber,Debug)
Else
hs.WriteLog("OTGW","Main; Message Send: " & Command)
Reply = SendMessage(Command,RemoteIP,PortNumber,Debug)
hs.WriteLog("OTGW","Main; Message Reply: " & Reply)
End If
End If
' set gateway back to default output
Reply = SendMessage("PS=0",RemoteIP,PortNumber,Debug)
End Sub
Sub SetTempChanged(ByVal varParameters)
'' This function is called when value of "Temperature Override" is changed
Dim RemoteIP As String = hs.GetINISetting("Telnet", "TCPAddress", "", INI_FILE)
Dim PortNumber As String = hs.GetINISetting("Telnet", "TCPPort", "", INI_FILE)
Dim Debug As Integer = hs.GetINISetting("Debug", "Debug", "", INI_FILE)
Dim Reply As String
If Debug > 0 Then hs.WriteLog("debugOTGW1","SetTempChanged; Parameters: " & Cstr(varParameters(2)))
If varParameters(2) = 0 Then
hs.WriteLog("OTGW","SetTempChanged; Disabling Temperature Override")
Reply = SendMessage("TT=0",RemoteIP,PortNumber,Debug)
hs.WriteLog("OTGW","SetTempChanged; Reply: " & Reply)
hs.SetDeviceString(varParameters(0),"<img src='images/Homeseer/ui/5-x-5_trans_spacer.gif'>" & _
hs.DeviceVSP_GetStatus(varParameters(0), varParameters(2), 1), False)
Else
Dim dvRef
dvRef = hs.GetDeviceRef("OT_TempOverrideMode")
If dvRef > 0 then
Dim value = hs.DeviceValue(dvRef)
If value = 0 Then
Reply = SendMessage("TT=" & Cstr(varParameters(2)) & ".00",RemoteIP,PortNumber,Debug)
hs.WriteLog("OTGW","SetTempChanged; Temporary Override. Reply: " & Reply)
hs.SetDeviceString(varParameters(0),"<img src='images/Homeseer/ui/5-x-5_trans_spacer.gif'>" & _
"Temporary Override = " & hs.DeviceVSP_GetStatus(varParameters(0), varParameters(2), 1), False)
Else
Reply = SendMessage("TC=" & Cstr(varParameters(2)) & ".00",RemoteIP,PortNumber,Debug)
hs.WriteLog("OTGW","SetTempChanged; Constant Override. Reply: " & Reply)
hs.SetDeviceString(varParameters(0),"<img src='images/Homeseer/ui/5-x-5_trans_spacer.gif'>" & _
"Constant Override = " & hs.DeviceVSP_GetStatus(varParameters(0), varParameters(2), 1), False)
End If
End If
End If
End Sub
Sub SetTempOverrideMode(ByVal varParameters)
'' This function is called when value of "Temperature Override Mode" is changed
Dim RemoteIP As String = hs.GetINISetting("Telnet", "TCPAddress", "", INI_FILE)
Dim PortNumber As String = hs.GetINISetting("Telnet", "TCPPort", "", INI_FILE)
Dim Debug As Integer = hs.GetINISetting("Debug", "Debug", "", INI_FILE)
Dim Reply As String
If Debug > 0 Then hs.WriteLog("debugOTGW1","SetTempOverrideMode; Parameters: " & Cstr(varParameters(2)))
Dim dvRef
dvRef = hs.GetDeviceRef("OT_TempDropDown")
If dvRef > 0 then
Dim value = hs.DeviceValue(dvRef)
If value > 0 Then
If varParameters(2) = 0
Reply = SendMessage("TT=" & Cstr(value) & ".00",RemoteIP,PortNumber,Debug)
hs.WriteLog("OTGW","SetTempOverrideMode; Temporary Override. Reply: " & Reply)
hs.SetDeviceString(dvRef,"<img src='images/Homeseer/ui/5-x-5_trans_spacer.gif'>" & _
"Temporary Override = " & hs.DeviceVSP_GetStatus(dvRef, value, 1), False)
Else
Reply = SendMessage("TC=" & Cstr(value) & ".00",RemoteIP,PortNumber,Debug)
hs.WriteLog("OTGW","SetTempOverrideMode; Constant Override. Reply: " & Reply)
hs.SetDeviceString(dvRef,"<img src='images/Homeseer/ui/5-x-5_trans_spacer.gif'>" & _
"Constant Override = " & hs.DeviceVSP_GetStatus(dvRef, value, 1), False)
End If
End If
End If
hs.SetDeviceString(varParameters(0), "<img src='images/Homeseer/ui/5-x-5_trans_spacer.gif'>" & _
hs.DeviceVSP_GetStatus(varParameters(0), varParameters(2), 1), False)
End Sub
Private Function SendDummy(Message,RemoteIP,PortNumber,Debug) as String
Dim Reply as String
Dim Counter as Integer = 1
Dim CounterMax as Integer = 30
If Debug > 0 Then hs.WriteLog("debugOTGW1","SendDummy; Message: " & Message)
Dim Client As New TcpClient()
Try
Client.Connect(IPAddress.Parse(RemoteIP), PortNumber)
Dim NetStream As NetworkStream = Client.GetStream()
' Send message
SendString(NetStream, message & vbCrLf)
' Receive reply
Sleep(500)
Reply = CleanReply(ReadString(Client),Debug)
If Debug > 0 Then hs.WriteLog("debugOTGW1","SendDummy; CleanReply: " & Reply)
Client.Close()
Catch ex As Exception
hs.WriteLog("Error","SendDummy; OTGW: " & ex.Message)
Reply = "error"
Client.Close()
End Try
Return Reply
End Function
Private Function SendMessage(Message,RemoteIP,PortNumber,Debug) as String
Dim Reply as String
Dim Counter as Integer = 1
Dim CounterMax as Integer = 30
If Debug > 0 Then hs.WriteLog("debugOTGW1","SendMessage; Message: " & Message)
Dim Client As New TcpClient()
Try
Client.Connect(IPAddress.Parse(RemoteIP), PortNumber)
Dim NetStream As NetworkStream = Client.GetStream()
' Send message
SendString(NetStream, message & vbCrLf)
' Receive reply
' Sleep(200)
Reply = CleanReply(ReadString(Client),Debug)
If Debug > 0 Then hs.WriteLog("debugOTGW1","SendMessage; CleanReply: " & Reply)
' when the request comes between the thermostat request and the boiler response, it receives the wrong reply and we need to look at the next message
Do While Not Left(Reply,2) = Left(Message,2) And Counter < CounterMax ' When a command is accepted by the gateway, it should respond with the two letters of the command code
Counter += 1
If Debug > 1 Then hs.WriteLog("debugOTGW2","SendMessage; Looking for a valid reply to " & Message & " (attempt " & Counter & ")")
Reply = ReadString(Client)
If Debug > 1 Then hs.WriteLog("debugOTGW2","SendMessage; This is the reply for " & Message & ": " & Reply)
If Not Left(Reply,2) = Left(Message,2) And Counter = CounterMax Then ' to avoid indefinite loop, the loop will end when the counter limit CounterMax has been reached
hs.WriteLog("OTGW","SendMessage; Error! No valid response to message " & Message)
Reply = "error"
End If
Loop
' only for PS=1 we need to evaluate the next message with the Print Summary information
Counter = 0
Do While Message = "PS=1" And Not Reply = "error" And Not Left(Reply,2) = "00" And Counter < CounterMax-1 ' a valid response to the Print Summary (PS) starts with Status (MsgID=0) which starts with "00" by default
Counter += 1
If Debug > 1 Then hs.WriteLog("debugOTGW2","SendMessage; Looking for a valid Print Summary reply (attempt " & Counter & ")")
If Debug > 1 Then hs.WriteLog("debugOTGW2","SendMessage; This is the length of the reply: " & Len(Reply))
If Len(Reply) > 7 And Left(Reply,5) = "PS: 1" Then ' sometimes the Print Summary information is already attached to "PS: 1 " in the reply (due to timing issues); we just need to cut off the "PS: 1 ", that's it!
Reply = Right(Reply,Len(Reply)-7)
Else
Reply = ReadString(Client)
End If
If Debug > 1 Then hs.WriteLog("debugOTGW2","SendMessage; This is the Print Summary reply: " & Reply)
If Not Left(Reply,2) = "00" And Counter = CounterMax Then ' to avoid indefinite loop, the loop will end when the counter limit CounterMax has been reached
hs.WriteLog("OTGW","SendMessage; Error! No valid Print Summary reply")
Reply = "error"
End If
Loop
' If Message = "PS=1" Then
' ' second message is interesting
' If Debug > 1 Then hs.WriteLog("debugOTGW2","SendMessage; Looking for a valid reply to PS=1 ....")
' Reply = ReadString(Client)
' If Debug > 1 Then hs.WriteLog("debugOTGW2","SendMessage; This is the reply for PS=1: " & Reply)
' If Not Left(Reply,2) = "00" Then
' 'If Reply = "PS: 1" Then ' when the request comes between the thermostat request and the boiler response, it receives the wrong reply and we need to look at the third message
' If Debug > 1 Then hs.WriteLog("debugOTGW2","SendMessage; Oops .... reply to PS=1 incorrect!!!")
' Reply = ReadString(Client)
' hs.WriteLog("OTGW","SendMessage; Status third line: " & Reply)
' End If
' Disconnect
Client.Close()
Catch ex As Exception
hs.WriteLog("Error","SendMessage; OTGW: " & ex.Message)
Reply = "error"
Client.Close()
End Try
Return Reply
End Function
Private Function ReadString(ByVal Client As System.Net.Sockets.TcpClient) As String
Dim Stream As NetworkStream = Client.GetStream
Dim Buffersize As Integer = Client.ReceiveBufferSize
Dim Data(Buffersize -1) As Byte
If Stream.CanTimeout Then Stream.ReadTimeout = 1000 * 10 '15
Dim BytesRead As Integer = Stream.Read(Data, 0, Buffersize)
Return Encoding.ASCII.GetString(Data, 0, BytesRead)
End Function
Private Function SendString(ByVal Stream As NetworkStream, ByVal Data As String) As Boolean
Dim Bytes As [Byte]() = Encoding.ASCII.GetBytes(Data)
If Stream.CanTimeout Then Stream.WriteTimeout = 1000 * 10 '5
Stream.Write(Bytes, 0, Bytes.Length)
Return True
End Function
Private Function CleanReply(Reply,Debug) as String
Dim xx = InStr(Reply,"Error") ' check if Reply contains and Error (start from "Error xx" direct after reply on PS=1 command)
If xx = 1
If Debug > 1 Then hs.WriteLog("debugOTGW2","CleanReply (xx = 1); Response from Serial Port: " & Reply)
Reply = Right(Reply,(Reply.Length)-9) ' in that case strip Reply
Else If xx > 1
If Debug > 1 Then hs.WriteLog("debugOTGW2","CleanReply (xx > 1); Response from Serial Port: " & Reply)
Reply = Left(Reply,xx-1) ' in that case strip Reply
End If
Return Reply
End Function
Private Function PR_UpdateDevices(RemoteIP,PortNumber,Debug)
Dim PR_command() As String = {"T","R","M","V","O","W","L"}
Dim GWValue As Double
Dim GWDevice, GWImage, GWString, message, OTReplyType As String
Dim Reply, OTReplyValue As String
For i As Byte = 0 To PR_command.GetUpperBound(0)
GWValue = 0
GWImage = "/images/HomeSeer/status/custom.gif"
message = "PR=" & PR_command(i)
Reply = SendMessage(Message,RemoteIP,PortNumber,Debug)
If Debug > 0 Then hs.WriteLog("debugOTGW1", "PR_UpdateDevices; Reply: " & Reply)
If Reply <> "error" Then
OTReplyType = Mid(Reply,5,1)
OTReplyValue = Stringitem(Reply, 2 , "=")
Select Case OTReplyType
Case "T"
'' Tweaks. Reports the state of the ignore transitions and override in high byte settings.
GWDevice = "Gateway Type"
GWString = "Normal"
If OTReplyValue = "1" Then GWString = "Celcia20"
Case "R"
'' The state of the automatic Remeha thermostat detection.
GWDevice = "Thermostat Type"
GWString = "Default"
If Left(OTReplyValue,1) = "I" Then GWString = "Remeha iSense"
If Left(OTReplyValue,1) = "C" Then GWString = "Remeha Celcia20"
If Left(OTReplyValue,1) = "R" Then GWString = "Remeha thermostat"
Case "M"
'' Gateway mode. G=Gateway, M=Monitor.
GWDevice = "Mode"
GWValue = 0
GWString = "Monitor"
If asc(OTReplyValue) = 71 Then
GWValue = 1
GWString = "Gateway"
End If
Case "V"
'' Report the reference voltage setting
GWDevice = "Voltage Reference"
GWValue = Val(OTReplyValue)
GWString = OTReplyValue & " V"
Case "O"
'' Report the setpoint override value
GWDevice = "Setpoint Override"
GWValue = 0
GWImage = "/images/OpenTherm/off.gif"
GWstring = "No"
If Left(OTReplyValue,1) <> "N"
GWValue = 1
GWImage = "/images/OpenTherm/on.gif"
GWString = "Yes: " & mid(OTReplyValue,1,5) & " °C"
Else
Dim dvRef = hs.GetDeviceRef("OT_TempDropDown")
If dvRef > 0 then
If hs.DeviceValue(dvRef) > 0 Then
hs.SetDeviceValueByRef(dvRef,0,False)
hs.SetDeviceString(dvRef,"<img src='images/Homeseer/ui/5-x-5_trans_spacer.gif'>" & _
"Thermostat Control (Set by thermostat)", False)
End If
End If
End If
Case "W"
'' Report the domestic hot water setting
GWDevice = "DHW Enabled"
GWValue = 0
GWImage = "/images/OpenTherm/off.gif"
GWstring = "Disabled"
If Left(OTReplyValue,1) = "A"
GWValue = 1
GWImage = "/images/OpenTherm/on.gif"
GWString = "Enabled"
End If
Case "L"
'' Configured functions for all 6 LEDS. The response consists of 6 letters representing the functions of LED A through LED F.
GWDevice = "LEDs"
GWValue = 1
GWString = OTReplyValue
Case Else
hs.WriteLog("OTGW", "PR_UpdateDevices; not recognized reply: " & OTReplyType)
hs.WriteLog("OTGW", "PR_UpdateDevices; Message: " & message)
hs.WriteLog("OTGW", "PR_UpdateDevices; Reply: " & Reply)
hs.WriteLog("OTGW", "PR_UpdateDevices; OTReplyType: " & OTReplyType)
hs.WriteLog("OTGW", "PR_UpdateDevices; OTReplyValue: " & OTReplyValue)
End Select
PR_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
If Debug > 0 Then hs.WriteLog("debugOTGW1","PR_UpdateDevices; Reply on PRC command: " & OTReplyType & ": " & OTReplyValue)
End If
Next
End Function
Private Function PS_UpdateDevices(Reply,Debug)
Dim GWValue as Double
Dim GWDevice, GWImage, GWString as String
Dim MyArray(), StatusArray() As String
MyArray = Split(Reply,",")
For i As Byte = 0 To MyArray.GetUpperBound(0)
GWValue = 0
GWImage = "/images/HomeSeer/status/custom.gif"
Select Case i
Case 0
'' Status (MsgID=0) - Printed as two 8-bit bitfields
GWDevice = "Status"
GWstring = MyArray(i)
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
StatusArray = Split(GWstring,"/")
'StatusArray(0) is Master Status (Thermostat)
GWValue = Val(Mid(StatusArray(0),8,1))
GWDevice = "CH Enable"
GWstring = Mid(StatusArray(0),8,1)
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
GWValue = Val(Mid(StatusArray(0),7,1))
GWDevice = "DHW Enable"
GWstring = Mid(StatusArray(0),7,1)
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
'StatusArray(1) is Slave Status (Boiler)
GWValue = Val(Mid(StatusArray(1),8,1))
GWDevice = "Fault Indication"
GWstring = Mid(StatusArray(1),8,1)
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
GWValue = Val(Mid(StatusArray(1),7,1))
GWDevice = "CH Mode"
GWstring = Mid(StatusArray(1),7,1)
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
GWValue = Val(Mid(StatusArray(1),6,1))
GWDevice = "DHW Mode"
GWstring = Mid(StatusArray(1),6,1)
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
GWValue = Val(Mid(StatusArray(1),5,1))
GWDevice = "Flame Status"
GWstring = Mid(StatusArray(1),5,1)
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
GWValue = Val(Mid(StatusArray(1),2,1))
GWDevice = "Diagnostic Indication"
GWstring = Mid(StatusArray(1),2,1)
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 1
'' Control setpoint (MsgID=1) - Printed as a floating point value
Case 2
'' Remote parameter flags (MsgID= 6) - Printed as two 8-bit bitfields ' DEZE WORDT WEL GEBRUIKT. UITCODEREN!
Case 3
'' Maximum relative modulation level (MsgID=14) - Printed as a floating point value
GWValue = Val(MyArray(i))
GWDevice = "Maximum relative modulation level"
GWstring = MyArray(i) & " %"
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 4
'' Boiler capacity and modulation limits (MsgID=15) - Printed as two bytes
Case 5
'' Room Setpoint (MsgID=16) - Printed as a floating point value
GWValue = Val(MyArray(i))
GWDevice = "Room Setpoint"
GWstring = MyArray(i) & " °C"
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 6
'' Relative modulation level (MsgID=17) - Printed as a floating point value
GWValue = Val(MyArray(i))
GWDevice = "Relative modulation level"
GWstring = MyArray(i) & " %"
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 7
'' CH water pressure (MsgID=18) - Printed as a floating point value
GWValue = Val(MyArray(i))
GWDevice = "CH water pressure"
GWstring = MyArray(i)
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 8
'' Room temperature (MsgID=24) - Printed as a floating point value
GWValue = Val(MyArray(i))
GWDevice = "Room temperature"
GWstring = MyArray(i) & " °C"
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 9
'' Boiler water temperature (MsgID=25) - Printed as a floating point value
GWValue = Val(MyArray(i))
GWDevice = "Boiler water temperature"
GWstring = MyArray(i) & " °C"
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 10
'' DHW temperature (MsgID=26) - Printed as a floating point value
GWValue = Val(MyArray(i))
GWDevice = "DHW temperature"
GWstring = MyArray(i) & " °C"
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 11
'' Outside temperature (MsgID=27) - Printed as a floating point value
GWValue = Val(MyArray(i))
GWDevice = "Outside temperature"
GWstring = MyArray(i) & " °C"
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 12
'' Return water temperature (MsgID=28) - Printed as a floating point value
GWValue = Val(MyArray(i))
GWDevice = "Return water temperature"
GWstring = MyArray(i) & " °C"
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 13
'' DHW setpoint boundaries (MsgID=48) - Printed as two bytes ' DEZE WORDT WEL GEBRUIKT. UITCODEREN!
Case 14
'' Max CH setpoint boundaries (MsgID=49) - Printed as two bytes
Case 15
'' DHW setpoint (MsgID=56) - Printed as a floating point value
GWValue = Val(MyArray(i))
GWDevice = "DHW setpoint"
GWstring = MyArray(i) & " °C"
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 16
'' Max CH water setpoint (MsgID=57) - Printed as a floating point value
GWValue = Val(MyArray(i))
GWDevice = "Max CH water setpoint"
GWstring = MyArray(i) & " °C"
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 17
'' Burner starts (MsgID=116) - Printed as a decimal value
GWValue = Val(MyArray(i))
GWDevice = "Burner starts"
GWstring = MyArray(i)
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 18
'' CH pump starts (MsgID=117) - Printed as a decimal value
GWValue = Val(MyArray(i))
GWDevice = "CH pump starts"
GWstring = MyArray(i)
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 19
'' DHW pump/valve starts (MsgID=118) - Printed as a decimal value
GWValue = Val(MyArray(i))
GWDevice = "DHW pump/valve starts"
GWstring = MyArray(i)
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 20
'' DHW burner starts (MsgID=119) - Printed as a decimal value
GWValue = Val(MyArray(i))
GWDevice = "DHW burner starts"
GWstring = MyArray(i)
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 21
'' Burner operation hours (MsgID=120) - Printed as a decimal value
GWValue = Val(MyArray(i))
GWDevice = "Burner operation hours"
GWstring = MyArray(i) & " h"
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 22
'' CH pump operation hours (MsgID=121) - Printed as a decimal value
GWValue = Val(MyArray(i))
GWDevice = "CH pump operation hours"
GWstring = MyArray(i) & " h"
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 23
'' DHW pump/valve operation hours (MsgID=122) - Printed as a decimal value
GWValue = Val(MyArray(i))
GWDevice = "DHW pump/valve operation hours"
GWstring = MyArray(i) & " h"
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
Case 24
'' DHW burner operation hours (MsgID=123) - Printed as a decimal value
GWValue = Val(MyArray(i))
GWDevice = "DHW burner operation hours"
GWstring = MyArray(i) & " h"
PS_SetDeviceValue(GWDevice, GWString, GWValue, GWImage)
End Select
Next
End Function
Private Function Stringitem(ByVal Str As String, ByVal Index As Integer, Byval Sep As String) As String
Try
Dim Result() As String = System.Text.RegularExpressions.Regex.Split(Str, System.Text.RegularExpressions.Regex.Escape(Sep))
Return Result(Index-1)
Catch
Return ""
End Try
End Function
Private Sub PR_SetDeviceValue(dev_name As String, dev_string As String, dev_value As Double, dev_image As String)
Dim dvRef
dvRef = hs.GetDeviceRef("OT_PR_" & dev_name)
if dvRef > 0 then
If Not hs.DeviceString(dvRef).Equals("<img src='" & dev_image & "'> " & dev_string) Then ' only set when DeviceString has changed
hs.SetDeviceValueByRef(dvRef, dev_value , False)
hs.SetDeviceString(dvRef, "<img src='" & dev_image & "'> " & dev_string, True)
End If
Else
Dim dv As Scheduler.Classes.DeviceClass = Nothing
dv = hs.NewDeviceEx(dev_name)
dv.Location(hs) = hs.GetINISetting("HS", "Room", "", INI_FILE)
dv.Location2(hs) = hs.GetINISetting("HS", "Floor", "", INI_FILE)
dv.Code(hs) = "OT_PR_" & dev_name
dv.MISC_Set(hs, &H10) ' status only
dv.Image(hs) = "images\OpenTherm\OT.png"
hs.SetDeviceValueByRef(dv.Ref(hs), dev_value , False)
hs.SetDeviceString(dv.Ref(hs), "<img src='" & dev_image & "'> " & dev_string, True)
If dev_name = "Gateway Type" Then
dv.Relationship(hs) = Enums.eRelationship.Parent_Root
Else
Dim rdvRef
Dim rdv As Scheduler.Classes.DeviceClass
rdvRef = hs.GetDeviceRef("OT_PR_Gateway Type")
If rdvRef > 0 then
rdv = hs.GetDeviceByRef(rdvRef)
If rdv IsNot Nothing Then
rdv.AssociatedDevice_Add(hs, dv.Ref(hs))
dv.Relationship(hs) = Enums.eRelationship.Child
End If
End If
End If
End If
End Sub
Private Sub PS_SetDeviceValue(dev_name As String, dev_string As String, dev_value as Double, dev_image As String)
Dim dvRef
dvRef = hs.GetDeviceRef("OT_PS_" & dev_name)
if dvRef > 0 then
If Not hs.DeviceString(dvRef).Equals("<img src='" & dev_image & "'> " & dev_string) Then ' only set when DeviceString has changed
hs.SetDeviceValueByRef(dvRef, dev_value , False)
hs.SetDeviceString(dvRef, "<img src='" & dev_image & "'> " & dev_string, True)
End If
Else
Dim dv As Scheduler.Classes.DeviceClass = Nothing
dv = hs.NewDeviceEx(dev_name)
dv.Location(hs) = hs.GetINISetting("HS", "Room", "", INI_FILE)
dv.Location2(hs) = hs.GetINISetting("HS", "Floor", "", INI_FILE)
dv.Code(hs) = "OT_PS_" & dev_name
dv.MISC_Set(hs, &H10) ' status only
dv.Image(hs) = "images\OpenTherm\OT.png"
hs.SetDeviceValueByRef(dv.Ref(hs), dev_value , False)
hs.SetDeviceString(dv.Ref(hs), "<img src='" & dev_image & "'> " & dev_string, True)
If dev_name = "Status" Then
dv.Relationship(hs) = Enums.eRelationship.Parent_Root
dv.MISC_Set(hs, &H20) ' hide device from view
Else
Dim rdvRef
Dim rdv As Scheduler.Classes.DeviceClass
rdvRef = hs.GetDeviceRef("OT_PS_Status")
If rdvRef > 0 then
rdv = hs.GetDeviceByRef(rdvRef)
If rdv IsNot Nothing Then
rdv.AssociatedDevice_Add(hs, dv.Ref(hs))
dv.Relationship(hs) = Enums.eRelationship.Child
End If
End If
End If
End If
End Sub
Private Sub CreateTempDropDown()
Dim dvRef
Dim dvRef2
Dim dv As Scheduler.Classes.DeviceClass = Nothing
Dim dv2 As Scheduler.Classes.DeviceClass = Nothing
Dim Pair As VSPair
dvRef = hs.GetDeviceRef("OT_TempDropDown")
if dvRef <= 0 then
Dim DT As New DeviceTypeInfo
dv = hs.NewDeviceEx("Temperature Override")
dv.Location(hs) = hs.GetINISetting("HS", "Room", "", INI_FILE)
dv.Location2(hs) = hs.GetINISetting("HS", "Floor", "", INI_FILE)
dv.Code(hs) = "OT_TempDropDown"
dv.Image(hs) = "images\OpenTherm\OT.png"
dv.Relationship(hs) = Enums.eRelationship.Parent_Root
dv.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES) 'This is &H100
dv.MISC_Clear(hs, Enums.dvMISC.STATUS_ONLY) 'This is &H10
dv.ScriptName(hs) = "BLB_OT_monitor.vb"
dv.ScriptFunc(hs) = "SetTempChanged"
DT.Device_API = DeviceTypeInfo.eDeviceAPI.Script
DT.Device_Type = DeviceTypeInfo.eDeviceType_Script.Run_On_Value_Change
dv.DeviceType_Set(hs) = DT
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Both)
Pair.PairType = VSVGPairType.SingleValue
Pair.Value = 0
Pair.Render = Enums.CAPIControlType.Values
Pair.Status = "Thermostat Control"
hs.DeviceVSP_AddPair(dv.Ref(hs), Pair)
For index As Integer = 10 To 25
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Both)
Pair.PairType = VSVGPairType.SingleValue
Pair.Value = index
Pair.Render = Enums.CAPIControlType.Values
Pair.Status = index.ToString & " " & Chr(176) & "C"
hs.DeviceVSP_AddPair(dv.Ref(hs), Pair)
Next
hs.SetDeviceValueByRef(dv.Ref(hs), 0 , False)
hs.SetDeviceString(dv.Ref(hs), "<img src='images/Homeseer/ui/5-x-5_trans_spacer.gif'>Thermostat Control", True)
End If
dvRef2 = hs.GetDeviceRef("OT_TempOverrideMode")
if dvRef2 <= 0 then
Dim DT As New DeviceTypeInfo
dv2 = hs.NewDeviceEx("Temperature Override Mode")
dv2.Location(hs) = hs.GetINISetting("HS", "Room", "", INI_FILE)
dv2.Location2(hs) = hs.GetINISetting("HS", "Floor", "", INI_FILE)
dv2.Code(hs) = "OT_TempOverrideMode"
dv2.Image(hs) = "images\OpenTherm\OT.png"
dv.AssociatedDevice_Add(hs, dv2.Ref(hs))
dv2.Relationship(hs) = Enums.eRelationship.Child
dv2.MISC_Set(hs, Enums.dvMISC.SHOW_VALUES) 'This is &H100
dv2.MISC_Clear(hs, Enums.dvMISC.STATUS_ONLY) 'This is &H10
dv2.ScriptName(hs) = "BLB_OT_monitor.vb"
dv2.ScriptFunc(hs) = "SetTempOverrideMode"
DT.Device_API = DeviceTypeInfo.eDeviceAPI.Script
DT.Device_Type = DeviceTypeInfo.eDeviceType_Script.Run_On_Value_Change
dv2.DeviceType_Set(hs) = DT
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Both)
Pair.PairType = VSVGPairType.SingleValue
Pair.Value = 0
Pair.Render = Enums.CAPIControlType.Values
Pair.Status = "Temporary"
hs.DeviceVSP_AddPair(dv2.Ref(hs), Pair)
Pair = New VSPair(HomeSeerAPI.ePairStatusControl.Both)
Pair.PairType = VSVGPairType.SingleValue
Pair.Value = 1
Pair.Render = Enums.CAPIControlType.Values
Pair.Status = "Constant"
hs.DeviceVSP_AddPair(dv2.Ref(hs), Pair)
hs.SetDeviceValueByRef(dv2.Ref(hs), 0 , False)
hs.SetDeviceString(dv2.Ref(hs), "<img src='images/Homeseer/ui/5-x-5_trans_spacer.gif'>Temporary", True)
End If
End Sub
Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
I run the script in a recurring event every 30 seconds with calling of Sub "Main" and parameter "update".