diff --git a/fhem/CHANGED b/fhem/CHANGED index 954dea97e..a7893d3ed 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -519,3 +519,4 @@ - bugfix: Avoid unitialized in xmllist for corrupt readings (reporter: Boris) - bugfix: Add binmode to 01_fhemweb.pm for windows - bugfix: Uniform check for windows, enable CUL for windows. + - bugfix: CUL/HMS parsing patches from Peter diff --git a/fhem/FHEM/15_CUL_EM.pm b/fhem/FHEM/15_CUL_EM.pm index 2d87e9cf5..3e602a61e 100755 --- a/fhem/FHEM/15_CUL_EM.pm +++ b/fhem/FHEM/15_CUL_EM.pm @@ -6,6 +6,9 @@ use warnings; my %defptr; +# Adjust TOTAL to you meter: +# {$defs{emwz}{READINGS}{basis}{VAL}=/- } + ##################################### sub CUL_EM_Initialize($) @@ -38,9 +41,9 @@ CUL_EM_Define($$) if($a[2] >= 1 && $a[2] <= 4) { # EMWZ: nRotation in 5 minutes my $c = (int(@a) > 3 ? $a[3] : 150); - $hash->{corr1} = (12/$c); - $c = (int(@a) > 4 ? $a[4] : 150); - $hash->{corr2} = (12/$c); + $hash->{corr1} = (12/$c); # peak/current + $c = (int(@a) > 4 ? $a[4] : 1800); + $hash->{corr2} = (12/$c); # total } elsif($a[2] >= 5 && $a[2] <= 8) { # EMEM # corr1 is the correction factor for power @@ -120,27 +123,22 @@ CUL_EM_Parse($$) # calculate readings # # initialize total_cnt_last - my $total_cnt_last; + my $total_cnt_last = 0; if(defined($hash->{READINGS}{total_cnt})) { - $total_cnt_last= $hash->{READINGS}{total_cnt}{VAL}; - } else { - $total_cnt_last= 0; + $total_cnt_last= $hash->{READINGS}{total_cnt}{VAL}; } # initialize basis_cnt_last - my $basis_cnt_last; + my $basis_cnt = 0; if(defined($hash->{READINGS}{basis})) { - $basis_cnt_last= $hash->{READINGS}{basis}{VAL}; - } else { - $basis_cnt_last= 0; + $basis_cnt = $hash->{READINGS}{basis}{VAL}; } # correct counter wraparound - my $basis_cnt= $basis_cnt_last; if($total_cnt< $total_cnt_last) { - $basis_cnt += 65536; - $readings{basis} = $basis_cnt; + $basis_cnt += 65536; + $readings{basis} = $basis_cnt; } # @@ -171,42 +169,55 @@ CUL_EM_Parse($$) # Start CUMULATE day and month Log GetLogLevel($n,4), "CUL_EM $n: $val"; my $tsecs_prev; + #----- get previous tsecs if(defined($hash->{READINGS}{tsecs})) { $tsecs_prev= $hash->{READINGS}{tsecs}{VAL}; } else { $tsecs_prev= 0; # 1970-01-01 } + #----- save actual tsecs my $tsecs= time(); # number of non-leap seconds since January 1, 1970, UTC $readings{tsecs} = $tsecs; + #----- get cost parameter my $cost = $hash->{CostPerUnit}; my $basicfee = $hash->{BasicFeePerMonth}; + #----- check whether day or month was changed if(!defined($hash->{READINGS}{cum_day})) { #----- init cum_day if it is not set $val = sprintf("CUM_DAY: %0.3f CUM: %0.3f COST: %0.2f", 0,$total,0); $readings{cum_day} = $val; + } else { + if( (localtime($tsecs_prev))[3] != (localtime($tsecs))[3] ) { #----- day has changed (#3) my @cmv = split(" ", $hash->{READINGS}{cum_day}{VAL}); - $val = sprintf("CUM_DAY: %0.3f CUM: %0.3f COST: %0.2f", $total-$cmv[3], $total, ($total-$cmv[3])*$cost); + $val = sprintf("CUM_DAY: %0.3f CUM: %0.3f COST: %0.2f", + $total-$cmv[3], $total, ($total-$cmv[3])*$cost); $readings{cum_day} = $val; Log GetLogLevel($n,3), "CUL_EM $n: $val"; - # + + if( (localtime($tsecs_prev))[4] != (localtime($tsecs))[4] ) { + #----- month has changed (#4) if(!defined($hash->{READINGS}{cum_month})) { # init cum_month if not set - $val = sprintf("CUM_MONTH: %0.3f CUM: %0.3f COST: %0.2f", 0,$total,0); + $val = sprintf("CUM_MONTH: %0.3f CUM: %0.3f COST: %0.2f", + 0, $total, 0); $readings{cum_month} = $val; + } else { @cmv = split(" ", $hash->{READINGS}{cum_month}{VAL}); - $val = sprintf("CUM_MONTH: %0.3f CUM: %0.3f COST: %0.2f", $total-$cmv[3],$total,($total-$cmv[3])*$cost+$basicfee); + $val = sprintf("CUM_MONTH: %0.3f CUM: %0.3f COST: %0.2f", + $total-$cmv[3], $total,($total-$cmv[3])*$cost+$basicfee); $readings{cum_month} = $val; Log GetLogLevel($n,3), "CUL_EM $n: $val"; + } } } diff --git a/fhem/docs/commandref.html b/fhem/docs/commandref.html index 883bd5bcf..f2910708b 100644 --- a/fhem/docs/commandref.html +++ b/fhem/docs/commandref.html @@ -1666,20 +1666,47 @@ A line ending with \ will be concatenated with the next one, so long lines from EMEM, EMWZ or EMGZ devices.

- + Define
    - define <name> CUL_EM <code> [corr]
    + define <name> CUL_EM <code> [corr1 corr2 + CostPerUnit BasicFeePerMonth]

    <code> is the code which must be set on the EM device. Valid values - are 1 through 12. 1-4 denotes EMWZ, 5-8 EMEM and 9-12 EMGZ devices.
    - corr (if specified) will be multiplied to the value delivered in the - message.
    + are 1 through 12. 1-4 denotes EMWZ, 5-8 EMEM and 9-12 EMGZ devices.

    + + corr1 is used to correct the current number, corr2 + for the total number.
    • for EMWZ devices you should specify the rotation speed (R/kW) - of your watt-meter (e.g. 150)
    • -
    • for EMEM devices the correct value is 0.01.
    • + of your watt-meter (e.g. 150) for corr1 and 12 times this value for + corr2 +
    • for EMEM devices the corr1 value is 0.01, and the corr2 value is + 0.001
    +
    + + CostPerUnit and BasicFeePerMonth are used to compute your + daily and mothly fees. Your COST will appear in the log, generated once + daiy (without the basic fee) or month (with the bassic fee included). Your + definition should look like E.g.: +
    +    define emwz 1 75 900 0.15 12.50
    + and the Log looks like: +
    +    CUM_DAY: 6.849 CUM: 60123.4 COST: 1.02
    +    CUM_MONTH: 212.319 CUM: 60123.4 COST: 44.34
    + + Tipp: You can configure your EMWZ device to show in the CUM column of the + STATE reading the current reading of your meter. For this purpose: multiply + the current reading (from the real device) with the corr1 value (RperKW), + and substract the RAW CUM value from it. Now set the basis reading of your + EMWZ device (named emwz) to this value:
    + +
    +    { $defs{emwz}{READINGS}{basis}{VAL} = <computedvalue> }
    + +