Recently a smart electricity meter is installed in my house. This meter is connected to my HomeSeer pc through serial to USB. I can read the data coming in with Putty.
The data looks like this. Every 10 sec this data is updated.
I trying to make this data available in Homeseer. The script runs fine until after the first line is read. Then I get the following error in the log: Length cannot be less then zero (see attached). The script I use is:
Can somebody point me in the right direction on how to solve this or where to start looking for an answer?
The data looks like this. Every 10 sec this data is updated.
Code:
/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:
' 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) End If End Sub
Comment