mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 06:39:11 +00:00
fhem.pl: extern SetMagic, add AttrNum and InternalNum (Forum #38276)
git-svn-id: https://svn.fhem.de/fhem/trunk@13904 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
7d5a03f40b
commit
57eb68292f
@ -1084,10 +1084,26 @@ The following local attributes are used by a wider range of devices:
|
||||
From featurelevel 5.7 on the set and setreading command replaces:
|
||||
<ul>
|
||||
<li>[device:name] with the reading, internal or attribute of the device, if
|
||||
both device and the reading, internal or attribute exists. You can use the
|
||||
r:, i: or a: prefix to restrict the search to one type, analogue to the
|
||||
devspec filtering.</li>
|
||||
both device and the reading, internal or attribute exists.
|
||||
<ul>
|
||||
<li>You can use the r:, i: or a: prefix to restrict the search to one
|
||||
type, analogue to the devspec filtering.</li>
|
||||
<li>The suffix :d retrieves the first number and converts it to an
|
||||
integer.</li>
|
||||
<li>The suffix :r<n> retrieves the first number and rounds it to
|
||||
<n> decimal places. If <n> is missing, then rounds it to
|
||||
one decimal place.</li>
|
||||
<li>The suffix :t returns the timestamp (works only for readings)</li>
|
||||
<li>The suffix :sec returns the number of seconds since the reading was
|
||||
set.</li>
|
||||
</ul>
|
||||
Example:
|
||||
<ul>
|
||||
set Lamp blink [blinkDummy:number] [r:blinkDummy:duration:d]
|
||||
</ul>
|
||||
</li>
|
||||
<li>[device:name:d] same as above, but only the number is retrieved</li>
|
||||
<li>[device:name:sec] same as above, but only the number is retrieved</li>
|
||||
<li>{(perlExpression)} with the result of perlExpression.
|
||||
The $DEV variable is additionally available, designating the set device
|
||||
name.
|
||||
@ -1648,8 +1664,10 @@ The following local attributes are used by a wider range of devices:
|
||||
Return the reading (the value in the Readings section of "list device")
|
||||
</li><br>
|
||||
<li>
|
||||
ReadingsNum(<devicename>,<reading>,<defaultvalue>)<br>
|
||||
Return the reading as a number, i.e. delete non-numerical values.
|
||||
ReadingsNum(<devicename>,<reading>,
|
||||
<defaultvalue>,<round>)<br>
|
||||
Return the first number from a reading value.
|
||||
Round id to <round> devimal places (optional parameter).
|
||||
</li><br>
|
||||
<li>ReadingsTimestamp(<devicename>,<reading>,<
|
||||
defaultvalue>)<br>
|
||||
@ -1670,12 +1688,24 @@ The following local attributes are used by a wider range of devices:
|
||||
{ ReadingsTimestamp("wz", "measured-temp", 0)}<br>
|
||||
{ AttrVal("wz", "room", "none") }<br>
|
||||
</li><br>
|
||||
<li>
|
||||
AttrNum(<devicename>,<attribute>,
|
||||
<defaultvalue>,<round>)<br>
|
||||
Return the first number from an attribute value.
|
||||
Round id to <round> devimal places (optional parameter).
|
||||
</li><br>
|
||||
<li>
|
||||
InternalVal(<devicename>,<property>,<defaultvalue>)
|
||||
<br>
|
||||
Return the internal value (the value in the Internals section of "list
|
||||
device").
|
||||
</li><br>
|
||||
<li>
|
||||
InternalNum(<devicename>,<property>,
|
||||
<defaultvalue>,<round>)<br>
|
||||
Return the first number from an internal value.
|
||||
Round id to <round> devimal places (optional parameter).
|
||||
</li><br>
|
||||
</ul>
|
||||
|
||||
|
||||
|
@ -1153,10 +1153,23 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
||||
<ul>
|
||||
<li>[device:name] mit dem Wert des Readings, Internals oder Attributes
|
||||
für device, falls sowohl device, als auch Reading, Internal oder
|
||||
Attribut existiert, und nicht leer ist. Man kann einen der Prefixe r:, i:
|
||||
oder a: verwenden, um die Suche einzuschraenken, genau wie im devspec.</li>
|
||||
<li>[device:name:d] wie ohne :d, aber alles nicht-numerische wird
|
||||
entfernt.</li>
|
||||
Attribut existiert, und nicht leer ist.
|
||||
<ul>
|
||||
<li>Man kann einen der Präfixe r:, i: oder a: verwenden, um die
|
||||
Suche einzuschränken, genau wie im devspec.</li>
|
||||
<li>Das Suffix :d extrahiert die erste Zahl als Ganzzahl.</li>
|
||||
<li>Das Suffix :r<n> extrahiert die erste Zahl, und rundet sie auf
|
||||
<n> Dezimalstellen. Falls <n> fehlt, dann wird auf eine
|
||||
Dezimalstelle gerundet.</li>
|
||||
<li>Das Suffix :t liefert den Zeitstempel des Readings</li>
|
||||
<li>Das Suffix :sec liefert Anzahl der Sekunden seit Änderung
|
||||
des Readings.</li>
|
||||
</ul>
|
||||
Beispiel:
|
||||
<ul>
|
||||
set Lamp blink [blinkDummy:number] [r:blinkDummy:duration:d]
|
||||
</ul>
|
||||
</lu>
|
||||
<li>{(perlExpression)} mit dem Ergebnis der perlExpression.
|
||||
$DEV wird dabei mit dem Namen des vom set betroffenen Gerätes ersetzt.
|
||||
</li>
|
||||
@ -1784,9 +1797,11 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
||||
dem "Readings"-Abschnitt von "list device" angezeigt wird)
|
||||
</li><br>
|
||||
<li>
|
||||
ReadingsNum(<devicename>,<reading>,<defaultvalue>)<br>
|
||||
Wie ReadingsVal, löscht aber alles, was kein Zahl ist, um den Wert
|
||||
bei Berechnungen verwenden zu können.
|
||||
ReadingsNum(<devicename>,<reading>,
|
||||
<defaultvalue>,<round>)<br>
|
||||
Gibt die erste Zahl aus dem Readingswert zurück.
|
||||
Falls <round> spezifiziert ist, wird sie auf diese Anzahl von
|
||||
Dezimalstellen gerundet.
|
||||
</li><br>
|
||||
<li>ReadingsTimestamp(<devicename>,
|
||||
<reading>,<defaultvalue>)<br>
|
||||
@ -1798,7 +1813,7 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
||||
</li><br>
|
||||
<li>
|
||||
AttrVal(<devicename>,<attribute>,<defaultvalue>)<br>
|
||||
Gibt die gesetzteb Attribute des Gerätes zurück
|
||||
Gibt das entsprechende Attribut des Gerätes zurück
|
||||
<br><br>
|
||||
{ Value("wz") }<br>
|
||||
{ OldValue("wz") }<br>
|
||||
@ -1808,10 +1823,25 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
||||
{ AttrVal("wz", "room", "none") }<br>
|
||||
</li><br>
|
||||
<li>
|
||||
InternalVal(<devicename>,<reading>,<defaultvalue>)<br>
|
||||
AttrNum(<devicename>,<attribute>,
|
||||
<defaultvalue>,<round>)<br>
|
||||
Gibt die erste Zahl aus dem Attributwert zurück.
|
||||
Falls <round> spezifiziert ist, wird sie auf diese Anzahl von
|
||||
Dezimalstellen gerundet.
|
||||
</li><br>
|
||||
<li>
|
||||
InternalVal(<devicename>,<internal>,
|
||||
<defaultvalue>)<br>
|
||||
Gibt den Inhalt der "internal" zurück (den Inhalt der in
|
||||
dem "Internals"-Abschnitt von "list device" angezeigt wird)
|
||||
</li><br>
|
||||
<li>
|
||||
InternalNum(<devicename>,<internal>,
|
||||
<defaultvalue>,<round>)<br>
|
||||
Gibt die erste Zahl aus dem "internal" zurück.
|
||||
Falls <round> spezifiziert ist, wird sie auf diese Anzahl von
|
||||
Dezimalstellen gerundet.
|
||||
</li><br>
|
||||
</ul>
|
||||
|
||||
|
||||
|
47
fhem/fhem.pl
47
fhem/fhem.pl
@ -48,6 +48,7 @@ sub AnalyzeInput($);
|
||||
sub AnalyzePerlCommand($$;$);
|
||||
sub AssignIoPort($;$);
|
||||
sub AttrVal($$$);
|
||||
sub AttrNum($$$;$);
|
||||
sub CallFn(@);
|
||||
sub CallInstanceFn(@);
|
||||
sub CheckDuplicate($$@);
|
||||
@ -70,6 +71,7 @@ sub HandleTimeout();
|
||||
sub IOWrite($@);
|
||||
sub InternalTimer($$$;$);
|
||||
sub InternalVal($$$);
|
||||
sub InternalNum($$$;$);
|
||||
sub IsDevice($;$);
|
||||
sub IsDisabled($);
|
||||
sub IsDummy($);
|
||||
@ -82,7 +84,7 @@ sub OldTimestamp($);
|
||||
sub OldValue($);
|
||||
sub OpenLogfile($);
|
||||
sub PrintHash($$);
|
||||
sub ReadingsNum($$$);
|
||||
sub ReadingsNum($$$;$);
|
||||
sub ReadingsTimestamp($$$);
|
||||
sub ReadingsVal($$$);
|
||||
sub RefreshAuthList();
|
||||
@ -1660,16 +1662,28 @@ ReplaceSetMagic($$@) # Forum #38276
|
||||
return $all if(!$hash);
|
||||
if(!$t || $t eq "r:") {
|
||||
my $r = $hash->{READINGS};
|
||||
if($s && ($s eq ":t" || $s eq ":sec")) {
|
||||
return $all if (!$r || !$r->{$n});
|
||||
$val = $r->{$n}{TIME};
|
||||
$val = time() - time_str2num($val) if($s eq ":sec");
|
||||
return $val;
|
||||
}
|
||||
$val = $r->{$n}{VAL} if($r && $r->{$n});
|
||||
}
|
||||
$val = $hash->{$n} if(!defined($val) && (!$t || $t eq "i:"));
|
||||
$val = $attr{$d}{$n} if(!defined($val) && (!$t || $t eq "a:") && $attr{$d});
|
||||
return $all if(!defined($val));
|
||||
$val =~ s/[^-\.\d]//g if($s);
|
||||
|
||||
if($s && $val =~ /(-?\d+(\.\d+)?)/) {
|
||||
$val = $1;
|
||||
$s = ":r0" if($s eq ":d");
|
||||
$val = round($val, defined($1) ? $1 : 1) if($s =~ /^:r(\d)?/);
|
||||
}
|
||||
return $val;
|
||||
}
|
||||
|
||||
$a=~s/(\[(.:)?([a-z0-9._]+):([a-z0-9._-]+)(:d)?\])/rsmVal($1,$2,$3,$4,$5)/egi;
|
||||
$a =~ s/(\[([ari]:)?([a-z0-9._]+):([a-z0-9._-]+)(:(t|sec|d|r|r\d))?\])/
|
||||
rsmVal($1,$2,$3,$4,$5)/egi;
|
||||
|
||||
$evalSpecials->{'%DEV'} = $hash->{NAME};
|
||||
$a =~ s/{\((.*?)\)}/AnalyzePerlCommand($hash->{CL},$1,1)/egs;
|
||||
@ -3938,6 +3952,16 @@ InternalVal($$$)
|
||||
return $default;
|
||||
}
|
||||
|
||||
sub
|
||||
InternalNum($$$;$)
|
||||
{
|
||||
my ($d,$n,$default,$round) = @_;
|
||||
my $val = InternalVal($d,$n,$default);
|
||||
$val = ($val =~ /(-?\d+(\.\d+)?)/ ? $1 : "");
|
||||
$val = round($val,$round) if($round);
|
||||
return $val;
|
||||
}
|
||||
|
||||
sub
|
||||
ReadingsVal($$$)
|
||||
{
|
||||
@ -3952,11 +3976,12 @@ ReadingsVal($$$)
|
||||
}
|
||||
|
||||
sub
|
||||
ReadingsNum($$$)
|
||||
ReadingsNum($$$;$)
|
||||
{
|
||||
my ($d,$n,$default) = @_;
|
||||
my ($d,$n,$default,$round) = @_;
|
||||
my $val = ReadingsVal($d,$n,$default);
|
||||
$val =~ s/[^-\.\d]//g;
|
||||
$val = ($val =~ /(-?\d+(\.\d+)?)/ ? $1 : "");
|
||||
$val = round($val,$round) if($round);
|
||||
return $val;
|
||||
}
|
||||
|
||||
@ -4017,6 +4042,16 @@ AttrVal($$$)
|
||||
return $default;
|
||||
}
|
||||
|
||||
sub
|
||||
AttrNum($$$;$)
|
||||
{
|
||||
my ($d,$n,$default,$round) = @_;
|
||||
my $val = AttrVal($d,$n,$default);
|
||||
$val = ($val =~ /(-?\d+(\.\d+)?)/ ? $1 : "");
|
||||
$val = round($val,$round) if($round);
|
||||
return $val;
|
||||
}
|
||||
|
||||
################################################################
|
||||
# Functions used by modules.
|
||||
sub
|
||||
|
Loading…
Reference in New Issue
Block a user