2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +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:
rudolfkoenig 2013-03-24 17:47:28 +00:00
parent 40c33b430e
commit c03b28b5d0
4 changed files with 94 additions and 42 deletions

View File

@ -1,6 +1,7 @@
# Add changes at the top of the list.
- SVN
- feature: notify supports $NAME/$EVENT/$EVTPART0/etc. @/% is deprecated.
- feature: 93_DbLog extended to give more functions for the charting frontend.
This includes new queries for raw table data and also statistics,
which get sum/max/min/avg values from the database.

View File

@ -127,44 +127,62 @@ notify_Attr(@)
Examples:
<ul>
<code>define b3lampV1 notify btn3 set lamp %</code><br>
<code>define b3lampV2 notify btn3 { fhem "set lamp %" }</code><br>
<code>define b3lampV3 notify btn3 "/usr/local/bin/setlamp "%""</code><br>
<code>define b3lampV3 notify btn3 set lamp1 %;;set lamp2 %</code><br>
<code>define wzMessLg notify wz:measured.* "/usr/local/bin/logfht @ "%""</code><br>
<!-- <code>define LogHToDB notify .*H:.* {DbLog("@","%")}</code><br> -->
<code>define LogUndef notify global:UNDEFINED.* "send-me-mail.sh "%""</code><br>
<code>define b3lampV1 notify btn3 set lamp $EVENT</code><br>
<code>define b3lampV2 notify btn3 { fhem "set lamp $EVENT" }</code><br>
<code>define b3lampV3 notify btn3 "/usr/local/bin/setlamp "$EVENT""</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 $NAME "$EVENT""</code><br>
<!-- <code>define LogHToDB notify .*H:.* {DbLog("$NAME","$EVENT")}</code><br> -->
<code>define LogUndef notify global:UNDEFINED.* "send-me-mail.sh "$EVENT""</code><br>
</ul>
<br>
Notes:
<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>
<li><code>&lt;pattern&gt;</code> may also be a compound of
<code>definition:event</code> to filter for events.</li>
<li><code>&lt;pattern&gt;</code> is either the name of the triggering
device, or <code>devicename:event</code>.</li>
<li><code>&lt;pattern&gt;</code> must completely (!)
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
href="#list">list</a> output in paranthesis after the device name, or the
string you see when you do a detailed list of the device.</li>
match either the device name, or the compound of the device name and the
event. To identify the events use "inform" command in telnet or "Event
Monitor" in FHEMWEB.</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
modules directory, and change the $dbconn parameter in the file.</li>

View File

@ -1,5 +1,9 @@
#!/usr/bin/perl
# MAXWI
# With pre: 1320, without 1020 (content only)
# pre { white-space: pre-wrap; } : 900
use strict;
use warnings;
@ -80,11 +84,6 @@ foreach my $lang (@lang) {
$skip = 1;
} 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;
$docCount++;
$hasLink = ($l =~ m/<a name="$mod">/) if(!$hasLink);

View File

@ -53,6 +53,7 @@ sub CheckDuplicate($$);
sub CommandChain($$);
sub Dispatch($$$);
sub DoTrigger($$@);
sub EvalSpecials($%);
sub EventMapAsList($);
sub FmtDateTime($);
sub FmtTime($);
@ -194,6 +195,7 @@ my $namedef =
my $stt_sec; # Used by SecondsTillTomorrow()
my $stt_day; # Used by SecondsTillTomorrow()
my @cmdList; # Remaining commands in a chain. Used by sleep
my $evalSpecials; # Used by EvalSpecials->AnalyzeCommand parameter passing
$init_done = 0;
@ -651,6 +653,7 @@ AnalyzeCommandChain($$)
push(@ret, $lret) if(defined($lret));
}
@cmdList = @saveCmdList;
$evalSpecials = undef;
return join("\n", @ret) if(@ret);
return undef;
}
@ -662,6 +665,7 @@ AnalyzePerlCommand($$)
my ($cl, $cmd) = @_;
$cmd =~ s/\\ *\n/ /g; # Multi-line
# Make life easier for oneliners:
%value = ();
foreach my $d (keys %defs) {
@ -675,6 +679,19 @@ AnalyzePerlCommand($$)
}
$month++;
$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;
$ret = $@ if($@);
return $ret;
@ -696,6 +713,9 @@ AnalyzeCommand($$)
}
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 = "";
$out = ">> $currlogfile 2>&1" if($currlogfile ne "-" && $^O ne "MSWin32");
system("$1 $out &");
@ -703,6 +723,10 @@ AnalyzeCommand($$)
}
$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);
return undef if(!$fn);
@ -710,7 +734,7 @@ AnalyzeCommand($$)
# Search for abbreviation
if(!defined($cmds{$fn})) {
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";
$fn = $f;
last;
@ -2008,7 +2032,8 @@ CommandSleep($$)
Log 4, "sleeping for $param";
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=();
} else {
@ -2021,8 +2046,9 @@ CommandSleep($$)
sub
WakeUpFn($)
{
my $param = shift;
my $ret = AnalyzeCommandChain(undef, $param);
my $h = shift;
$evalSpecials = $h->{evalSpecials};
my $ret = AnalyzeCommandChain(undef, $h->{cmd});
Log 2, "After sleep: $ret" if($ret);
}
@ -2193,8 +2219,6 @@ EvalSpecials($%)
my ($exec, %specials)= @_;
$exec = SemicolonEscape($exec);
$exec =~ s/%%/____/g;
# %EVTPART due to HM remote logic
my $idx = 0;
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
my $extsyntax= 0;
foreach my $special (keys %specials) {