mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +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:
|
From featurelevel 5.7 on the set and setreading command replaces:
|
||||||
<ul>
|
<ul>
|
||||||
<li>[device:name] with the reading, internal or attribute of the device, if
|
<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
|
both device and the reading, internal or attribute exists.
|
||||||
r:, i: or a: prefix to restrict the search to one type, analogue to the
|
<ul>
|
||||||
devspec filtering.</li>
|
<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: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.
|
<li>{(perlExpression)} with the result of perlExpression.
|
||||||
The $DEV variable is additionally available, designating the set device
|
The $DEV variable is additionally available, designating the set device
|
||||||
name.
|
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")
|
Return the reading (the value in the Readings section of "list device")
|
||||||
</li><br>
|
</li><br>
|
||||||
<li>
|
<li>
|
||||||
ReadingsNum(<devicename>,<reading>,<defaultvalue>)<br>
|
ReadingsNum(<devicename>,<reading>,
|
||||||
Return the reading as a number, i.e. delete non-numerical values.
|
<defaultvalue>,<round>)<br>
|
||||||
|
Return the first number from a reading value.
|
||||||
|
Round id to <round> devimal places (optional parameter).
|
||||||
</li><br>
|
</li><br>
|
||||||
<li>ReadingsTimestamp(<devicename>,<reading>,<
|
<li>ReadingsTimestamp(<devicename>,<reading>,<
|
||||||
defaultvalue>)<br>
|
defaultvalue>)<br>
|
||||||
@ -1670,12 +1688,24 @@ The following local attributes are used by a wider range of devices:
|
|||||||
{ ReadingsTimestamp("wz", "measured-temp", 0)}<br>
|
{ ReadingsTimestamp("wz", "measured-temp", 0)}<br>
|
||||||
{ AttrVal("wz", "room", "none") }<br>
|
{ AttrVal("wz", "room", "none") }<br>
|
||||||
</li><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>
|
<li>
|
||||||
InternalVal(<devicename>,<property>,<defaultvalue>)
|
InternalVal(<devicename>,<property>,<defaultvalue>)
|
||||||
<br>
|
<br>
|
||||||
Return the internal value (the value in the Internals section of "list
|
Return the internal value (the value in the Internals section of "list
|
||||||
device").
|
device").
|
||||||
</li><br>
|
</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>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
@ -1153,10 +1153,23 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
|||||||
<ul>
|
<ul>
|
||||||
<li>[device:name] mit dem Wert des Readings, Internals oder Attributes
|
<li>[device:name] mit dem Wert des Readings, Internals oder Attributes
|
||||||
für device, falls sowohl device, als auch Reading, Internal oder
|
für device, falls sowohl device, als auch Reading, Internal oder
|
||||||
Attribut existiert, und nicht leer ist. Man kann einen der Prefixe r:, i:
|
Attribut existiert, und nicht leer ist.
|
||||||
oder a: verwenden, um die Suche einzuschraenken, genau wie im devspec.</li>
|
<ul>
|
||||||
<li>[device:name:d] wie ohne :d, aber alles nicht-numerische wird
|
<li>Man kann einen der Präfixe r:, i: oder a: verwenden, um die
|
||||||
entfernt.</li>
|
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.
|
<li>{(perlExpression)} mit dem Ergebnis der perlExpression.
|
||||||
$DEV wird dabei mit dem Namen des vom set betroffenen Gerätes ersetzt.
|
$DEV wird dabei mit dem Namen des vom set betroffenen Gerätes ersetzt.
|
||||||
</li>
|
</li>
|
||||||
@ -1784,9 +1797,11 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
|||||||
dem "Readings"-Abschnitt von "list device" angezeigt wird)
|
dem "Readings"-Abschnitt von "list device" angezeigt wird)
|
||||||
</li><br>
|
</li><br>
|
||||||
<li>
|
<li>
|
||||||
ReadingsNum(<devicename>,<reading>,<defaultvalue>)<br>
|
ReadingsNum(<devicename>,<reading>,
|
||||||
Wie ReadingsVal, löscht aber alles, was kein Zahl ist, um den Wert
|
<defaultvalue>,<round>)<br>
|
||||||
bei Berechnungen verwenden zu können.
|
Gibt die erste Zahl aus dem Readingswert zurück.
|
||||||
|
Falls <round> spezifiziert ist, wird sie auf diese Anzahl von
|
||||||
|
Dezimalstellen gerundet.
|
||||||
</li><br>
|
</li><br>
|
||||||
<li>ReadingsTimestamp(<devicename>,
|
<li>ReadingsTimestamp(<devicename>,
|
||||||
<reading>,<defaultvalue>)<br>
|
<reading>,<defaultvalue>)<br>
|
||||||
@ -1798,7 +1813,7 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
|||||||
</li><br>
|
</li><br>
|
||||||
<li>
|
<li>
|
||||||
AttrVal(<devicename>,<attribute>,<defaultvalue>)<br>
|
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>
|
<br><br>
|
||||||
{ Value("wz") }<br>
|
{ Value("wz") }<br>
|
||||||
{ OldValue("wz") }<br>
|
{ OldValue("wz") }<br>
|
||||||
@ -1808,10 +1823,25 @@ Die folgenden lokalen Attribute werden von mehreren Geräten verwendet:
|
|||||||
{ AttrVal("wz", "room", "none") }<br>
|
{ AttrVal("wz", "room", "none") }<br>
|
||||||
</li><br>
|
</li><br>
|
||||||
<li>
|
<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
|
Gibt den Inhalt der "internal" zurück (den Inhalt der in
|
||||||
dem "Internals"-Abschnitt von "list device" angezeigt wird)
|
dem "Internals"-Abschnitt von "list device" angezeigt wird)
|
||||||
</li><br>
|
</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>
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
47
fhem/fhem.pl
47
fhem/fhem.pl
@ -48,6 +48,7 @@ sub AnalyzeInput($);
|
|||||||
sub AnalyzePerlCommand($$;$);
|
sub AnalyzePerlCommand($$;$);
|
||||||
sub AssignIoPort($;$);
|
sub AssignIoPort($;$);
|
||||||
sub AttrVal($$$);
|
sub AttrVal($$$);
|
||||||
|
sub AttrNum($$$;$);
|
||||||
sub CallFn(@);
|
sub CallFn(@);
|
||||||
sub CallInstanceFn(@);
|
sub CallInstanceFn(@);
|
||||||
sub CheckDuplicate($$@);
|
sub CheckDuplicate($$@);
|
||||||
@ -70,6 +71,7 @@ sub HandleTimeout();
|
|||||||
sub IOWrite($@);
|
sub IOWrite($@);
|
||||||
sub InternalTimer($$$;$);
|
sub InternalTimer($$$;$);
|
||||||
sub InternalVal($$$);
|
sub InternalVal($$$);
|
||||||
|
sub InternalNum($$$;$);
|
||||||
sub IsDevice($;$);
|
sub IsDevice($;$);
|
||||||
sub IsDisabled($);
|
sub IsDisabled($);
|
||||||
sub IsDummy($);
|
sub IsDummy($);
|
||||||
@ -82,7 +84,7 @@ sub OldTimestamp($);
|
|||||||
sub OldValue($);
|
sub OldValue($);
|
||||||
sub OpenLogfile($);
|
sub OpenLogfile($);
|
||||||
sub PrintHash($$);
|
sub PrintHash($$);
|
||||||
sub ReadingsNum($$$);
|
sub ReadingsNum($$$;$);
|
||||||
sub ReadingsTimestamp($$$);
|
sub ReadingsTimestamp($$$);
|
||||||
sub ReadingsVal($$$);
|
sub ReadingsVal($$$);
|
||||||
sub RefreshAuthList();
|
sub RefreshAuthList();
|
||||||
@ -1660,16 +1662,28 @@ ReplaceSetMagic($$@) # Forum #38276
|
|||||||
return $all if(!$hash);
|
return $all if(!$hash);
|
||||||
if(!$t || $t eq "r:") {
|
if(!$t || $t eq "r:") {
|
||||||
my $r = $hash->{READINGS};
|
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 = $r->{$n}{VAL} if($r && $r->{$n});
|
||||||
}
|
}
|
||||||
$val = $hash->{$n} if(!defined($val) && (!$t || $t eq "i:"));
|
$val = $hash->{$n} if(!defined($val) && (!$t || $t eq "i:"));
|
||||||
$val = $attr{$d}{$n} if(!defined($val) && (!$t || $t eq "a:") && $attr{$d});
|
$val = $attr{$d}{$n} if(!defined($val) && (!$t || $t eq "a:") && $attr{$d});
|
||||||
return $all if(!defined($val));
|
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;
|
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};
|
$evalSpecials->{'%DEV'} = $hash->{NAME};
|
||||||
$a =~ s/{\((.*?)\)}/AnalyzePerlCommand($hash->{CL},$1,1)/egs;
|
$a =~ s/{\((.*?)\)}/AnalyzePerlCommand($hash->{CL},$1,1)/egs;
|
||||||
@ -3938,6 +3952,16 @@ InternalVal($$$)
|
|||||||
return $default;
|
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
|
sub
|
||||||
ReadingsVal($$$)
|
ReadingsVal($$$)
|
||||||
{
|
{
|
||||||
@ -3952,11 +3976,12 @@ ReadingsVal($$$)
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub
|
sub
|
||||||
ReadingsNum($$$)
|
ReadingsNum($$$;$)
|
||||||
{
|
{
|
||||||
my ($d,$n,$default) = @_;
|
my ($d,$n,$default,$round) = @_;
|
||||||
my $val = ReadingsVal($d,$n,$default);
|
my $val = ReadingsVal($d,$n,$default);
|
||||||
$val =~ s/[^-\.\d]//g;
|
$val = ($val =~ /(-?\d+(\.\d+)?)/ ? $1 : "");
|
||||||
|
$val = round($val,$round) if($round);
|
||||||
return $val;
|
return $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4017,6 +4042,16 @@ AttrVal($$$)
|
|||||||
return $default;
|
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.
|
# Functions used by modules.
|
||||||
sub
|
sub
|
||||||
|
Loading…
Reference in New Issue
Block a user