Kaifa Smartmeter

Forum over Homeseer scripts (DUTCH forum)

Moderators: TANE, Ruud

Post Reply
Romac
Starting Member
Starting Member
Posts: 47
Joined: Tue May 11, 2010 9:45 pm
Location: Utrecht, Netherlands

Kaifa Smartmeter

Post by Romac »

Recently a smart meter has been installed in my house. It is a Kaifa MA105. I'm able to read the P1 port with Putty with the following settings: 115200,8,N,1. The output looks like this:

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
Now I'm trying to get this data into Homeseer through the following script:

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
When starting Homeseer the following messages apear in the log file (see attached screen dump)

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?
Attachments
2014-02-08 08.17.39 am.png
2014-02-08 08.17.39 am.png (17.56 KiB) Viewed 8704 times
HS3, Z-Wave Network, CommandFusion GUI
Romac
Starting Member
Starting Member
Posts: 47
Joined: Tue May 11, 2010 9:45 pm
Location: Utrecht, Netherlands

Re: Kaifa Smartmeter

Post by Romac »

Anybody an idea?

I tried an nearly empty script with just a few lines to write the data that has been read to the log file of Homeseer. The results is exactly the same. Only the first line of the data arrives followed by the warning message.
HS3, Z-Wave Network, CommandFusion GUI
Romac
Starting Member
Starting Member
Posts: 47
Joined: Tue May 11, 2010 9:45 pm
Location: Utrecht, Netherlands

Re: Kaifa Smartmeter

Post by Romac »

The script seems to error on the second line of data received. This line holds just and CRLF. How can I modify the script to stop the error from halting the script?

Code: Select all

/KFM5KAIFA-METER<CR><LF> [len=16]
<CR><LF>[len=0]
1-3:0.2.8(40)<CR><LF> [len=13]
0-0:1.0.0(140215110435W)<CR><LF> [len=24]
0-0:96.1.1(4530303039313030303031363435353133)<CR><LF> [len=46]
1-0:1.8.1(000103.745*kWh)<CR><LF> [len=25]
1-0:1.8.2(000081.165*kWh)<CR><LF> [len=25]
1-0:2.8.1(000000.000*kWh)<CR><LF> [len=25]
1-0:2.8.2(000000.000*kWh)<CR><LF> [len=25]
0-0:96.14.0(0001)<CR><LF> [len=17]
1-0:1.7.0(00.525*kW)<CR><LF> [len=20]
1-0:2.7.0(00.000*kW)<CR><LF> [len=20]
0-0:17.0.0(999.9*kW)<CR><LF> [len=20]
0-0:96.3.10(1)<CR><LF> [len=14]
0-0:96.7.21(00007)<CR><LF> [len=18]
0-0:96.7.9(00005)<CR><LF> [len=17]
1-0:99.97.0(1)(0-0:96.7.19)(000101000001W)(2147483647*s)<CR><LF> [len=56]
1-0:32.32.0(00000)<CR><LF> [len=18]
1-0:32.36.0(00000)<CR><LF> [len=18]
0-0:96.13.1()<CR><LF> [len=13]
0-0:96.13.0()<CR><LF> [len=13]
1-0:31.7.0(002*A)<CR><LF> [len=17]
1-0:21.7.0(00.525*kW)<CR><LF> [len=21]
1-0:22.7.0(00.000*kW)<CR><LF> [len=21]
0-1:24.1.0(003)<CR><LF> [len=15]
0-1:96.1.0(4730303136353631323034323832383133)<CR><LF> [len=46]
0-1:24.2.1(140215110000W)(00081.926*m3)<CR><LF> [len=39]
0-1:24.4.0(1)<CR><LF> [len=13]
!4F9B<CR><LF> [len=5]
HS3, Z-Wave Network, CommandFusion GUI
Bwired
Administrator
Administrator
Posts: 4704
Joined: Sat Mar 25, 2006 1:07 am
Location: Netherlands
Contact:

Re: Kaifa Smartmeter

Post by Bwired »

im not sure what you are doing, cant check it ...No Homeseer here
But you shoulc split the telegram on <CR><LF>, then just pick the values out of the lines you need
Romac
Starting Member
Starting Member
Posts: 47
Joined: Tue May 11, 2010 9:45 pm
Location: Utrecht, Netherlands

Re: Kaifa Smartmeter

Post by Romac »

Bwired wrote:im not sure what you are doing, cant check it ...No Homeseer here
But you shoulc split the telegram on <CR><LF>, then just pick the values out of the lines you need
This what I'm trying to do, but for some reason this is not working. There is a thread on the HomeSeer forum, but no solution yet.

http://board.homeseer.com/showthread.php?t=166033
HS3, Z-Wave Network, CommandFusion GUI
Post Reply

Return to “Homeseer Scripts Forum”