Code: Select all
/KFM5KAIFA-METER
1-3:0.2.8(40)
0-0:1.0.0(140207214844W)
0-0:96.1.1(4530303039313030303031363435353133)
1-0:1.8.1(000029.567*kWh)
1-0:1.8.2(000025.374*kWh)
1-0:2.8.1(000000.000*kWh)
1-0:2.8.2(000000.000*kWh)
0-0:96.14.0(0002)
1-0:1.7.0(01.645*kW)
1-0:2.7.0(00.000*kW)
0-0:17.0.0(999.9*kW)
0-0:96.3.10(1)
0-0:96.7.21(00007)
0-0:96.7.9(00005)
1-0:99.97.0(1)(0-0:96.7.19)(000101000001W)(2147483647*s)
1-0:32.32.0(00000)
1-0:32.36.0(00000)
0-0:96.13.1()
0-0:96.13.0()
1-0:31.7.0(007*A)
1-0:21.7.0(01.651*kW)
1-0:22.7.0(00.000*kW)
0-1:24.1.0(003)
0-1:96.1.0(4730303136353631323034323832383133)
0-1:24.2.1(140207210000W)(00026.831*m3)
0-1:24.4.0(1)
!D6BF
Code: Select all
' place in Homeseer Startup.txt and replace X with com-port #
' hs.closecomport X
' e=hs.OpenComPort(X,"115200,N,8,1",1,"P1.vb","P1_event", "!")
' if e <> "" then
' hs.writelog "P1", "Setup error " & e
' else
' hs.writelog "P1", "Setup complete"
' end if
' Place the following in the Shutdown script
' e=hs.CloseComPort("X")
' if e<> "" then
' hs.writelog "Error closing COM1",e
' else
' hs.writelog "COM1", "Port was closed"
' end if
'Create these virtual devices in Homeseer
Const CURRENT_POWER_USAGE = "E1"
Const TOTAL_POWER_USAGE_T1 = "E2"
Const TOTAL_POWER_USAGE_T2 = "E3"
Const TARIFF_INDICATOR = "E4"
Const TOTAL_GAS_USAGE = "E5"
Const GAS_USAGE_UPDATE = "E6"
Dim v1, v2, device_value, device_string, y, m, d, h
Const DEBUG_LOG = True 'set to False when running without error
Sub P1_event(data)
If DEBUG_LOG Then
hs.writelog("P1", "Data: " & CStr(data))
End If
' Current Power Use
' 1-0:1.7.0(0001.05*kW)
If left(data, 10) = "1-0:1.7.0(" Then
v1 = Split(data, "(")
v2 = Split(v1(1), "*")
device_value = CDbl(replace(v2(0), ".", ",")) * 1000
'device_string = device_value&"W"
If DEBUG_LOG Then
hs.writelog("P1", "Current Power Use: " & CStr(device_value) & " Watt")
End If
hs.SetDeviceString(CURRENT_POWER_USAGE, device_string)
hs.SetDeviceValue(CURRENT_POWER_USAGE, device_value)
hs.setDeviceLastChange("E1", now)
'Total Use Tarif 1:
'1-0:1.8.1(00287.000*kWh)
ElseIf left(data, 10) = "1-0:1.8.1(" Then
v1 = Split(data, "(")
v2 = Split(v1(1), "*")
device_value = CDbl(replace(v2(0), ".", ","))
device_string = device_value & "kWh"
If DEBUG_LOG Then
hs.writelog("P1", "Total Usage Tarif 1: " & CStr(device_value) & " Wh")
End If
hs.SetDeviceString(TOTAL_POWER_USAGE_T1, device_string)
hs.SetDeviceValue(TOTAL_POWER_USAGE_T1, device_value)
'Total Use Tarif2:
'1-0:1.8.2(00187.000*kWh)
ElseIf left(data, 10) = "1-0:1.8.2(" Then
v1 = Split(data, "(")
v2 = Split(v1(1), "*")
device_value = CDbl(replace(v2(0), ".", ","))
device_string = device_value & "kWh"
If DEBUG_LOG Then
hs.writelog("P1", "Total Usage Tarif 2: " & CStr(device_value) & " Wh")
End If
hs.SetDeviceString(TOTAL_POWER_USAGE_T2, device_string)
hs.SetDeviceValue(TOTAL_POWER_USAGE_T2, device_value)
' Tarif Indicator
' 0-0:96.14.0(0002)
ElseIf left(data, 12) = "0-0:96.14.0(" Then
v1 = Split(data, "(")
v2 = Split(v1(1), ")")
device_value = CInt(v2(0))
device_string = "Tarif " & device_value
If DEBUG_LOG Then
hs.writelog("P1", "Tarif: " & device_string)
End If
hs.SetDeviceString(TARIFF_INDICATOR, device_string)
hs.SetDeviceValue(TARIFF_INDICATOR, device_value)
' Total Gas Usage
' (00518.216)
ElseIf left(data, 1) = "(" Then
v1 = Split(data, "(")
v2 = Split(v1(1), ")")
device_value = CDbl(replace(v2(0), ".", ","))
device_string = device_value & "M3"
If DEBUG_LOG Then
hs.writelog("P1", "Total Gas Usage: " & device_string)
End If
hs.SetDeviceString(TOTAL_GAS_USAGE, device_string)
hs.SetDeviceValue(TOTAL_GAS_USAGE, device_value)
' Timestamp Last Total Gas Usage
' Data:0-1:24.3.0(130104130000)(00)(60)(1)(0-1:24.2.1)(m3)
ElseIf left(data, 11) = "0-1:24.3.0(" Then
v1 = Split(data, "(")
v2 = Split(v1(1), ")")
y = left(v2(0), 2)
m = right(left(v2(0), 4), 2)
d = right(left(v2(0), 6), 2)
h = CInt(left(right(v2(0), 6), 2))
device_value = h
device_string = d & "-" & m & "-" & y & " " & h & "h"
If DEBUG_LOG Then
hs.writelog("P1", "Timestamp Last Gas Total Update: " & device_string)
End If
hs.SetDeviceString(GAS_USAGE_UPDATE, device_string)
hs.SetDeviceValue(GAS_USAGE_UPDATE, device_value)
End If
End Sub
To me it looks like the script is running and the first line of the data comes in. The next line however is an empty line. Looks like this where the script generates the error.
Is this assumption correct and how can I resolve this?