diff --git a/fhem/FHEM/98_DOIF.pm b/fhem/FHEM/98_DOIF.pm
index 05f8a4a6b..b78d433db 100644
--- a/fhem/FHEM/98_DOIF.pm
+++ b/fhem/FHEM/98_DOIF.pm
@@ -1549,11 +1549,15 @@ sub setValue_collect
readingsSingleUpdate ($hash, "error", "${$collect}{output}, ".$@,1);
}
}
- return if (!defined $r);
my ($seconds, $microseconds) = gettimeofday();
- $r = ($r =~ /(-?\d+(\.\d+)?)/ ? $1 : "N/A");
+ if (defined $r) {
+ $r = ($r =~ /(-?\d+(\.\d+)?)/ ? $1 : "N/A");
+ } else {
+ $r="N/A";
+ }
+
${$collect}{value}=$r;
${$collect}{time}=$seconds;
@@ -1564,48 +1568,56 @@ sub setValue_collect
my $va=${$collect}{values};
my $ta=${$collect}{times};
- if ($r ne "N/A") {
- my $seconds_per_slot=$hours*3600/$dim;
-
- # if (@{$ta} == $dim) {
- if (defined ${$va}[$dim-1]) {
- $last_slot=int (${$ta}[-1]/$seconds_per_slot);
- }
- my $slot_nr=int ($seconds/$seconds_per_slot);
- if (defined $last_slot) {
- $diff_slots=$slot_nr-$last_slot;
- if ($diff_slots > 0) {
- if ($diff_slots >= $dim) {
- ${$collect}{last_value}=${$collect}{value} if (defined ${$collect}{value});
- @{$va}=();
- @{$ta}=();
- ${$collect}{last}=undef;
- } else {
- my @rv=splice (@{$va},0,$diff_slots);
- my @rt=splice (@{$ta},0,$diff_slots);
- if ($diff_slots > 1 and !defined ${$va}[$dim-$diff_slots] and defined ${$collect}{last} and ${$va}[$dim-$diff_slots-1] != ${$collect}{last}) {
- ${$va}[$dim-$diff_slots]=${$collect}{last};
- ${$ta}[$dim-$diff_slots]=(int(${$ta}[$dim-$diff_slots-1]/$seconds_per_slot)+1)*$seconds_per_slot;
- }
- ${$collect}{last}=undef;
- for (my $i=@rv-1;$i>=0;$i--) {
- if (defined ($rv[$i])) {
- ${$collect}{last_value}=$rv[$i];
- last;
- }
- }
+
+ my $seconds_per_slot=$hours*3600/$dim;
+
+ # if (@{$ta} == $dim) {
+ #if (defined ${$va}[$dim-1]) {
+ # $last_slot=int (${$ta}[-1]/$seconds_per_slot);
+ #}
+ my $slot_nr=int ($seconds/$seconds_per_slot);
+
+ if (!defined ${$collect}{last_slot}) {
+ $last_slot=$slot_nr-1;
+ } else {
+ $last_slot=${$collect}{last_slot};
+ }
+
+ $diff_slots=$slot_nr-$last_slot;
+ if ($diff_slots > 0) {
+ $change=1;
+ if ($diff_slots >= $dim) {
+ ${$collect}{last_value}=${$collect}{value} if (defined ${$collect}{value});
+ @{$va}=();
+ @{$ta}=();
+ ${$collect}{last}=undef;
+ } else {
+ my @rv=splice (@{$va},0,$diff_slots);
+ my @rt=splice (@{$ta},0,$diff_slots);
+ if ($diff_slots > 1 and !defined ${$va}[$dim-$diff_slots] and defined ${$collect}{last} and ${$va}[$dim-$diff_slots-1] != ${$collect}{last}) {
+ ${$va}[$dim-$diff_slots]=${$collect}{last};
+ ${$ta}[$dim-$diff_slots]=(int(${$ta}[$dim-$diff_slots-1]/$seconds_per_slot)+1)*$seconds_per_slot;
+ }
+ ${$collect}{last}=undef;
+ for (my $i=@rv-1;$i>=0;$i--) {
+ if (defined ($rv[$i])) {
+ ${$collect}{last_value}=$rv[$i];
+ last;
}
}
}
+ }
+ if ($r ne "N/A") {
if (!defined ${$va}[$dim-1] or !defined ${$collect}{last_v} or (abs($r-${$collect}{last_v}) > abs(${$va}[$dim-1]-${$collect}{last_v}))) {
${$va}[$dim-1]=$r;
${$ta}[$dim-1]=$seconds;
- $change=1;
} elsif (${$va}[$dim-1] != $r) {
${$collect}{last}=$r;
}
}
+ ${$collect}{last_slot}=$slot_nr;
+
if (defined $change) {
DOIF_statistic_col ($collect)
}
@@ -1648,15 +1660,22 @@ sub DOIF_statistic_col
last;
}
}
-
- ${$collect}{max_value}=$maxVal;
- ${$collect}{max_value_time}=$maxValTime;
- ${$collect}{max_value_slot}=$maxValSlot;
-
- ${$collect}{min_value}=$minVal;
- ${$collect}{min_value_time}=$minValTime;
- ${$collect}{min_value_slot}=$minValSlot;
+ delete ${$collect}{max_value};
+ delete ${$collect}{max_value_time};
+ delete ${$collect}{max_value_slot};
+ delete ${$collect}{min_value};
+ delete ${$collect}{min_value_time};
+ delete ${$collect}{min_value_slot};
+ if (defined $maxVal) {
+ ${$collect}{max_value}=$maxVal;
+ ${$collect}{max_value_time}=$maxValTime;
+ ${$collect}{max_value_slot}=$maxValSlot;
+
+ ${$collect}{min_value}=$minVal;
+ ${$collect}{min_value_time}=$minValTime;
+ ${$collect}{min_value_slot}=$minValSlot;
+ }
if (defined ${$collect}{last_value}) {
if (${$collect}{last_value} > $maxVal) {
${$collect}{last_value}=$maxVal;
@@ -1714,6 +1733,13 @@ sub DOIF_statistic_bar
}
}
}
+
+ delete ${$bar}{max_value};
+ delete ${$bar}{max_value_slot};
+ delete ${$bar}{min_value};
+ delete ${$bar}{min_value_slot};
+ delete ${$bar}{average_value};
+
if ($numb > 0) {
${$bar}{max_value}=$maxVal;
${$bar}{max_value_slot}=$maxValSlot;
@@ -1828,15 +1854,16 @@ sub setValue_bar
readingsSingleUpdate ($hash, "error", "${$bar}{output}, ".$@,1);
}
}
- return if (!defined $r);
my ($seconds, $microseconds) = gettimeofday();
-
- $r = ($r =~ /(-?\d+(\.\d+)?)/ ? $1 : "N/A");
- ${$bar}{value}=$r;
-
my ($period1,$period2,$begin_period2)=DOIF_setPeriod($seconds,$period);
+ if (defined $r) {
+ $r = ($r =~ /(-?\d+(\.\d+)?)/ ? $1 : "N/A");
+ } else {
+ $r="N/A";
+ }
+
if (defined $trigger) {
if ($r ne "N/A") {
# if (${$bar}{counter}) {
@@ -1851,6 +1878,8 @@ sub setValue_bar
# }
}
}
+
+
my $va=${$bar}{values};
my $change="";
@@ -1867,8 +1896,15 @@ sub setValue_bar
}
$change=1;
}
+
+ ${$bar}{last_period2}=$period2;
+ ${$bar}{last_period1}=$period1;
+ ${$bar}{begin_period2}=$begin_period2;
+
+
- if (defined $trigger) {
+ ${$bar}{value}=$r;
+ if (defined $trigger and $r ne "N/A") {
if ($timeOffset == 0) {
${$va}[$period1]=${$bar}{value};
} else {
@@ -1877,10 +1913,6 @@ sub setValue_bar
$change=1;
}
- ${$bar}{last_period2}=$period2;
- ${$bar}{last_period1}=$period1;
- ${$bar}{begin_period2}=$begin_period2;
-
if ($change or defined $statistic) {
DOIF_statistic_bar ($bar)
}
@@ -5001,7 +5033,7 @@ sub format_value {
my ($val,$min,$dec)=@_;
my $format;
my $value=$val;
- if (!defined $val or $val eq "") {
+ if (!defined $val or $val eq "" or $val eq "N/A") {
$val="N/A";
$format='%s';
$value=$min;
@@ -5109,6 +5141,8 @@ sub plot {
}
my ($format,$value);
($format,$value,$val)=format_value($val,$min,$dec);
+
+ my $decform='%1.'.$dec.'f';
$minVal=$value if (!defined $minVal);
$maxVal=$value if (!defined $maxVal);
@@ -5210,7 +5244,7 @@ sub plot {
for (my $i=0;$i<=5;$i++) {
my $v=($maxPlot-$minPlot)*(1-$i*0.2)+$minPlot;
my ($color)= get_color($v,$min,$max,$minColor,$maxColor,$func);
- $out.= sprintf('%s',$anchor,$pos,$i*10+2,$noColor eq "1" ? "#CCCCCC":color($color,$lmm),"",sprintf($format,$v));
+ $out.= sprintf('%s',$anchor,$pos,$i*10+2,$noColor eq "1" ? "#CCCCCC":color($color,$lmm),"",sprintf($decform,$v));
}
}
@@ -5295,11 +5329,11 @@ sub plot {
$footer.= sprintf('%s',$footerPos,defined $unitColor ? $unitColor : "#CCCCCC", $unit);
if (defined $maxValSlot) {
$footer.= sprintf('Ø',$footerPos,defined $unitColor ? $unitColor : "#CCCCCC");
- $footer.= sprintf('%s',$bwidth/2-15,$footerPos,color($averageValColor,$lmm),"",sprintf($format,$averageVal));
+ $footer.= sprintf('%s',$bwidth/2-15,$footerPos,color($averageValColor,$lmm),"",sprintf($decform,$averageVal));
$footer.= sprintf('▲%s',$bwidth/2-15,$footerPos,defined $unitColor ? $unitColor : "#CCCCCC", $maxValTime) ;
- $footer.= sprintf('%s',$bwidth/2+42.5,$footerPos,color($maxValColor,$lmm),"",sprintf($format,${$collect}{max_value}));
+ $footer.= sprintf('%s',$bwidth/2+42.5,$footerPos,color($maxValColor,$lmm),"",sprintf($decform,${$collect}{max_value}));
$footer.= sprintf('▼%s',$bwidth/2+42.5,$footerPos,defined $unitColor ? $unitColor : "#CCCCCC", $minValTime);
- $footer.= sprintf('%s', $bwidth+8,$footerPos,color($minValColor,$lmm),"",sprintf($format,${$collect}{min_value}));
+ $footer.= sprintf('%s', $bwidth+8,$footerPos,color($minValColor,$lmm),"",sprintf($decform,${$collect}{min_value}));
}
}
} else { # col
@@ -5348,26 +5382,25 @@ sub plot {
}
$out.=sprintf('',$yNull,$chart_dim,$yNull);
- ##$out.=sprintf('',$maxValSlot*$x_prop,(50-int((${$a}[$maxValSlot]*$m+$n)*10)/10),defined $unitColor ? $unitColor:color($maxValColor,$ln)) if (defined $maxValSlot);
- my ($x1,$y1)=($maxValSlot*$x_prop,(50-int((${$a}[$maxValSlot]*$m+$n)*10)/10)-2.3);
- $out.=sprintf('',$x1,$y1,$x1+2.4,$y1+4.3,$x1-2.4,$y1+4.3, defined $unitColor ? $unitColor:color($maxValColor,$ln)) if (defined $maxValSlot);
-
- ##$out.=sprintf(',',$minValSlot*$x_prop,(50-int((${$a}[$minValSlot]*$m+$n)*10)/10),defined $unitColor ? $unitColor:color($minValColor,$ln)) if (defined $minValSlot);
- ($x1,$y1)=($minValSlot*$x_prop,(50-int((${$a}[$minValSlot]*$m+$n)*10)/10)+2.3);
- $out.=sprintf('',$x1,$y1,$x1+2.4,$y1-4.3,$x1-2.4,$y1-4.3, defined $unitColor ? $unitColor:color($minValColor,$ln)) if (defined $minValSlot);
+ if (defined $maxValSlot) {
+ my ($x1,$y1)=($maxValSlot*$x_prop,(50-int((${$a}[$maxValSlot]*$m+$n)*10)/10)-2.3);
+ $out.=sprintf('',$x1,$y1,$x1+2.4,$y1+4.3,$x1-2.4,$y1+4.3, defined $unitColor ? $unitColor:color($maxValColor,$ln));
+ ($x1,$y1)=($minValSlot*$x_prop,(50-int((${$a}[$minValSlot]*$m+$n)*10)/10)+2.3);
+ $out.=sprintf('',$x1,$y1,$x1+2.4,$y1-4.3,$x1-2.4,$y1-4.3, defined $unitColor ? $unitColor:color($minValColor,$ln));
+ }
$out.=sprintf((''.$animate),$chart_dim,(50-int(($value*$m+$n)*10)/10),defined $unitColor ? $unitColor:color($currColor,$ln)) if ($val ne "N/A");
if ($footerPos) {
+ $footer.= sprintf('%s',$footerPos,defined $unitColor ? $unitColor : "#CCCCCC", $unit);
if (defined $maxValTime) {
- $footer.= sprintf('%s',$footerPos,defined $unitColor ? $unitColor : "#CCCCCC", $unit);
if ($hours > 168) {
$footer.= sprintf('▲%s',$footerPos,defined $unitColor ? $unitColor : "#CCCCCC", ::strftime("%d.%m %H:%M",localtime($maxValTime)));
} else {
$footer.= sprintf('▲%s',$footerPos,defined $unitColor ? $unitColor : "#CCCCCC", ::strftime("%a",localtime($maxValTime)));
$footer.= sprintf('%s',$footerPos,::strftime("%H:%M",localtime($maxValTime)));
}
- $footer.= sprintf('%s',$bwidth/2+25.5,$footerPos,color($maxValColor,$lmm),"",sprintf($format,${$collect}{max_value}));
+ $footer.= sprintf('%s',$bwidth/2+25.5,$footerPos,color($maxValColor,$lmm),"",sprintf($decform,${$collect}{max_value}));
}
if (defined $minValTime) {
if ($hours > 168) {
@@ -5377,7 +5410,7 @@ sub plot {
$footer.= sprintf('▼%s',$bwidth/2+25.5,$footerPos,defined $unitColor ? $unitColor : "#CCCCCC", ::strftime("%a",localtime($minValTime)));
$footer.= sprintf('%s',$bwidth/2+46,$footerPos,::strftime("%H:%M",localtime($minValTime)));
}
- $footer.= sprintf('%s', $bwidth+8,$footerPos,color($minValColor,$lmm),"",sprintf($format,${$collect}{min_value}));
+ $footer.= sprintf('%s', $bwidth+8,$footerPos,color($minValColor,$lmm),"",sprintf($decform,${$collect}{min_value}));
}
}
} # col
@@ -5743,8 +5776,8 @@ sub card
my $maxVal;
for (my $i=0;$i< @value1;$i++) {
if (defined ($value1[$i]{dim})) {
- my $min=defined $value1[$i]{min_value} ? $value1[$i]{min_value} : $value1[$i]{value};
- my $max=defined $value1[$i]{max_value} ? $value1[$i]{max_value} : $value1[$i]{value};
+ my $min=defined $value1[$i]{min_value} ? $value1[$i]{min_value} : $value1[$i]{value} ne "N/A" ? $value1[$i]{value} : $min;
+ my $max=defined $value1[$i]{max_value} ? $value1[$i]{max_value} : $value1[$i]{value} ne "N/A" ? $value1[$i]{value} : $max;
$minVal=$min if (!defined $minVal or $min < $minVal);
$maxVal=$max if (!defined $maxVal or $max > $maxVal);
}
@@ -5752,7 +5785,7 @@ sub card
my $j=0;
for (my $i=0;$i<@value1;$i++) {
- if (defined ($value1[$i]{dim})) {
+ if (defined $value1[$i]{dim}) {
($outplot,$outfooter) = plot ($value1[$i],[$min,$minVal],[$max,$maxVal],$minColor,$maxColor,$dec,$func,$steps,$x_prop,$chart_dim, $noColor,$lmm,$ln,$lr,$plot,$bwidth,$noFooter eq "1" ? 0:84+$j*10,undef,-2.5,"end",(split(",",$unit1[$i]))[1],(split(",",$unit1[$i]))[0]);
$j++;
$out.=$outplot;
@@ -5833,15 +5866,15 @@ sub card
my $maxVal;
for (my $i=0;$i< @value1;$i++) {
if (defined ($value1[$i]{dim})) {
- my $min=defined $value1[$i]{min_value} ? $value1[$i]{min_value} : $value1[$i]{value};
- my $max=defined $value1[$i]{max_value} ? $value1[$i]{max_value} : $value1[$i]{value};
+ my $min=defined $value1[$i]{min_value} ? $value1[$i]{min_value} : $value1[$i]{value} ne "N/A" ? $value1[$i]{value} : $min;
+ my $max=defined $value1[$i]{max_value} ? $value1[$i]{max_value} : $value1[$i]{value} ne "N/A" ? $value1[$i]{value} : $max;
$minVal=$min if (!defined $minVal or $min < $minVal);
$maxVal=$max if (!defined $maxVal or $max > $maxVal);
}
}
my $j=0;
for (my $i=0;$i<@value1;$i++) {
- if (defined ($value1[$i]{dim})) {
+ if (defined $value1[$i]{dim}) {
($outplot,$outfooter) = plot ($value1[$i],[$min,$minVal],[$max,$maxVal],$minColor,$maxColor,$dec,$func,$steps,$x_prop,$chart_dim, $j == 0 ? $noColor:-1,$lmm,$ln,$lr,$plot,$bwidth,$noFooter eq "1" ? 0:84+$j*10,undef,-2.5,"end",(split(",",$unit1[$i]))[1],(split(",",$unit1[$i]))[0]);
$j++;
$out.=$outplot;
@@ -5853,8 +5886,8 @@ sub card
my $maxVal2;
for (my $i=0;$i< @value2;$i++) {
if (defined ($value2[$i]{dim})) {
- my $min=defined $value2[$i]{min_value} ? $value2[$i]{min_value} : $value2[$i]{value};
- my $max=defined $value2[$i]{max_value} ? $value2[$i]{max_value} : $value2[$i]{value};
+ my $min=defined $value2[$i]{min_value} ? $value2[$i]{min_value} : $value2[$i]{value} ne "N/A" ? $value2[$i]{value} : $min;
+ my $max=defined $value2[$i]{max_value} ? $value2[$i]{max_value} : $value2[$i]{value} ne "N/A" ? $value2[$i]{value} : $max;
$minVal2=$min if (!defined $minVal2 or $min < $minVal2);
$maxVal2=$max if (!defined $maxVal2 or $max > $maxVal2);
}
@@ -5862,7 +5895,7 @@ sub card
my $offset=@outfooter*10;
my $j=0;
for (my $i=0;$i<@value2;$i++) {
- if (defined ($value2[$i]{dim})) {
+ if (defined $value2[$i]{dim}) {
($outplot,$outfooter) = plot ($value2[$i],[$min2,$minVal2],[$max2,$maxVal2],$minColor2,$maxColor2,$dec2,$func2,$steps,$x_prop,$chart_dim, $j == 0 ? $noColor:-1,$lmm,$ln,$lr,$plot,$bwidth,$noFooter eq "1" ? 0:84+$offset+$j*10,undef,$chart_dim+3,"start",(split(",",$unit2[$i]))[1],(split(",",$unit2[$i]))[0]);
$j++;
$out.=$outplot;