From 36e9002b14c5b8e9c9ddd69595d6778f520489f2 Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Mon, 3 Oct 2016 14:01:05 +0000 Subject: [PATCH] 15_CUL_EM.pm: try a workaround for CUL_EM power shortage (Forum #55626) git-svn-id: https://svn.fhem.de/fhem/trunk@12259 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/15_CUL_EM.pm | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/fhem/FHEM/15_CUL_EM.pm b/fhem/FHEM/15_CUL_EM.pm index afa707acf..6f652af6a 100755 --- a/fhem/FHEM/15_CUL_EM.pm +++ b/fhem/FHEM/15_CUL_EM.pm @@ -98,7 +98,7 @@ CUL_EM_Parse($$) # basis_cnt= correction to total (cumulated) value in ticks to account for # counter wraparounds # total = total (cumulated) value in device units - # current_cnt = current value (average over latest 5 minutes) in device units + # current_cnt = current value (average over latest 5 minutes) in device units # peak = maximum value in device units my $seqno = hex($a[5].$a[6]); @@ -132,19 +132,23 @@ CUL_EM_Parse($$) $total_cnt_last= $hash->{READINGS}{total_cnt}{VAL}; } - - # initialize basis_cnt_last - my $basis_cnt = 0; - if(defined($hash->{READINGS}{basis})) { - $basis_cnt = $hash->{READINGS}{basis}{VAL}; - } - - # # translate into device units # my $corr1 = $hash->{corr1}; # EMEM power correction factor my $corr2 = $hash->{corr2}; # EMEM energy correction factor + my $counter_offset = AttrVal($n,"CounterOffset",0); + my $oldraw = ReadingsVal($n, "RAW", ""); # Forum #55626 + my $basis_cnt = ReadingsVal($n, "basis", 0); + if($oldraw) { + my @a = split(" ", $oldraw); + if($a[3] > $total_cnt) { + $basis_cnt += ($a[3]+$total_cnt)/$corr2; + readingsSingleUpdate($hash, "basis", $basis_cnt, 0); + Log 1, "$n was reset, old CUM $a[3], new CUM: $total_cnt, ". + "new basis $basis_cnt"; + } + } my $peak; @@ -177,7 +181,6 @@ CUL_EM_Parse($$) $basis_cnt += ($total_cnt_last > 65000 ? 65536 : $total_cnt_last); $readings{basis} = $basis_cnt; } - my $counter_offset = AttrVal($n,"CounterOffset",0); my $total = (($basis_cnt+$total_cnt)*$corr2)+$counter_offset; my $current = $current_cnt*$corr1;