mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
98_DOIF.pm: Regex for readings in aggregate function
git-svn-id: https://svn.fhem.de/fhem/trunk@15917 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
6ba23b519c
commit
928aab275b
@ -725,6 +725,7 @@ sub AggrIntDoIf
|
||||
my $format;
|
||||
my $place;
|
||||
my $number;
|
||||
my $readingRegex;
|
||||
|
||||
if ($modeType =~ /.(sum|average|max|min)?[:]?(?:(a|d)?(\d)?)?/) {
|
||||
$type = (defined $1)? $1 : "";
|
||||
@ -739,73 +740,82 @@ sub AggrIntDoIf
|
||||
$default=EvalValueDoIf($hash,"default",$default);
|
||||
}
|
||||
}
|
||||
|
||||
if (defined $reading) {
|
||||
if ($reading =~ /^"(.*)"$/) {
|
||||
$readingRegex = $1;
|
||||
}
|
||||
}
|
||||
|
||||
foreach my $name (($device eq "") ? keys %defs:grep {/$device/} keys %defs) {
|
||||
next if($attr{$name} && $attr{$name}{ignore});
|
||||
$value="";
|
||||
$number="";
|
||||
if ($reading) {
|
||||
if (defined $defs{$name}{READINGS}{$reading}) {
|
||||
$value=$defs{$name}{READINGS}{$reading}{VAL};
|
||||
$number = ($value =~ /(-?\d+(\.\d+)?)/ ? $1 : 0);
|
||||
} else {
|
||||
next;
|
||||
}
|
||||
}
|
||||
if ($cond) {
|
||||
if ($cond =~ /^"(.*)"$/) {
|
||||
if (defined $defs{$name}{READINGS}{$reading}) {
|
||||
$ret=($value =~ /$1/);
|
||||
}
|
||||
} else {
|
||||
$_=$value;
|
||||
$STATE=Value($name);
|
||||
$TYPE=$defs{$name}{TYPE};
|
||||
$group=AttrVal($name,"group","");
|
||||
$room=AttrVal($name,"room","");
|
||||
$lastWarningMsg="";
|
||||
$ret = eval $cond;
|
||||
if ($@) {
|
||||
$@ =~ s/^(.*) at \(eval.*\)(.*)$/$1,$2/;
|
||||
if (defined $hash) {
|
||||
Log3 ($hash->{NAME},3 , "$hash->{NAME}: aggregate function: error in condition: $cond, $@");
|
||||
}
|
||||
return("error in aggregate function: ".$@);
|
||||
foreach my $reading ((defined $readingRegex) ? grep {/$readingRegex/} keys %{$defs{$name}{READINGS}} : $reading) {
|
||||
$value="";
|
||||
$number="";
|
||||
if ($reading) {
|
||||
if (defined $defs{$name}{READINGS}{$reading}) {
|
||||
$value=$defs{$name}{READINGS}{$reading}{VAL};
|
||||
$number = ($value =~ /(-?\d+(\.\d+)?)/ ? $1 : 0);
|
||||
} else {
|
||||
next;
|
||||
}
|
||||
if ($lastWarningMsg) {
|
||||
$warning=1;
|
||||
$lastWarningMsg =~ s/^(.*) at \(eval.*$/$1/;
|
||||
Log3 ($hash->{NAME},3 , "$hash->{NAME}: aggregate function: warning in condition: $cond, Device: $name");
|
||||
readingsSingleUpdate ($hash, "warning_aggr", "condition: $cond , device: $name, $lastWarningMsg",0);
|
||||
}
|
||||
$lastWarningMsg="";
|
||||
}
|
||||
} else {
|
||||
$ret=1;
|
||||
}
|
||||
if ($format eq "a") {
|
||||
$devname=AttrVal($name,"alias",$name);
|
||||
} else {
|
||||
$devname=$name;
|
||||
}
|
||||
if ($ret) {
|
||||
if ($type eq ""){
|
||||
$num++;
|
||||
push (@devices,$devname);
|
||||
} elsif (defined $value) {
|
||||
if ($type eq "sum" or $type eq "average") {
|
||||
if ($cond) {
|
||||
if ($cond =~ /^"(.*)"$/) {
|
||||
if (defined $defs{$name}{READINGS}{$reading}) {
|
||||
$ret=($value =~ /$1/);
|
||||
}
|
||||
} else {
|
||||
$_=$value;
|
||||
$STATE=Value($name);
|
||||
$TYPE=$defs{$name}{TYPE};
|
||||
$group=AttrVal($name,"group","");
|
||||
$room=AttrVal($name,"room","");
|
||||
$lastWarningMsg="";
|
||||
$ret = eval $cond;
|
||||
if ($@) {
|
||||
$@ =~ s/^(.*) at \(eval.*\)(.*)$/$1,$2/;
|
||||
if (defined $hash) {
|
||||
Log3 ($hash->{NAME},3 , "$hash->{NAME}: aggregate function: error in condition: $cond, $@");
|
||||
}
|
||||
return("error in aggregate function: ".$@);
|
||||
}
|
||||
if ($lastWarningMsg) {
|
||||
$warning=1;
|
||||
$lastWarningMsg =~ s/^(.*) at \(eval.*$/$1/;
|
||||
Log3 ($hash->{NAME},3 , "$hash->{NAME}: aggregate function: warning in condition: $cond, Device: $name");
|
||||
readingsSingleUpdate ($hash, "warning_aggr", "condition: $cond , device: $name, $lastWarningMsg",0);
|
||||
}
|
||||
$lastWarningMsg="";
|
||||
}
|
||||
} else {
|
||||
$ret=1;
|
||||
}
|
||||
if ($format eq "a") {
|
||||
$devname=AttrVal($name,"alias",$name);
|
||||
} else {
|
||||
$devname=$name;
|
||||
}
|
||||
if ($ret) {
|
||||
if ($type eq ""){
|
||||
$num++;
|
||||
push (@devices,$devname);
|
||||
$sum+=$number;
|
||||
} elsif ($type eq "max") {
|
||||
if (!defined $extrem or $number>$extrem) {
|
||||
$extrem=$number;
|
||||
@devices=($devname);
|
||||
}
|
||||
} elsif ($type eq "min") {
|
||||
if (!defined $extrem or $number<$extrem) {
|
||||
$extrem=$number;
|
||||
@devices=($devname);
|
||||
}
|
||||
} elsif (defined $value) {
|
||||
if ($type eq "sum" or $type eq "average") {
|
||||
$num++;
|
||||
push (@devices,$devname);
|
||||
$sum+=$number;
|
||||
} elsif ($type eq "max") {
|
||||
if (!defined $extrem or $number>$extrem) {
|
||||
$extrem=$number;
|
||||
@devices=($devname);
|
||||
}
|
||||
} elsif ($type eq "min") {
|
||||
if (!defined $extrem or $number<$extrem) {
|
||||
$extrem=$number;
|
||||
@devices=($devname);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3492,7 +3502,7 @@ Die Angabe des Readings kann weggelassen werden, dann wird lediglich nach entspr
|
||||
<br>
|
||||
Syntax:<br>
|
||||
<br>
|
||||
<code>[<function>:<format>:"<regex device>:<regex event>":<reading>:<condition>,<default>]</code><br>
|
||||
<code>[<function>:<format>:"<regex device>:<regex event>":<reading>|"<regex reading>":<condition>,<default>]</code><br>
|
||||
<br>
|
||||
<function>:<br>
|
||||
<br>
|
||||
@ -3512,6 +3522,8 @@ Die Angabe <regex Event> ist im Ausführungsteil nicht sinnvoll und sollte
|
||||
<br>
|
||||
<reading> Reading, welches überprüft werden soll<br>
|
||||
<br>
|
||||
"<regex reading>"; Regex für Readings, die überprüft werden sollen<br>
|
||||
<br>
|
||||
<condition> Aggregations-Bedingung, $_ ist der Platzhalter für den aktuellen Wert des internen Schleifendurchlaufs, Angaben in Anführungszeichen der Art "<value>" entsprechen $_ =~ "<value>" , hier sind alle Perloperatoren möglich.<br>
|
||||
<br>
|
||||
<default> Default-Wert, falls kein Device gefunden wird, entspricht der Syntax des Default-Wertes bei Readingangaben<br>
|
||||
@ -3524,10 +3536,6 @@ Anzahl der Devices, die mit "window" beginnen:<br>
|
||||
<br>
|
||||
<code>[#"^window"]</code><br>
|
||||
<br>
|
||||
Liste der Devices, die mit "window" beginnen:<br>
|
||||
<br>
|
||||
<code>[@"^window"]</code><br>
|
||||
<br>
|
||||
Liste der Devices, die mit "window" beginnen, es werden Aliasnamen ausgegeben, falls definiert:<br>
|
||||
<br>
|
||||
<code>[@:a"^window"]</code><br>
|
||||
@ -3544,6 +3552,14 @@ entspricht:<br>
|
||||
<br>
|
||||
<code>[@"^window":state:$_ =~ "open"]</code> siehe Aggregationsbedingung.<br>
|
||||
<br>
|
||||
Kleinster Wert der Readings des Devices "abfall", in deren Namen "Gruenschnitt" vorkommt und die mit "_days" enden:<br>
|
||||
<br>
|
||||
<code>[#min:"^abfall$":"Gruenschnitt.*_days$"]</code><br>
|
||||
<br>
|
||||
Durchschnitt von Readings aller Devices, die mit "T_" beginnen, in deren Reading-Namen "temp" vorkommt:<br>
|
||||
<br>
|
||||
<code>[#average:"^T_":"temp"]</code><br>
|
||||
<br>
|
||||
In der Aggregationsbedingung <condition> können alle in FHEM definierten Perlfunktionen genutzt werden. Folgende Variablen sind vorbelegt und können ebenfalls benutzt werden:<br>
|
||||
<br>
|
||||
<b>$_</b> Inhalt des angegebenen Readings (s.o.)<br>
|
||||
|
Loading…
Reference in New Issue
Block a user