98_PID20 : bugfix: wrong evaluation of sensor string

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@10312 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
john99sr 2015-12-30 21:45:35 +00:00
parent c2126b824f
commit 0690f6f221

View File

@ -49,7 +49,9 @@
# 27.11.2014 Change: all readings are updated cyclically # 27.11.2014 Change: all readings are updated cyclically
# V 1.0.0.5 # V 1.0.0.5
# 06.11.2015 Fix: reg expression in sub PID20_Notify modifed. Thanks to user gero # 06.11.2015 Fix: reg expression in sub PID20_Notify modifed. Thanks to user gero
# V 1.0.0.6
# 12.11.2015 Fix: wrong evaluation of Sensor String, when value was 0 than sensor timeout was detected
# Feature: added <Internal> VERSION
#################################################################################################### ####################################################################################################
package main; package main;
@ -61,7 +63,7 @@ use vars qw($readingFnAttributes);
use vars qw(%attr); use vars qw(%attr);
use vars qw(%modules); use vars qw(%modules);
my $PID20_Version = "1.0.0.5"; my $PID20_Version = "1.0.0.6";
sub PID20_Calc($); sub PID20_Calc($);
######################################## ########################################
sub PID20_Log($$$) sub PID20_Log($$$)
@ -156,7 +158,7 @@ sub PID20_Define($$$)
return $msg; return $msg;
} }
$hash->{helper}{sensor} = $sensor; $hash->{helper}{sensor} = $sensor;
$hash->{VERSION} = $PID20_Version;
# defaults for regexp # defaults for regexp
if ( !$regexp ) if ( !$regexp )
{ {
@ -174,13 +176,13 @@ sub PID20_Define($$$)
return $msg; return $msg;
} }
$hash->{helper}{actor} = $actor; $hash->{helper}{actor} = $actor;
$hash->{helper}{actorCommand} = ( defined($cmd) ) ? $cmd : ""; $hash->{helper}{actorCommand} = ( defined($cmd) ) ? $cmd : '';
$hash->{helper}{stopped} = 0; $hash->{helper}{stopped} = 0;
$hash->{helper}{adjust} = ""; $hash->{helper}{adjust} = '';
$modules{PID20}{defptr}{$name} = $hash; $modules{PID20}{defptr}{$name} = $hash;
readingsSingleUpdate( $hash, 'state', 'initializing', 1 ); readingsSingleUpdate( $hash, 'state', 'initializing', 1 );
RemoveInternalTimer($name); RemoveInternalTimer($name);
InternalTimer( gettimeofday() + 10, "PID20_Calc", $name, 0 ); InternalTimer( gettimeofday() + 10, 'PID20_Calc', $name, 0 );
return undef; return undef;
} }
######################################## ########################################
@ -204,7 +206,7 @@ sub PID20_Notify($$)
# no action if disabled # no action if disabled
if ( $disable eq '1' ) if ( $disable eq '1' )
{ {
return ""; return '';
} }
return if ( $dev->{NAME} ne $sensorName ); return if ( $dev->{NAME} ne $sensorName );
my $sensorReadingName = $hash->{helper}{reading}; my $sensorReadingName = $hash->{helper}{reading};
@ -219,7 +221,7 @@ sub PID20_Notify($$)
my $s = $dev->{CHANGED}[$i]; my $s = $dev->{CHANGED}[$i];
# continue, if no match with reading-name # continue, if no match with reading-name
$s = "" if ( !defined($s) ); $s = '' if ( !defined($s) );
PID20_Log $hash, 5, "check event:<$s>"; PID20_Log $hash, 5, "check event:<$s>";
next if ( $s !~ m/^$sensorReadingName:.*$/ ); next if ( $s !~ m/^$sensorReadingName:.*$/ );
@ -254,9 +256,9 @@ sub PID20_Notify($$)
my $deltaGradient = $deltaDiff / $tsDiff my $deltaGradient = $deltaDiff / $tsDiff
if ( defined($deltaDiff) && defined($tsDiff) && ( $tsDiff > 0 ) ); if ( defined($deltaDiff) && defined($tsDiff) && ( $tsDiff > 0 ) );
$deltaGradient = 0 if ( !defined($deltaGradient) ); $deltaGradient = 0 if ( !defined($deltaGradient) );
my $sdeltaDiff = ($deltaDiff) ? sprintf( "%.2f", $deltaDiff ) : ""; my $sdeltaDiff = ($deltaDiff) ? sprintf( "%.2f", $deltaDiff ) : '';
my $sTSDiff = ($tsDiff) ? sprintf( "%.2f", $tsDiff ) : ""; my $sTSDiff = ($tsDiff) ? sprintf( "%.2f", $tsDiff ) : '';
my $sDeltaGradient = ($deltaGradient) ? sprintf( "%.6f", $deltaGradient ) : ""; my $sDeltaGradient = ($deltaGradient) ? sprintf( "%.6f", $deltaGradient ) : '';
PID20_Log $hash, 5, PID20_Log $hash, 5,
"deltaGradient: (Diff[$sdeltaDiff]" . "/tsDiff[$sTSDiff]" . "=deltaGradient per sec [$sDeltaGradient]" "deltaGradient: (Diff[$sdeltaDiff]" . "/tsDiff[$sTSDiff]" . "=deltaGradient per sec [$sDeltaGradient]"
if ($DEBUG); if ($DEBUG);
@ -267,7 +269,7 @@ sub PID20_Notify($$)
$hash->{helper}{deltaOldTS} = TimeNow(); $hash->{helper}{deltaOldTS} = TimeNow();
last; last;
} }
return ""; return '';
} }
######################################## ########################################
sub PID20_Get($@) sub PID20_Get($@)
@ -313,7 +315,7 @@ sub PID20_Set($@)
#PID20_Log $hash, 3, "name:$name cmd:$cmd $desired:$desired"; #PID20_Log $hash, 3, "name:$name cmd:$cmd $desired:$desired";
given ($cmd) given ($cmd)
{ {
when ("?") when ('?')
{ {
return $usage; return $usage;
} }
@ -328,22 +330,22 @@ sub PID20_Set($@)
readingsSingleUpdate( $hash, $cmd, $value, 1 ); readingsSingleUpdate( $hash, $cmd, $value, 1 );
PID20_Log $hash, 3, "set $name $cmd $a[2]"; PID20_Log $hash, 3, "set $name $cmd $a[2]";
} }
when ("start") when ('start')
{ {
return "Set start needs a <value> parameter" return 'Set start needs a <value> parameter'
if ( @a != 2 ); if ( @a != 2 );
$hash->{helper}{stopped} = 0; $hash->{helper}{stopped} = 0;
} }
when ("stop") when ('stop')
{ {
return "Set stop needs a <value> parameter" return 'Set stop needs a <value> parameter'
if ( @a != 2 ); if ( @a != 2 );
$hash->{helper}{stopped} = 1; $hash->{helper}{stopped} = 1;
PID20_Calc($name); PID20_Calc($name);
} }
when ("restart") when ('restart')
{ {
return "Set restart needs a <value> parameter" return 'Set restart needs a <value> parameter'
if ( @a != 3 ); if ( @a != 3 );
my $value = $a[2]; my $value = $a[2];
$value = ( $value =~ m/$reFloat/ ) ? $1 : undef; $value = ( $value =~ m/$reFloat/ ) ? $1 : undef;
@ -394,26 +396,26 @@ sub PID20_Calc($)
my $DEBUG_Update = AttrVal( $name, 'pidDebugUpdate', '0' ) eq '1'; my $DEBUG_Update = AttrVal( $name, 'pidDebugUpdate', '0' ) eq '1';
my $DEBUG = $DEBUG_Sensor || $DEBUG_Actuation || $DEBUG_Calc || $DEBUG_Delta || $DEBUG_Update; my $DEBUG = $DEBUG_Sensor || $DEBUG_Actuation || $DEBUG_Calc || $DEBUG_Delta || $DEBUG_Update;
my $actuation = ""; my $actuation = '';
my $actuationDone = ReadingsVal( $name, 'actuation', "" ); my $actuationDone = ReadingsVal( $name, 'actuation', '' );
my $actuationCalc = ReadingsVal( $name, 'actuationCalc', "" ); my $actuationCalc = ReadingsVal( $name, 'actuationCalc', '' );
my $actuationCalcOld = $actuationCalc; my $actuationCalcOld = $actuationCalc;
my $actorTimestamp = my $actorTimestamp =
( $hash->{helper}{actorTimestamp} ) ( $hash->{helper}{actorTimestamp} )
? $hash->{helper}{actorTimestamp} ? $hash->{helper}{actorTimestamp}
: FmtDateTime( gettimeofday() - 3600 * 24 ); : FmtDateTime( gettimeofday() - 3600 * 24 );
my $sensorStr = ReadingsVal( $sensor, $reading, "" ); my $sensorStr = ReadingsVal( $sensor, $reading, '' );
my $sensorValue = ""; my $sensorValue = '';
my $sensorTS = ReadingsTimestamp( $sensor, $reading, undef ); my $sensorTS = ReadingsTimestamp( $sensor, $reading, undef );
my $sensorIsAlive = 0; my $sensorIsAlive = 0;
my $iPortion = ReadingsVal( $name, 'p_i', 0 ); my $iPortion = ReadingsVal( $name, 'p_i', 0 );
my $pPortion = ReadingsVal( $name, 'p_p', "" ); my $pPortion = ReadingsVal( $name, 'p_p', '' );
my $dPortion = ReadingsVal( $name, 'p_d', "" ); my $dPortion = ReadingsVal( $name, 'p_d', '' );
my $stateStr = ""; my $stateStr = '';
my $deltaOld = ReadingsVal( $name, 'delta', 0 ); my $deltaOld = ReadingsVal( $name, 'delta', 0 );
my $delta = ""; my $delta = '';
my $deltaGradient = ( $hash->{helper}{deltaGradient} ) ? $hash->{helper}{deltaGradient} : 0; my $deltaGradient = ( $hash->{helper}{deltaGradient} ) ? $hash->{helper}{deltaGradient} : 0;
my $calcReq = 0; my $calcReq = 0;
my $readingUpdateReq = ''; my $readingUpdateReq = '';
@ -447,33 +449,33 @@ sub PID20_Calc($)
if ( $hash->{helper}{disable} ) if ( $hash->{helper}{disable} )
{ {
$stateStr = "disabled"; $stateStr = 'disabled';
last; last;
} }
if ( $hash->{helper}{stopped} ) if ( $hash->{helper}{stopped} )
{ {
$stateStr = "stopped"; $stateStr = 'stopped';
last; last;
} }
my $desired = ReadingsVal( $name, $hash->{helper}{desiredName}, "" ); my $desired = ReadingsVal( $name, $hash->{helper}{desiredName}, '' );
# sensor found # sensor found
PID20_Log $hash, 2, "--------------------------" if ($DEBUG); PID20_Log $hash, 2, '--------------------------' if ($DEBUG);
PID20_Log $hash, 2, "S1 sensorStr:$sensorStr sensorTS:$sensorTS" if ($DEBUG_Sensor); PID20_Log $hash, 2, "S1 sensorStr:$sensorStr sensorTS:$sensorTS" if ($DEBUG_Sensor);
$stateStr = "alarm - no $reading yet for $sensor" if ( !$sensorStr && !$stateStr ); $stateStr = "alarm - no $reading yet for $sensor" if ( $sensorStr eq '' && $stateStr eq '' );
# sensor alive # sensor alive
if ( $sensorStr && $sensorTS ) if ( $sensorStr ne '' && $sensorTS )
{ {
my $timeDiff = PID20_TimeDiff($sensorTS); my $timeDiff = PID20_TimeDiff($sensorTS);
$sensorIsAlive = 1 if ( $timeDiff <= $hash->{helper}{sensorTimeout} ); $sensorIsAlive = 1 if ( $timeDiff <= $hash->{helper}{sensorTimeout} );
$sensorStr =~ m/$regexp/; $sensorStr =~ m/$regexp/;
$sensorValue = $1; $sensorValue = $1;
$sensorValue = "" if ( !defined($sensorValue) ); $sensorValue = '' if ( !defined($sensorValue) );
PID20_Log $hash, 2, PID20_Log $hash, 2,
"S2 timeOfDay:" 'S2 timeOfDay:'
. gettimeofday() . gettimeofday()
. " timeDiff:$timeDiff sensorTimeout:" . " timeDiff:$timeDiff sensorTimeout:"
. $hash->{helper}{sensorTimeout} . $hash->{helper}{sensorTimeout}
@ -482,18 +484,18 @@ sub PID20_Calc($)
} }
# sensor dead # sensor dead
$stateStr = "alarm - dead sensor" if ( !$sensorIsAlive && !$stateStr ); $stateStr = 'alarm - dead sensor' if ( !$sensorIsAlive && $stateStr eq '' );
# missing desired # missing desired
$stateStr = "alarm - missing desired" if ( $desired eq "" && !$stateStr ); $stateStr = 'alarm - missing desired' if ( $desired eq '' && $stateStr eq '' );
# check delta threshold # check delta threshold
$delta = ( $desired ne "" && $sensorValue ne "" ) ? $desired - $sensorValue : ""; $delta = ( $desired ne '' && $sensorValue ne '' ) ? $desired - $sensorValue : '';
$calcReq = 1 if ( !$stateStr && $delta ne "" && ( abs($delta) >= abs( $hash->{helper}{deltaTreshold} ) ) ); $calcReq = 1 if ( $stateStr eq '' && $delta ne '' && ( abs($delta) >= abs( $hash->{helper}{deltaTreshold} ) ) );
PID20_Log $hash, 2, PID20_Log $hash, 2,
"D1 desired[" . ( $desired ne "" ) ? sprintf( "%.1f", $desired ) "D1 desired[" . ( $desired ne '' ) ? sprintf( "%.1f", $desired )
: "" . "] - sensorValue: [" . ( $sensorValue ne "" ) ? sprintf( "%.1f", $sensorValue ) : "" . "] - sensorValue: [" . ( $sensorValue ne '' ) ? sprintf( "%.1f", $sensorValue )
: "" . "] = delta[" . ( $delta ne "" ) ? sprintf( "%.2f", $delta ) : "" . "] = delta[" . ( $delta ne "" ) ? sprintf( "%.2f", $delta )
: "" . "] calcReq:$calcReq" : "" . "] calcReq:$calcReq"
if ($DEBUG_Delta); if ($DEBUG_Delta);
@ -518,13 +520,13 @@ sub PID20_Calc($)
&& ( ( $workDelta > 0 && $actuationCalcOld > $actorLimitUpper ) && ( ( $workDelta > 0 && $actuationCalcOld > $actorLimitUpper )
|| ( $workDelta < 0 && $actuationCalcOld < $actorLimitLower ) ); || ( $workDelta < 0 && $actuationCalcOld < $actorLimitLower ) );
if ( $hash->{helper}{adjust} ne "" ) if ( $hash->{helper}{adjust} ne '' )
{ {
$iPortion = $hash->{helper}{adjust} - ( $pPortion + $dPortion ); $iPortion = $hash->{helper}{adjust} - ( $pPortion + $dPortion );
$iPortion = $actorLimitUpper if ( $iPortion > $actorLimitUpper ); $iPortion = $actorLimitUpper if ( $iPortion > $actorLimitUpper );
$iPortion = $actorLimitLower if ( $iPortion < $actorLimitLower ); $iPortion = $actorLimitLower if ( $iPortion < $actorLimitLower );
PID20_Log $hash, 5, "adjust request with:" . $hash->{helper}{adjust} . " ==> p_i:$iPortion"; PID20_Log $hash, 5, "adjust request with:" . $hash->{helper}{adjust} . " ==> p_i:$iPortion";
$hash->{helper}{adjust} = ""; $hash->{helper}{adjust} = '';
} elsif ( !$isWindup ) # integrate only if no windUp } elsif ( !$isWindup ) # integrate only if no windUp
{ {
# normalize the intervall to minute=60 seconds # normalize the intervall to minute=60 seconds
@ -537,10 +539,10 @@ sub PID20_Calc($)
# calc actuation # calc actuation
$actuationCalc = $pPortion + $iPortion + $dPortion; $actuationCalc = $pPortion + $iPortion + $dPortion;
PID20_Log $hash, 2, "P1 delta:" . sprintf( "%.2f", $delta ) . " isWindup:$isWindup" if ($DEBUG_Calc); PID20_Log $hash, 2, 'P1 delta:' . sprintf( "%.2f", $delta ) . " isWindup:$isWindup" if ($DEBUG_Calc);
PID20_Log $hash, 2, PID20_Log $hash, 2,
"P2 pPortion:" 'P2 pPortion:'
. sprintf( "%.2f", $pPortion ) . sprintf( "%.2f", $pPortion )
. " iPortion:" . " iPortion:"
. sprintf( "%.2f", $iPortion ) . sprintf( "%.2f", $iPortion )
@ -559,23 +561,23 @@ sub PID20_Calc($)
# check actor fallback in case of sensor fault # check actor fallback in case of sensor fault
if ( !$sensorIsAlive && ( $hash->{helper}{actorErrorAction} eq "errorPos" ) ) if ( !$sensorIsAlive && ( $hash->{helper}{actorErrorAction} eq "errorPos" ) )
{ {
$stateStr .= "- force pid-output to errorPos"; $stateStr .= '- force pid-output to errorPos';
$actuationCalc = $hash->{helper}{actorErrorPos}; $actuationCalc = $hash->{helper}{actorErrorPos};
$actuationCalc = "" if ( !defined($actuationCalc) ); $actuationCalc = '' if ( !defined($actuationCalc) );
} }
# check acutation diff # check acutation diff
$actuation = $actuationCalc; $actuation = $actuationCalc;
# limit $actuation # limit $actuation
$actuation = $actorLimitUpper if ( $actuation ne "" && ( $actuation > $actorLimitUpper ) ); $actuation = $actorLimitUpper if ( $actuation ne '' && ( $actuation > $actorLimitUpper ) );
$actuation = $actorLimitLower if ( $actuation ne "" && ( $actuation < $actorLimitLower ) ); $actuation = $actorLimitLower if ( $actuation ne '' && ( $actuation < $actorLimitLower ) );
# check if round request # check if round request
my $fmt = "%." . $hash->{helper}{actorValueDecPlaces} . "f"; my $fmt = "%." . $hash->{helper}{actorValueDecPlaces} . "f";
$actuation = sprintf( $fmt, $actuation ) if ( $actuation ne "" ); $actuation = sprintf( $fmt, $actuation ) if ( $actuation ne '' );
my $actuationDiff = abs( $actuation - $actuationDone ) my $actuationDiff = abs( $actuation - $actuationDone )
if ( $actuation ne "" && $actuationDone ne "" ); if ( $actuation ne '' && $actuationDone ne '' );
PID20_Log $hash, 2, PID20_Log $hash, 2,
"A1 act:$actuation actDone:$actuationDone " "A1 act:$actuation actDone:$actuationDone "
. " actThreshold:" . " actThreshold:"
@ -584,25 +586,25 @@ sub PID20_Calc($)
if ($DEBUG_Actuation); if ($DEBUG_Actuation);
# check threshold-condition for actuation # check threshold-condition for actuation
my $rsTS = $actuationDone ne "" && $actuationDiff >= $hash->{helper}{actorThreshold}; my $rsTS = $actuationDone ne '' && $actuationDiff >= $hash->{helper}{actorThreshold};
# ...... special handling if acutation is in the black zone between actorLimit and (actorLimit - actorThreshold) # ...... special handling if acutation is in the black zone between actorLimit and (actorLimit - actorThreshold)
# upper range # upper range
my $rsUp = my $rsUp =
$actuationDone ne "" $actuationDone ne ''
&& $actuation > $actorLimitUpper - $hash->{helper}{actorThreshold} && $actuation > $actorLimitUpper - $hash->{helper}{actorThreshold}
&& $actuationDiff != 0 && $actuationDiff != 0
&& $actuation >= $actorLimitUpper; && $actuation >= $actorLimitUpper;
# low range # low range
my $rsDown = my $rsDown =
$actuationDone ne "" $actuationDone ne ''
&& $actuation < $actorLimitLower + $hash->{helper}{actorThreshold} && $actuation < $actorLimitLower + $hash->{helper}{actorThreshold}
&& $actuationDiff != 0 && $actuationDiff != 0
&& $actuation <= $actorLimitLower; && $actuation <= $actorLimitLower;
# upper or lower limit are exceeded # upper or lower limit are exceeded
my $rsLimit = $actuationDone ne "" && ( $actuationDone < $actorLimitLower || $actuationDone > $actorLimitUpper ); my $rsLimit = $actuationDone ne '' && ( $actuationDone < $actorLimitLower || $actuationDone > $actorLimitUpper );
my $actuationByThreshold = ( ( $rsTS || $rsUp || $rsDown ) && $noTrouble ); my $actuationByThreshold = ( ( $rsTS || $rsUp || $rsDown ) && $noTrouble );
PID20_Log $hash, 2, "A2 rsTS:$rsTS rsUp:$rsUp rsDown:$rsDown noTrouble:$noTrouble" PID20_Log $hash, 2, "A2 rsTS:$rsTS rsUp:$rsUp rsDown:$rsDown noTrouble:$noTrouble"
@ -629,8 +631,8 @@ sub PID20_Calc($)
( $actuationByThreshold && $actuationByTime ) ( $actuationByThreshold && $actuationByTime )
|| $actuationKeepAliveReq # request by keep alive || $actuationKeepAliveReq # request by keep alive
|| $rsLimit # upper or lower limit are exceeded || $rsLimit # upper or lower limit are exceeded
|| $actuationDone eq "" # startup condition || $actuationDone eq '' # startup condition
) && $actuation ne ""; # acutation is initialized ) && $actuation ne ''; # acutation is initialized
PID20_Log $hash, 2, PID20_Log $hash, 2,
"A4 (actByTh:$actuationByThreshold && actByTime:$actuationByTime)" "A4 (actByTh:$actuationByThreshold && actByTime:$actuationByTime)"
@ -645,11 +647,11 @@ sub PID20_Calc($)
#build command for fhem #build command for fhem
PID20_Log $hash, 5, PID20_Log $hash, 5,
"actor:" 'actor:'
. $hash->{helper}{actor} . $hash->{helper}{actor}
. " actorCommand:" . ' actorCommand:'
. $hash->{helper}{actorCommand} . $hash->{helper}{actorCommand}
. " actuation:" . ' actuation:'
. $actuation; . $actuation;
my $cmd = sprintf( "set %s %s %g", $hash->{helper}{actor}, $hash->{helper}{actorCommand}, $actuation ); my $cmd = sprintf( "set %s %s %g", $hash->{helper}{actor}, $hash->{helper}{actorCommand}, $actuation );
@ -660,11 +662,11 @@ sub PID20_Calc($)
# note timestamp # note timestamp
$hash->{helper}{actorTimestamp} = TimeNow(); $hash->{helper}{actorTimestamp} = TimeNow();
$actuationDone = $actuation; $actuationDone = $actuation;
my $retStr = ""; my $retStr = '';
$retStr = " with return-value:" . $ret if ( defined($ret) && ( $ret ne '' ) ); $retStr = ' with return-value:' . $ret if ( defined($ret) && ( $ret ne '' ) );
PID20_Log $hash, 3, "<$cmd> " . $retStr; PID20_Log $hash, 3, "<$cmd> " . $retStr;
} }
my $updateAlive = ( $actuation ne "" ) my $updateAlive = ( $actuation ne '' )
&& PID20_TimeDiff( ReadingsTimestamp( $name, 'actuation', gettimeofday() ) ) >= $hash->{helper}{updateInterval}; && PID20_TimeDiff( ReadingsTimestamp( $name, 'actuation', gettimeofday() ) ) >= $hash->{helper}{updateInterval};
# my $updateReq = ( ( $actuationReq || $updateAlive ) && $actuation ne "" ); # my $updateReq = ( ( $actuationReq || $updateAlive ) && $actuation ne "" );
@ -674,14 +676,14 @@ sub PID20_Calc($)
if ($readingUpdateReq) if ($readingUpdateReq)
{ {
readingsBeginUpdate($hash); readingsBeginUpdate($hash);
readingsBulkUpdate( $hash, $hash->{helper}{desiredName}, $desired ) if ( $desired ne "" ); readingsBulkUpdate( $hash, $hash->{helper}{desiredName}, $desired ) if ( $desired ne '' );
readingsBulkUpdate( $hash, $hash->{helper}{measuredName}, $sensorValue ) if ( $sensorValue ne "" ); readingsBulkUpdate( $hash, $hash->{helper}{measuredName}, $sensorValue ) if ( $sensorValue ne '' );
readingsBulkUpdate( $hash, 'p_p', $pPortion ) if ( $pPortion ne "" ); readingsBulkUpdate( $hash, 'p_p', $pPortion ) if ( $pPortion ne '' );
readingsBulkUpdate( $hash, 'p_d', $dPortion ) if ( $dPortion ne "" ); readingsBulkUpdate( $hash, 'p_d', $dPortion ) if ( $dPortion ne '' );
readingsBulkUpdate( $hash, 'p_i', $iPortion ) if ( $iPortion ne "" ); readingsBulkUpdate( $hash, 'p_i', $iPortion ) if ( $iPortion ne '' );
readingsBulkUpdate( $hash, 'actuation', $actuationDone ) if ( $actuationDone ne "" ); readingsBulkUpdate( $hash, 'actuation', $actuationDone ) if ( $actuationDone ne '' );
readingsBulkUpdate( $hash, 'actuationCalc', $actuationCalc ) if ( $actuationCalc ne "" ); readingsBulkUpdate( $hash, 'actuationCalc', $actuationCalc ) if ( $actuationCalc ne '' );
readingsBulkUpdate( $hash, 'delta', $delta ) if ( $delta ne "" ); readingsBulkUpdate( $hash, 'delta', $delta ) if ( $delta ne '' );
readingsEndUpdate( $hash, 1 ); readingsEndUpdate( $hash, 1 );
PID20_Log $hash, 5, "readings updated"; PID20_Log $hash, 5, "readings updated";
} }
@ -690,15 +692,15 @@ sub PID20_Calc($)
} # end while } # end while
# ........ update statePID. # ........ update statePID.
$stateStr = "idle" if ( !$stateStr && !$calcReq ); $stateStr = 'idle' if ( $stateStr eq '' && !$calcReq );
$stateStr = "processing" if ( !$stateStr && $calcReq ); $stateStr = 'processing' if ( $stateStr eq '' && $calcReq );
readingsSingleUpdate( $hash, 'state', $stateStr, 0 ); readingsSingleUpdate( $hash, 'state', $stateStr, 0 );
PID20_Log $hash, 2, "C1 stateStr:$stateStr calcReq:$calcReq" if ($DEBUG_Calc); PID20_Log $hash, 2, "C1 stateStr:$stateStr calcReq:$calcReq" if ($DEBUG_Calc);
#......... timer setup #......... timer setup
my $next = gettimeofday() + $hash->{helper}{calcInterval}; my $next = gettimeofday() + $hash->{helper}{calcInterval};
RemoveInternalTimer($name); # prevent multiple timers for same hash RemoveInternalTimer($name); # prevent multiple timers for same hash
InternalTimer( $next, "PID20_Calc", $name, 1 ); InternalTimer( $next, 'PID20_Calc', $name, 1 );
#PID20_Log $hash, 2, "InternalTimer next:".FmtDateTime($next)." PID20_Calc name:$name DEBUG_Calc:$DEBUG_Calc"; #PID20_Log $hash, 2, "InternalTimer next:".FmtDateTime($next)." PID20_Calc name:$name DEBUG_Calc:$DEBUG_Calc";
return; return;