LogProxy Prozedur Proplanta für DWD_Opendata?

Begonnen von Tobias, 06 Juli 2018, 19:51:04

Vorheriges Thema - Nächstes Thema

Tobias

Maintainer: Text2Speech, TrashCal, MediaList

Meine Projekte: https://github.com/tobiasfaust
* PumpControl v2: allround Bewässerungssteuerung mit ESP und FHEM
* Ein Modbus RS485 zu MQTT Gateway für SolarWechselrichter

Tobias

Hab ich jetzt mal selbst gemacht.
Bitte mal testen:

#---------------------------------------
# DWD LogProxy-Funktion
#---------------------------------------
sub logProxy_dwd2Plot($$$$;$$) {
my ($device, $fcValue, $from, $to, $fcHour, $expMode) = @_;
    my $regex;
    my @rl;
   
return undef if(!$device);
   
    if($fcValue =~ s/_$//) {
        $regex = "^fc[\\d]+_[\\d]{1}_".$fcValue."\$";
    }
    else {
        $regex = "^fc[\\d]+_".$fcValue."\$";
    }
   
    $fcHour = 12 if(!defined $fcHour);
    $expMode = "point" if(!defined $expMode);
#Log3 undef,2, "Regex: ".$regex;

# ermitteln aller relevanten Readings
if( defined($defs{$device}) ) {
if( $defs{$device}{TYPE} eq "DWD_OpenData" ) {
            @rl = sort{
                my ($an) = ($a =~ m/fc(\d+)_.*/);
                my ($bn) = ($b =~ m/fc(\d+)_.*/);
                $an <=> $bn or $a cmp $b;
                }( grep /${regex}/,keys %{$defs{$device}{READINGS}} );
#Log3 undef,2, Dumper(@rl);
return undef if( !@rl );
} else {
Log3 undef, 2, "logProxy_dwd2Plot: $device is not a DWD_OpenData device";
return undef;
}
}
#    Log3 undef,2, Dumper(@rl);

my $fromsec = SVG_time_to_sec($from);
my $tosec   = SVG_time_to_sec($to);
my $sec = $fromsec;
my ($h,$hp,$fcDay,$mday,$mon,$year);
my $timestamp;
   
my $reading;
my $value;
my $prev_value;
my $min = 999999;
my $max = -999999;
my $ret = "";

# while not end of plot range reached
while(($sec < $tosec) && @rl) {
#remember previous value for start of plot range
$prev_value = $value;

$reading = shift @rl;
        ($fcDay) = $reading =~ m/^fc(\d+).*/;
    ($hp) = $reading =~ m/^fc[\d]_(\d).*/;
#Log 1, "hp: ".$hp;
if ($hp) {
  $h = ReadingsVal($device, "fc".$fcDay."_".$hp."_time", $fcHour);
  $h =~ m/^([\d\d]):[\d\d]/;
} else { $h=$fcHour;}

$value = ReadingsVal($device,$reading,undef);
       
($year,$mon,$mday) = split('\-',ReadingsVal($device, "fc".$fcDay."_date",undef));
$timestamp = sprintf("%04d-%02d-%02d_%02d:%02d:%02d", $year, $mon, $mday, $h, 0, 0);
$sec = SVG_time_to_sec($timestamp);
       
# skip all values before start of plot range
next if( SVG_time_to_sec($timestamp) < $fromsec );

# add first value at start of plot range
if( !$ret && $prev_value ) {
$min = $prev_value if( $prev_value < $min );
$max = $prev_value if( $prev_value > $max );
$ret .= "$from $prev_value\n";
}

# done if after end of plot range
last if($sec > $tosec);

$min = $value if( $value < $min );
$max = $value if( $value > $max );

# add actual controll point
$ret .= "$timestamp $value\n";

Log 1, "$timestamp $value <<< $reading";
}
    if(($sec < $tosec) && !@rl && ($expMode eq "day")) {
    $timestamp = sprintf("%04d-%02d-%02d_%02d:%02d:%02d", $year, $mon, $mday, 23, 59, 59);
    if(SVG_time_to_sec($timestamp) < $tosec) {
        $ret .= "$timestamp $value\n";
        }
        else {
$ret .= "$to $value\n";
        }
    }
    elsif(($sec > $tosec) && ($expMode eq "day")) {
        $value = $prev_value + ($value - $prev_value)*(86400 + ($tosec - $sec))/86400;
        $ret .= "$to $value\n";
    }
return ($ret,$min,$max,$prev_value);
}
Maintainer: Text2Speech, TrashCal, MediaList

Meine Projekte: https://github.com/tobiasfaust
* PumpControl v2: allround Bewässerungssteuerung mit ESP und FHEM
* Ein Modbus RS485 zu MQTT Gateway für SolarWechselrichter