2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-05-03 13:45:36 +00:00

HP1000: improved history; use windchill for temperatureCondition instead of temperature

git-svn-id: https://svn.fhem.de/fhem/trunk@14016 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2017-04-17 15:56:28 +00:00
parent 8af0e02a43
commit 00f09f2ba7

View File

@ -802,10 +802,16 @@ sub HP1000_CGI() {
} }
# temperatureCondition # temperatureCondition
if ( defined( $webArgs->{outtemp} ) ) { if ( defined( $webArgs->{windchill} ) ) {
my ( $v, $rgb ) = UConv::c2condition( $webArgs->{outtemp} ); my $avg =
readingsBulkUpdateIfChanged( $hash, "temperatureCondition", $v ); HP1000_GetAvg( $hash, "windchill", 600, $webArgs->{windchill} );
readingsBulkUpdateIfChanged( $hash, "temperatureCondition_rgb", $rgb );
if ( $hash->{INTERVAL} > 0 ) {
my ( $cond, $rgb ) = UConv::c2condition($avg);
readingsBulkUpdateIfChanged( $hash, "temperatureCondition", $cond );
readingsBulkUpdateIfChanged( $hash, "temperatureCondition_rgb",
$rgb );
}
} }
# indoorTemperatureCondition # indoorTemperatureCondition
@ -1035,7 +1041,7 @@ sub HP1000_CGI() {
} }
if ( $hash->{INTERVAL} > 0 && $uptime >= 120 ) { if ( $hash->{INTERVAL} > 0 && $uptime >= 120 ) {
my $v2 = round( HP1000_GetAvg( $hash, "winddir", 120, -1 ), 0 ); my $v2 = round( HP1000_GetAvg( $hash, "winddir", 120 ), 0 );
$webArgs->{winddir_avg2m} = $v2; $webArgs->{winddir_avg2m} = $v2;
readingsBulkUpdateIfChanged( $hash, "wind_direction_avg2m", readingsBulkUpdateIfChanged( $hash, "wind_direction_avg2m",
$webArgs->{winddir_avg2m} ); $webArgs->{winddir_avg2m} );
@ -1482,58 +1488,55 @@ sub HP1000_ReturnWU($$$) {
return; return;
} }
sub HP1000_GetSum($$$$) { sub HP1000_GetAvg($$;$$) {
my ( $hash, $t, $s, $v ) = @_; my ( $hash, $t, $s, $v ) = @_;
return HP1000_GetHistory( $hash, $t, $s, $v ); return HP1000_HistoryDb( $hash, $t, $s, $v, 1 );
} }
sub HP1000_GetAvg($$$$) { sub HP1000_GetMax($$;$$) {
my ( $hash, $t, $s, $v ) = @_; my ( $hash, $t, $s, $v ) = @_;
return HP1000_GetHistory( $hash, $t, $s, $v, 1 ); return HP1000_HistoryDb( $hash, $t, $s, $v, 2 );
} }
sub HP1000_GetMax($$$$) { sub HP1000_HistoryDb($$;$$$) {
my ( $hash, $t, $s, $v ) = @_;
return HP1000_GetHistory( $hash, $t, $s, $v, 2 );
}
sub HP1000_GetHistory($$$$;$) {
my ( $hash, $t, $s, $v, $type ) = @_; my ( $hash, $t, $s, $v, $type ) = @_;
my $name = $hash->{NAME}; my $name = $hash->{NAME};
return $v if ( $type && $type == 1 && $hash->{INTERVAL} < 1 ); return $v if ( $type && $type == 1 && $hash->{INTERVAL} < 1 );
return "0" if ( $hash->{INTERVAL} < 1 ); return "0" if ( $hash->{INTERVAL} < 1 );
my $max = round( $s / $hash->{INTERVAL}, 0 ); my $historySize = $s ? round( $s / $hash->{INTERVAL}, 0 ) : undef;
$max = "1" if ( $max < 1 ); $historySize = "1" if ( defined($historySize) && $historySize < 1 );
my $return = $v;
my $v2 = unshift @{ $hash->{helper}{history}{$t} }, $v if ( defined($v) && looks_like_number($v) ) {
unless ( $v < 0 || ( !$type && $v <= 0 ) ); my $v2 = unshift @{ $hash->{helper}{history}{$t} }, $v
my $v3 = splice @{ $hash->{helper}{history}{$t} }, $max unless ( $v < 0 ); unless ( !$type && $v <= 0 );
my $v3 = splice @{ $hash->{helper}{history}{$t} }, $historySize
if ($historySize);
Log3 $name, 5, "HP1000 $name: Updated history for $t:" Log3 $name, 5, "HP1000 $name: Added $v to history for $t:"
. Dumper( $hash->{helper}{history}{$t} ); . Dumper( @{ $hash->{helper}{history}{$t} } );
if ( !$type ) {
$return = round( sum( @{ $hash->{helper}{history}{$t} } ), 1 );
Log3 $name, 5, "HP1000 $name: Sum for $t: $return";
} }
elsif ( $type == 1 ) {
$return = round(
sum( @{ $hash->{helper}{history}{$t} } ) /
@{ $hash->{helper}{history}{$t} },
1
);
Log3 $name, 5, "HP1000 $name: Average for $t: $return"; my $asize = scalar @{ $hash->{helper}{history}{$t} };
return $v unless ($asize);
$historySize = $asize if ( !$historySize || $asize < $historySize );
$historySize--;
my @a =
$historySize
? @{ $hash->{helper}{history}{$t} }[ 0 .. $historySize ]
: @{ $hash->{helper}{history}{$t} }[0];
if ( $type == 1 ) {
return round( sum(@a) / @a, 1 );
} }
elsif ( $type == 2 ) { elsif ( $type == 2 ) {
$return = maxNum( 0, @{ $hash->{helper}{history}{$t} } ); return maxNum( 0, @a );
Log3 $name, 5, "HP1000 $name: Max for $t: $return";
} }
return $return; return undef;
} }
1; 1;