mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
$EVENT/$NAME added to notify
git-svn-id: https://svn.fhem.de/fhem/trunk@2982 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
40c33b430e
commit
c03b28b5d0
@ -1,6 +1,7 @@
|
|||||||
# Add changes at the top of the list.
|
# Add changes at the top of the list.
|
||||||
|
|
||||||
- SVN
|
- SVN
|
||||||
|
- feature: notify supports $NAME/$EVENT/$EVTPART0/etc. @/% is deprecated.
|
||||||
- feature: 93_DbLog extended to give more functions for the charting frontend.
|
- feature: 93_DbLog extended to give more functions for the charting frontend.
|
||||||
This includes new queries for raw table data and also statistics,
|
This includes new queries for raw table data and also statistics,
|
||||||
which get sum/max/min/avg values from the database.
|
which get sum/max/min/avg values from the database.
|
||||||
|
@ -127,44 +127,62 @@ notify_Attr(@)
|
|||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
<ul>
|
<ul>
|
||||||
<code>define b3lampV1 notify btn3 set lamp %</code><br>
|
<code>define b3lampV1 notify btn3 set lamp $EVENT</code><br>
|
||||||
<code>define b3lampV2 notify btn3 { fhem "set lamp %" }</code><br>
|
<code>define b3lampV2 notify btn3 { fhem "set lamp $EVENT" }</code><br>
|
||||||
<code>define b3lampV3 notify btn3 "/usr/local/bin/setlamp "%""</code><br>
|
<code>define b3lampV3 notify btn3 "/usr/local/bin/setlamp "$EVENT""</code><br>
|
||||||
<code>define b3lampV3 notify btn3 set lamp1 %;;set lamp2 %</code><br>
|
<code>define b3lampV3 notify btn3 set lamp1 $EVENT;;set lamp2 $EVENT</code><br>
|
||||||
<code>define wzMessLg notify wz:measured.* "/usr/local/bin/logfht @ "%""</code><br>
|
<code>define wzMessLg notify wz:measured.* "/usr/local/bin/logfht $NAME "$EVENT""</code><br>
|
||||||
<!-- <code>define LogHToDB notify .*H:.* {DbLog("@","%")}</code><br> -->
|
<!-- <code>define LogHToDB notify .*H:.* {DbLog("$NAME","$EVENT")}</code><br> -->
|
||||||
<code>define LogUndef notify global:UNDEFINED.* "send-me-mail.sh "%""</code><br>
|
<code>define LogUndef notify global:UNDEFINED.* "send-me-mail.sh "$EVENT""</code><br>
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
<ul>
|
<ul>
|
||||||
<li>The character <code>%</code> will be replaced with the received event,
|
<li><code><pattern></code> is either the name of the triggering
|
||||||
e.g. with <code>on</code> or <code>off</code> or <code>measured-temp: 21.7
|
device, or <code>devicename:event</code>.</li>
|
||||||
(Celsius)</code><br> It is advisable to put the <code>%</code> into double
|
|
||||||
quotes, else the shell may get a syntax error.</li>
|
|
||||||
|
|
||||||
<li>The character <code>@</code> will be replaced with the device
|
|
||||||
name.</li>
|
|
||||||
|
|
||||||
<li>To use % or @ in the text itself, use the double mode (%% or @@).</li>
|
|
||||||
|
|
||||||
<li>Instead of <code>%</code> and <code>@</code>, the parameters
|
|
||||||
<code>%EVENT</code> (same as <code>%</code>), <code>%NAME</code> (same as
|
|
||||||
<code>@</code>) and <code>%TYPE</code> (contains the device type, e.g.
|
|
||||||
<code>FHT</code>) can be used. The space separated event "parts" are
|
|
||||||
available as %EVTPART0, %EVTPART1, etc. A single <code>%</code> looses
|
|
||||||
its special meaning if any of these parameters appears in the
|
|
||||||
definition.</li>
|
|
||||||
|
|
||||||
<li><code><pattern></code> may also be a compound of
|
|
||||||
<code>definition:event</code> to filter for events.</li>
|
|
||||||
|
|
||||||
<li><code><pattern></code> must completely (!)
|
<li><code><pattern></code> must completely (!)
|
||||||
match either the device name, or the compound of the device name and the
|
match either the device name, or the compound of the device name and the
|
||||||
event. The event is either the string you see in the <a
|
event. To identify the events use "inform" command in telnet or "Event
|
||||||
href="#list">list</a> output in paranthesis after the device name, or the
|
Monitor" in FHEMWEB.</li>
|
||||||
string you see when you do a detailed list of the device.</li>
|
<li>in the command section you can access the event:
|
||||||
|
<ul>
|
||||||
|
<li>The variable $EVENT will contain the complete event, e.g.
|
||||||
|
<code>measured-temp: 21.7 (Celsius)</code></li>
|
||||||
|
<li>$EVTPART0,$EVTPART1,$EVTPART2,etc contain the space separated event
|
||||||
|
parts (e.g. <code>$EVTPART0="measured-temp:", $EVTPART1="21.7",
|
||||||
|
$EVTPART2="(Celsius)"</code>. This data is available as a local
|
||||||
|
variable in perl, as environment variable for shell scripts, and will
|
||||||
|
be textually replaced for FHEM commands.</li>
|
||||||
|
<li>$NAME contains the device triggering the event, e.g.
|
||||||
|
<code>myFht</code></li>
|
||||||
|
</ul></li>
|
||||||
|
|
||||||
|
<li>Note: the following is deprecated and will be removed in a future
|
||||||
|
release. The described replacement is attempted if none of the above
|
||||||
|
variables ($NAME/$EVENT/etc) found in the command.
|
||||||
|
<ul>
|
||||||
|
<li>The character <code>%</code> will be replaced with the received
|
||||||
|
event, e.g. with <code>on</code> or <code>off</code> or
|
||||||
|
<code>measured-temp: 21.7 (Celsius)</code><br> It is advisable to put
|
||||||
|
the <code>%</code> into double quotes, else the shell may get a syntax
|
||||||
|
error.</li>
|
||||||
|
|
||||||
|
<li>The character <code>@</code> will be replaced with the device
|
||||||
|
name.</li>
|
||||||
|
|
||||||
|
<li>To use % or @ in the text itself, use the double mode (%% or
|
||||||
|
@@).</li>
|
||||||
|
|
||||||
|
<li>Instead of <code>%</code> and <code>@</code>, the parameters
|
||||||
|
<code>%EVENT</code> (same as <code>%</code>), <code>%NAME</code> (same
|
||||||
|
as <code>@</code>) and <code>%TYPE</code> (contains the device type,
|
||||||
|
e.g. <code>FHT</code>) can be used. The space separated event "parts"
|
||||||
|
are available as %EVTPART0, %EVTPART1, etc. A single <code>%</code>
|
||||||
|
looses its special meaning if any of these parameters appears in the
|
||||||
|
definition.</li>
|
||||||
|
</ul></li>
|
||||||
|
|
||||||
<li>To use database logging, copy the file contrib/91_DbLog.pm into your
|
<li>To use database logging, copy the file contrib/91_DbLog.pm into your
|
||||||
modules directory, and change the $dbconn parameter in the file.</li>
|
modules directory, and change the $dbconn parameter in the file.</li>
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
|
|
||||||
|
# MAXWI
|
||||||
|
# With pre: 1320, without 1020 (content only)
|
||||||
|
# pre { white-space: pre-wrap; } : 900
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
|
|
||||||
@ -80,11 +84,6 @@ foreach my $lang (@lang) {
|
|||||||
$skip = 1;
|
$skip = 1;
|
||||||
|
|
||||||
} elsif(!$skip) {
|
} elsif(!$skip) {
|
||||||
# here we copy line by line from the module
|
|
||||||
# if($l =~ m/<.?pre>/) {
|
|
||||||
# print "$lang $mod REMOVING <pre> Formatting\n";
|
|
||||||
# $l =~ s/<.?pre>//g;
|
|
||||||
# }
|
|
||||||
print OUT $l;
|
print OUT $l;
|
||||||
$docCount++;
|
$docCount++;
|
||||||
$hasLink = ($l =~ m/<a name="$mod">/) if(!$hasLink);
|
$hasLink = ($l =~ m/<a name="$mod">/) if(!$hasLink);
|
||||||
|
46
fhem/fhem.pl
46
fhem/fhem.pl
@ -53,6 +53,7 @@ sub CheckDuplicate($$);
|
|||||||
sub CommandChain($$);
|
sub CommandChain($$);
|
||||||
sub Dispatch($$$);
|
sub Dispatch($$$);
|
||||||
sub DoTrigger($$@);
|
sub DoTrigger($$@);
|
||||||
|
sub EvalSpecials($%);
|
||||||
sub EventMapAsList($);
|
sub EventMapAsList($);
|
||||||
sub FmtDateTime($);
|
sub FmtDateTime($);
|
||||||
sub FmtTime($);
|
sub FmtTime($);
|
||||||
@ -194,6 +195,7 @@ my $namedef =
|
|||||||
my $stt_sec; # Used by SecondsTillTomorrow()
|
my $stt_sec; # Used by SecondsTillTomorrow()
|
||||||
my $stt_day; # Used by SecondsTillTomorrow()
|
my $stt_day; # Used by SecondsTillTomorrow()
|
||||||
my @cmdList; # Remaining commands in a chain. Used by sleep
|
my @cmdList; # Remaining commands in a chain. Used by sleep
|
||||||
|
my $evalSpecials; # Used by EvalSpecials->AnalyzeCommand parameter passing
|
||||||
|
|
||||||
$init_done = 0;
|
$init_done = 0;
|
||||||
|
|
||||||
@ -651,6 +653,7 @@ AnalyzeCommandChain($$)
|
|||||||
push(@ret, $lret) if(defined($lret));
|
push(@ret, $lret) if(defined($lret));
|
||||||
}
|
}
|
||||||
@cmdList = @saveCmdList;
|
@cmdList = @saveCmdList;
|
||||||
|
$evalSpecials = undef;
|
||||||
return join("\n", @ret) if(@ret);
|
return join("\n", @ret) if(@ret);
|
||||||
return undef;
|
return undef;
|
||||||
}
|
}
|
||||||
@ -662,6 +665,7 @@ AnalyzePerlCommand($$)
|
|||||||
my ($cl, $cmd) = @_;
|
my ($cl, $cmd) = @_;
|
||||||
|
|
||||||
$cmd =~ s/\\ *\n/ /g; # Multi-line
|
$cmd =~ s/\\ *\n/ /g; # Multi-line
|
||||||
|
|
||||||
# Make life easier for oneliners:
|
# Make life easier for oneliners:
|
||||||
%value = ();
|
%value = ();
|
||||||
foreach my $d (keys %defs) {
|
foreach my $d (keys %defs) {
|
||||||
@ -675,6 +679,19 @@ AnalyzePerlCommand($$)
|
|||||||
}
|
}
|
||||||
$month++;
|
$month++;
|
||||||
$year+=1900;
|
$year+=1900;
|
||||||
|
|
||||||
|
if($evalSpecials) {
|
||||||
|
$cmd = join("", map { my $n = substr($_,1);
|
||||||
|
my $v = $evalSpecials->{$_};
|
||||||
|
$v =~ s/(['\\])/\\$1/g;
|
||||||
|
"my \$$n='$v';";
|
||||||
|
} keys %{$evalSpecials})
|
||||||
|
. $cmd;
|
||||||
|
# Normally this is deleted in AnalyzeCommandChain, but ECMDDevice calls us
|
||||||
|
# directly, and combining perl with something else isnt allowed anyway.
|
||||||
|
$evalSpecials = undef;
|
||||||
|
}
|
||||||
|
|
||||||
my $ret = eval $cmd;
|
my $ret = eval $cmd;
|
||||||
$ret = $@ if($@);
|
$ret = $@ if($@);
|
||||||
return $ret;
|
return $ret;
|
||||||
@ -696,6 +713,9 @@ AnalyzeCommand($$)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if($cmd =~ m/^"(.*)"$/s) { # Shell code in bg, to be able to call us from it
|
if($cmd =~ m/^"(.*)"$/s) { # Shell code in bg, to be able to call us from it
|
||||||
|
if($evalSpecials) {
|
||||||
|
map { $ENV{substr($_,1)} = $evalSpecials->{$_}; } keys %{$evalSpecials};
|
||||||
|
}
|
||||||
my $out = "";
|
my $out = "";
|
||||||
$out = ">> $currlogfile 2>&1" if($currlogfile ne "-" && $^O ne "MSWin32");
|
$out = ">> $currlogfile 2>&1" if($currlogfile ne "-" && $^O ne "MSWin32");
|
||||||
system("$1 $out &");
|
system("$1 $out &");
|
||||||
@ -703,6 +723,10 @@ AnalyzeCommand($$)
|
|||||||
}
|
}
|
||||||
|
|
||||||
$cmd =~ s/^[ \t]*//;
|
$cmd =~ s/^[ \t]*//;
|
||||||
|
if($evalSpecials) {
|
||||||
|
map { my $n = substr($_,1); my $v = $evalSpecials->{$_};
|
||||||
|
$cmd =~ s/\$$n/$v/g; } keys %{$evalSpecials};
|
||||||
|
}
|
||||||
my ($fn, $param) = split("[ \t][ \t]*", $cmd, 2);
|
my ($fn, $param) = split("[ \t][ \t]*", $cmd, 2);
|
||||||
return undef if(!$fn);
|
return undef if(!$fn);
|
||||||
|
|
||||||
@ -710,7 +734,7 @@ AnalyzeCommand($$)
|
|||||||
# Search for abbreviation
|
# Search for abbreviation
|
||||||
if(!defined($cmds{$fn})) {
|
if(!defined($cmds{$fn})) {
|
||||||
foreach my $f (sort keys %cmds) {
|
foreach my $f (sort keys %cmds) {
|
||||||
if(length($f) > length($fn) && lc(substr($f, 0, length($fn))) eq lc($fn)) {
|
if(length($f) > length($fn) && lc(substr($f,0,length($fn))) eq lc($fn)) {
|
||||||
Log 5, "$fn => $f";
|
Log 5, "$fn => $f";
|
||||||
$fn = $f;
|
$fn = $f;
|
||||||
last;
|
last;
|
||||||
@ -2008,7 +2032,8 @@ CommandSleep($$)
|
|||||||
Log 4, "sleeping for $param";
|
Log 4, "sleeping for $param";
|
||||||
|
|
||||||
if(!$cl && @cmdList && $param && $init_done) {
|
if(!$cl && @cmdList && $param && $init_done) {
|
||||||
InternalTimer(gettimeofday()+$param, "WakeUpFn", join(";", @cmdList), 0);
|
my %h = (cmd=>join(";", @cmdList), evalSpecials=>$evalSpecials);
|
||||||
|
InternalTimer(gettimeofday()+$param, "WakeUpFn", \%h, 0);
|
||||||
@cmdList=();
|
@cmdList=();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -2021,8 +2046,9 @@ CommandSleep($$)
|
|||||||
sub
|
sub
|
||||||
WakeUpFn($)
|
WakeUpFn($)
|
||||||
{
|
{
|
||||||
my $param = shift;
|
my $h = shift;
|
||||||
my $ret = AnalyzeCommandChain(undef, $param);
|
$evalSpecials = $h->{evalSpecials};
|
||||||
|
my $ret = AnalyzeCommandChain(undef, $h->{cmd});
|
||||||
Log 2, "After sleep: $ret" if($ret);
|
Log 2, "After sleep: $ret" if($ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2193,8 +2219,6 @@ EvalSpecials($%)
|
|||||||
my ($exec, %specials)= @_;
|
my ($exec, %specials)= @_;
|
||||||
$exec = SemicolonEscape($exec);
|
$exec = SemicolonEscape($exec);
|
||||||
|
|
||||||
$exec =~ s/%%/____/g;
|
|
||||||
|
|
||||||
# %EVTPART due to HM remote logic
|
# %EVTPART due to HM remote logic
|
||||||
my $idx = 0;
|
my $idx = 0;
|
||||||
if(defined($specials{"%EVENT"})) {
|
if(defined($specials{"%EVENT"})) {
|
||||||
@ -2204,6 +2228,16 @@ EvalSpecials($%)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $re = join("|", keys %specials);
|
||||||
|
$re =~ s/%//g;
|
||||||
|
if($exec =~ m/\$($re)\b/) {
|
||||||
|
$evalSpecials = \%specials;
|
||||||
|
return $exec;
|
||||||
|
}
|
||||||
|
|
||||||
|
$exec =~ s/%%/____/g;
|
||||||
|
|
||||||
|
|
||||||
# perform macro substitution
|
# perform macro substitution
|
||||||
my $extsyntax= 0;
|
my $extsyntax= 0;
|
||||||
foreach my $special (keys %specials) {
|
foreach my $special (keys %specials) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user