91_notify.pm 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. ##############################################
  2. # $Id: 91_notify.pm 13207 2017-01-23 13:55:25Z rudolfkoenig $
  3. package main;
  4. use strict;
  5. use warnings;
  6. use vars qw($FW_ME); # webname (default is fhem)
  7. #####################################
  8. sub
  9. notify_Initialize($)
  10. {
  11. my ($hash) = @_;
  12. $hash->{DefFn} = "notify_Define";
  13. $hash->{NotifyFn} = "notify_Exec";
  14. $hash->{AttrFn} = "notify_Attr";
  15. $hash->{AttrList} ="disable:1,0 disabledForIntervals forwardReturnValue:1,0 ".
  16. "readLog:1,0 showtime:1,0 addStateEvent:1,0";
  17. $hash->{SetFn} = "notify_Set";
  18. $hash->{StateFn} = "notify_State";
  19. $hash->{FW_detailFn} = "notify_fhemwebFn";
  20. }
  21. #####################################
  22. sub
  23. notify_Define($$)
  24. {
  25. my ($hash, $def) = @_;
  26. my ($name, $type, $re, $command) = split("[ \t]+", $def, 4);
  27. if(!$command) {
  28. if($hash->{OLDDEF}) { # Called from modify, where command is optional
  29. (undef, $command) = split("[ \t]+", $hash->{OLDDEF}, 2);
  30. $hash->{DEF} = "$re $command";
  31. } else {
  32. return "Usage: define <name> notify <regexp> <command>";
  33. }
  34. }
  35. # Checking for misleading regexps
  36. return "Bad regexp: starting with *" if($re =~ m/^\*/);
  37. eval { "Hallo" =~ m/^$re$/ };
  38. return "Bad regexp: $@" if($@);
  39. $hash->{REGEXP} = $re;
  40. my %specials= (
  41. "%NAME" => $name,
  42. "%TYPE" => $name,
  43. "%EVENT" => "1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0",
  44. "%SELF" => $name,
  45. );
  46. my $err = perlSyntaxCheck($command, %specials);
  47. return $err if($err);
  48. $hash->{".COMMAND"} = $command;
  49. my $doTrigger = ($name !~ m/^$re$/); # Forum #34516
  50. readingsSingleUpdate($hash, "state", "active", $doTrigger);
  51. notifyRegexpChanged($hash, $re);
  52. return undef;
  53. }
  54. #####################################
  55. sub
  56. notify_Exec($$)
  57. {
  58. my ($ntfy, $dev) = @_;
  59. my $ln = $ntfy->{NAME};
  60. return "" if(IsDisabled($ln));
  61. my $n = $dev->{NAME};
  62. my $re = $ntfy->{REGEXP};
  63. my $events = deviceEvents($dev, AttrVal($ln, "addStateEvent", 0));
  64. return if(!$events); # Some previous notify deleted the array.
  65. my $max = int(@{$events});
  66. my $t = $dev->{TYPE};
  67. my $ret = "";
  68. for (my $i = 0; $i < $max; $i++) {
  69. my $s = $events->[$i];
  70. $s = "" if(!defined($s));
  71. my $found = ($n =~ m/^$re$/ || "$n:$s" =~ m/^$re$/);
  72. if(!$found && AttrVal($n, "eventMap", undef)) {
  73. my @res = ReplaceEventMap($n, [$n,$s], 0);
  74. shift @res;
  75. $s = join(" ", @res);
  76. $found = ("$n:$s" =~ m/^$re$/);
  77. }
  78. if($found) {
  79. Log3 $ln, 5, "Triggering $ln";
  80. my %specials= (
  81. "%NAME" => $n,
  82. "%TYPE" => $t,
  83. "%EVENT" => $s,
  84. "%SELF" => $ln
  85. );
  86. my $exec = EvalSpecials($ntfy->{".COMMAND"}, %specials);
  87. Log3 $ln, 4, "$ln exec $exec";
  88. my $r = AnalyzeCommandChain(undef, $exec);
  89. Log3 $ln, 3, "$ln return value: $r" if($r);
  90. $ret .= " $r" if($r);
  91. $ntfy->{STATE} =
  92. AttrVal($ln,'showtime',1) ? $dev->{NTFY_TRIGGERTIME} : 'active';
  93. }
  94. }
  95. return $ret if(AttrVal($ln, "forwardReturnValue", 0));
  96. return undef;
  97. }
  98. sub
  99. notify_Attr(@)
  100. {
  101. my @a = @_;
  102. my $do = 0;
  103. my $hash = $defs{$a[1]};
  104. if($a[0] eq "set" && $a[2] eq "readLog") {
  105. if(!defined($a[3]) || $a[3]) {
  106. $logInform{$a[1]} = sub($$){
  107. my ($me, $msg) = @_;
  108. return if(defined($hash->{CHANGED}));
  109. $hash->{CHANGED}[0] = $msg;
  110. notify_Exec($hash, $hash);
  111. delete($hash->{CHANGED});
  112. }
  113. } else {
  114. delete $logInform{$a[1]};
  115. }
  116. return;
  117. }
  118. if($a[0] eq "set" && $a[2] eq "disable") {
  119. $do = (!defined($a[3]) || $a[3]) ? 1 : 2;
  120. }
  121. $do = 2 if($a[0] eq "del" && (!$a[2] || $a[2] eq "disable"));
  122. return if(!$do);
  123. readingsSingleUpdate($hash, "state", $do==1 ? "disabled":"active", 1);
  124. return undef;
  125. }
  126. ###################################
  127. sub
  128. notify_Set($@)
  129. {
  130. my ($hash, @a) = @_;
  131. my $me = $hash->{NAME};
  132. return "no set argument specified" if(int(@a) < 2);
  133. my %sets = (addRegexpPart=>2, removeRegexpPart=>1, inactive=>0, active=>0);
  134. my $cmd = $a[1];
  135. if(!defined($sets{$cmd})) {
  136. my $ret ="Unknown argument $cmd, choose one of ".join(" ", sort keys %sets);
  137. $ret =~ s/active/active:noArg/g;
  138. return $ret;
  139. }
  140. return "$cmd needs $sets{$cmd} parameter(s)" if(@a-$sets{$cmd} != 2);
  141. if($cmd eq "addRegexpPart") {
  142. my %h;
  143. my $re = "$a[2]:$a[3]";
  144. map { $h{$_} = 1 } split(/\|/, $hash->{REGEXP});
  145. $h{$re} = 1;
  146. $re = join("|", sort keys %h);
  147. return "Bad regexp: starting with *" if($re =~ m/^\*/);
  148. eval { "Hallo" =~ m/^$re$/ };
  149. return "Bad regexp: $@" if($@);
  150. $hash->{REGEXP} = $re;
  151. $hash->{DEF} = "$re ".$hash->{".COMMAND"};
  152. notifyRegexpChanged($hash, $re);
  153. } elsif($cmd eq "removeRegexpPart") {
  154. my %h;
  155. map { $h{$_} = 1 } split(/\|/, $hash->{REGEXP});
  156. return "Cannot remove regexp part: not found" if(!$h{$a[2]});
  157. return "Cannot remove last regexp part" if(int(keys(%h)) == 1);
  158. delete $h{$a[2]};
  159. my $re = join("|", sort keys %h);
  160. return "Bad regexp: starting with *" if($re =~ m/^\*/);
  161. eval { "Hallo" =~ m/^$re$/ };
  162. return "Bad regexp: $@" if($@);
  163. $hash->{REGEXP} = $re;
  164. $hash->{DEF} = "$re ".$hash->{".COMMAND"};
  165. notifyRegexpChanged($hash, $re);
  166. } elsif($cmd eq "inactive") {
  167. readingsSingleUpdate($hash, "state", "inactive", 1);
  168. }
  169. elsif($cmd eq "active") {
  170. readingsSingleUpdate($hash, "state", "active", 1)
  171. if(!AttrVal($me, "disable", undef));
  172. }
  173. return undef;
  174. }
  175. #############
  176. sub
  177. notify_State($$$$)
  178. {
  179. my ($hash, $tim, $vt, $val) = @_;
  180. return undef if($vt ne "state" || $val ne "inactive");
  181. readingsSingleUpdate($hash, "state", "inactive", 1);
  182. return undef;
  183. }
  184. #########################
  185. sub
  186. notify_fhemwebFn($$$$)
  187. {
  188. my ($FW_wname, $d, $room, $pageHash) = @_; # pageHash is set for summaryFn.
  189. my $hash = $defs{$d};
  190. my $ret .= "<br>Regexp wizard";
  191. my $row=0;
  192. $ret .= "<br><table class=\"block wide\">";
  193. my @ra = split(/\|/, $hash->{REGEXP});
  194. if(@ra > 1) {
  195. foreach my $r (@ra) {
  196. $ret .= "<tr class=\"".(($row++&1)?"odd":"even")."\">";
  197. my $cmd = "cmd.X= set $d removeRegexpPart&val.X=$r"; # =.set: avoid JS
  198. $ret .= "<td>$r</td>";
  199. $ret .= FW_pH("$cmd&detail=$d", "removeRegexpPart", 1,undef,1);
  200. $ret .= "</tr>";
  201. }
  202. }
  203. my @et = devspec2array("TYPE=eventTypes");
  204. if(!@et) {
  205. $ret .= FW_pH("$FW_ME/docs/commandref.html#eventTypes",
  206. "To add a regexp an eventTypes definition is needed",
  207. 1, undef, 1);
  208. } else {
  209. my %dh;
  210. my $etList = AnalyzeCommand(undef, "get $et[0] list");
  211. $etList = "" if(!$etList);
  212. foreach my $l (split("\n", $etList)) {
  213. my @a = split(/[ \r\n]/, $l);
  214. $a[1] = "" if(!defined($a[1]));
  215. $a[1] =~ s/\.\*//g;
  216. $a[1] =~ s/,.*//g;
  217. next if(@a < 2);
  218. $dh{$a[0]}{".*"} = 1;
  219. $dh{$a[0]}{$a[1].".*"} = 1;
  220. }
  221. my $list = "";
  222. foreach my $dev (sort keys %dh) {
  223. $list .= " $dev:" . join(",", sort keys %{$dh{$dev}});
  224. }
  225. $list =~ s/(['"])/./g;
  226. $ret .= "<tr class=\"".(($row++&1)?"odd":"even")."\">";
  227. $ret .= '<td colspan="2">';
  228. $ret .= FW_detailSelect($d, "set", $list, "addRegexpPart");
  229. $ret .= "</td></tr>";
  230. }
  231. $ret .= "</table>";
  232. return $ret;
  233. }
  234. 1;
  235. =pod
  236. =item helper
  237. =item summary execute a command upon receiving an event
  238. =item summary_DE f&uuml;hrt bei Events Anweisungen aus
  239. =begin html
  240. <a name="notify"></a>
  241. <h3>notify</h3>
  242. <ul>
  243. <br>
  244. <a name="notifydefine"></a>
  245. <b>Define</b>
  246. <ul>
  247. <code>define &lt;name&gt; notify &lt;pattern&gt; &lt;command&gt;</code>
  248. <br><br>
  249. Execute a command when received an event for the <a
  250. href="#define">definition</a> <code>&lt;pattern&gt;</code>. If
  251. &lt;command&gt; is enclosed in {}, then it is a perl expression, if it is
  252. enclosed in "", then it is a shell command, else it is a "plain" fhem.pl
  253. command (chain). See the <a href="#trigger">trigger</a> command for
  254. testing it.
  255. Examples:
  256. <ul>
  257. <code>define b3lampV1 notify btn3 set lamp $EVENT</code><br>
  258. <code>define b3lampV2 notify btn3 { fhem "set lamp $EVENT" }</code><br>
  259. <code>define b3lampV3 notify btn3 "/usr/local/bin/setlamp "$EVENT""</code><br>
  260. <code>define b3lampV3 notify btn3 set lamp1 $EVENT;;set lamp2 $EVENT</code><br>
  261. <code>define wzMessLg notify wz:measured.* "/usr/local/bin/logfht $NAME "$EVENT""</code><br>
  262. <code>define LogUndef notify global:UNDEFINED.* "send-me-mail.sh "$EVENT""</code><br>
  263. </ul>
  264. <br>
  265. Notes:
  266. <ul>
  267. <li><code>&lt;pattern&gt;</code> is either the name of the triggering
  268. device, or <code>devicename:event</code>.</li>
  269. <li><code>&lt;pattern&gt;</code> must completely (!)
  270. match either the device name, or the compound of the device name and
  271. the event. To identify the events use the inform command from the
  272. telnet prompt or the "Event Monitor" link in the browser
  273. (FHEMWEB), and wait for the event to be printed. See also the
  274. eventTypes device.</li>
  275. <li>in the command section you can access the event:
  276. <ul>
  277. <li>The variable $EVENT will contain the complete event, e.g.
  278. <code>measured-temp: 21.7 (Celsius)</code></li>
  279. <li>$EVTPART0,$EVTPART1,$EVTPART2,etc contain the space separated event
  280. parts (e.g. <code>$EVTPART0="measured-temp:", $EVTPART1="21.7",
  281. $EVTPART2="(Celsius)"</code>. This data is available as a local
  282. variable in perl, as environment variable for shell scripts, and will
  283. be textually replaced for FHEM commands.</li>
  284. <li>$NAME and $TYPE contain the name and type of the device triggering
  285. the event, e.g. myFht and FHT</li>
  286. </ul></li>
  287. <li>Note: the following is deprecated and will be removed in a future
  288. release. It is only active for featurelevel up to 5.6.
  289. The described replacement is attempted if none of the above
  290. variables ($NAME/$EVENT/etc) found in the command.
  291. <ul>
  292. <li>The character <code>%</code> will be replaced with the received
  293. event, e.g. with <code>on</code> or <code>off</code> or
  294. <code>measured-temp: 21.7 (Celsius)</code><br> It is advisable to put
  295. the <code>%</code> into double quotes, else the shell may get a syntax
  296. error.</li>
  297. <li>The character @ will be replaced with the device
  298. name.</li>
  299. <li>To use % or @ in the text itself, use the double mode (%% or
  300. @@).</li>
  301. <li>Instead of % and @, the parameters %EVENT (same as %), %NAME (same
  302. as @) and %TYPE (contains the device type,
  303. e.g. FHT) can be used. The space separated event "parts"
  304. are available as %EVTPART0, %EVTPART1, etc. A single %
  305. looses its special meaning if any of these parameters appears in the
  306. definition.</li>
  307. </ul></li>
  308. <li>Following special events will be generated for the device "global"
  309. <ul>
  310. <li>INITIALIZED after initialization is finished.</li>
  311. <li>REREADCFG after the configuration is reread.</li>
  312. <li>SAVE before the configuration is saved.</li>
  313. <li>SHUTDOWN before FHEM is shut down.</li>
  314. <li>DEFINED &lt;devname&gt; after a device is defined.</li>
  315. <li>DELETED &lt;devname&gt; after a device was deleted.</li>
  316. <li>RENAMED &lt;old&gt; &lt;new&gt; after a device was renamed.</li>
  317. <li>UNDEFINED &lt;defspec&gt; upon reception of a message for an
  318. undefined device.</li>
  319. </ul></li>
  320. <li>Notify can be used to store macros for manual execution. Use the <a
  321. href="#trigger">trigger</a> command to execute the macro.
  322. E.g.<br>
  323. <code>fhem> define MyMacro notify MyMacro { Log 1, "Hello"}</code><br>
  324. <code>fhem> trigger MyMacro</code><br>
  325. </li>
  326. </ul>
  327. </ul>
  328. <br>
  329. <a name="notifyset"></a>
  330. <b>Set </b>
  331. <ul>
  332. <li>addRegexpPart &lt;device&gt; &lt;regexp&gt;<br>
  333. add a regexp part, which is constructed as device:regexp. The parts
  334. are separated by |. Note: as the regexp parts are resorted, manually
  335. constructed regexps may become invalid. </li>
  336. <li>removeRegexpPart &lt;re&gt;<br>
  337. remove a regexp part. Note: as the regexp parts are resorted, manually
  338. constructed regexps may become invalid.<br>
  339. The inconsistency in addRegexpPart/removeRegexPart arguments originates
  340. from the reusage of javascript functions.</li>
  341. <li>inactive<br>
  342. Inactivates the current device. Note the slight difference to the
  343. disable attribute: using set inactive the state is automatically saved
  344. to the statefile on shutdown, there is no explicit save necesary.<br>
  345. This command is intended to be used by scripts to temporarily
  346. deactivate the notify.<br>
  347. The concurrent setting of the disable attribute is not recommended.</li>
  348. <li>active<br>
  349. Activates the current device (see inactive).</li>
  350. </ul>
  351. <br>
  352. <a name="notifyget"></a>
  353. <b>Get</b> <ul>N/A</ul><br>
  354. <a name="notifyattr"></a>
  355. <b>Attributes</b>
  356. <ul>
  357. <li><a href="#disable">disable</a></li>
  358. <li><a href="#disabledForIntervals">disabledForIntervals</a></li>
  359. <a name="addStateEvent"></a>
  360. <li>addStateEvent<br>
  361. The event associated with the state Reading is special, as the "state: "
  362. string is stripped, i.e $EVENT is not "state: on" but just "on". In some
  363. circumstances it is desireable to get the event without "state: "
  364. stripped. In such a case the addStateEvent attribute should be set to 1
  365. (default is 0, i.e. strip the "state: " string).<br>
  366. Note 1: you have to set this attribute for the event "receiver", i.e.
  367. notify, FileLog, etc.<br>
  368. Note 2: this attribute will only work for events generated by devices
  369. supporting the <a href="#readingFnAttributes">readingFnAttributes</a>.
  370. </li>
  371. <a name="forwardReturnValue"></a>
  372. <li>forwardReturnValue<br>
  373. Forward the return value of the executed command to the caller,
  374. default is disabled (0). If enabled (1), then e.g. a set command which
  375. triggers this notify will also return this value. This can cause e.g
  376. FHEMWEB to display this value, when clicking "on" or "off", which is
  377. often not intended.</li>
  378. <a name="readLog"></a>
  379. <li>readLog<br>
  380. Execute the notify for messages appearing in the FHEM Log. The device
  381. in this case is set to the notify itself, e.g. checking for the startup
  382. message looks like:
  383. <ul><code>
  384. define n notify n:.*Server.started.* { Log 1, "Really" }<br>
  385. attr n readLog
  386. </code></ul>
  387. </li>
  388. <a name="perlSyntaxCheck"></a>
  389. <li>perlSyntaxCheck<br>
  390. by setting the <b>global</b> attribute perlSyntaxCheck, a syntax check
  391. will be executed upon definition or modification, if the command is
  392. perl and FHEM is already started.
  393. </li>
  394. </ul>
  395. <br>
  396. </ul>
  397. =end html
  398. =begin html_DE
  399. <a name="notify"></a>
  400. <h3>notify</h3>
  401. <ul>
  402. <br>
  403. <a name="notifydefine"></a>
  404. <b>Define</b>
  405. <ul>
  406. <code>define &lt;name&gt; notify &lt;Suchmuster&gt; &lt;Anweisung&gt;</code>
  407. <br><br>
  408. F&uuml;hrt eine oder mehrere Anweisungen aus, wenn ein Event generiert
  409. wurde, was dem &lt;Suchmuster&gt; (Ger&auml;tename oder
  410. Ger&auml;tename:Event) entspricht.
  411. Die Anweisung ist einer der FHEM <a href="#command">Befehlstypen</a>.
  412. Zum Test dient das <a href="#trigger">trigger</a>-Kommando.
  413. <br><br>
  414. Beispiele:
  415. <ul>
  416. <code>define b3lampV1 notify btn3 set lamp $EVENT</code><br>
  417. <code>define b3lampV2 notify btn3 { fhem "set lamp $EVENT" }</code><br>
  418. <code>define b3lampV3 notify btn3 "/usr/local/bin/setlamp
  419. "$EVENT""</code><br>
  420. <code>define b3lampV3 notify btn3 set lamp1 $EVENT;;set lamp2
  421. $EVENT</code><br>
  422. <code>define wzMessLg notify wz:measured.* "/usr/local/bin/logfht $NAME
  423. "$EVENT""</code><br>
  424. <code>define LogUndef notify global:UNDEFINED.* "send-me-mail.sh
  425. "$EVENT""</code><br>
  426. </ul>
  427. <br>
  428. Hinweise:
  429. <ul>
  430. <li><code>&lt;Suchmuster&gt;</code> ist entweder der Name des
  431. ausl&ouml;senden ("triggernden") Ger&auml;tes oder die Kombination aus
  432. Ger&auml;t und ausl&ouml;sendem Ereignis (Event)
  433. <code>Ger&auml;tename:Event</code>.</li>
  434. <li>Das <code>&lt;Suchmuster&gt;</code> muss exakt (!)
  435. entweder dem Ger&auml;tenamen entsprechen oder der Zusammenf&uuml;gung
  436. aus Ger&auml;tename:Event. Events lassen sich mit "inform" in Telnet
  437. oder durch Beobachtung des "Event-Monitors" in FHEMWEB ermitteln.</li>
  438. <li>In der Anweisung von Notify kann das ausl&ouml;sende Ereignis (Event)
  439. genutzt werden:
  440. <ul>
  441. <li>Die Anweisung $EVENT wird das komplette Ereignis (Event)
  442. beinhalten, z.B. <code>measured-temp: 21.7 (Celsius)</code></li>
  443. <li>$EVTPART0,$EVTPART1,$EVTPART2,etc enthalten die durch Leerzeichen
  444. getrennten Teile des Events der Reihe nach (im Beispiel also
  445. <code>$EVTPART0="measured-temp:", $EVTPART1="21.7",
  446. $EVTPART2="(Celsius)"</code>.<br> Diese Daten sind verf&uuml;gbar
  447. als lokale Variablen in Perl, als Umgebungs-Variablen f&uuml;r
  448. Shell-Scripts, und werden als Text ausgetauscht in
  449. FHEM-Kommandos.</li>
  450. <li>$NAME und $TYPE enthalten den Namen bzw. Typ des Ereignis
  451. ausl&ouml;senden Ger&auml;tes, z.B. myFht und FHT</li>
  452. </ul></li>
  453. <li>Achtung: Folgende Vorgehensweise ist abgek&uuml;ndigt, funktioniert
  454. bis featurelevel 5.6 und wird in einem zuk&uuml;nftigen Release von
  455. FHEM nicht mehr unterst&uuml;tzt. Wenn keine der oben genannten
  456. Variablen ($NAME/$EVENT/usw.) in der Anweisung gefunden wird, werden
  457. Platzhalter ersetzt.
  458. <ul>
  459. <li>Das Zeichen % wird ersetzt mit dem empfangenen
  460. Ereignis (Event), z.B. mit on oder off oder
  461. <code>measured-temp: 21.7 (Celsius)</code>.
  462. </li>
  463. <li>Das Zeichen @ wird ersetzt durch den
  464. Ger&auml;tenamen.</li>
  465. <li>Um % oder @ im Text selbst benutzen zu k&ouml;nnen, m&uuml;ssen
  466. sie verdoppelt werden (%% oder @@).</li>
  467. <li>Anstelle von % und @, k&ouml;nnen die
  468. Parameter %EVENT (funktionsgleich mit %),
  469. %NAME (funktionsgleich mit @) und
  470. %TYPE (enth&auml;lt den Typ des Ger&auml;tes, z.B.
  471. FHT) benutzt werden. Die von Leerzeichen unterbrochenen
  472. Teile eines Ereignisses (Event) sind verf&uuml;gbar als %EVTPART0,
  473. %EVTPART1, usw. Ein einzeln stehendes % verliert seine
  474. oben beschriebene Bedeutung, falls auch nur einer dieser Parameter
  475. in der Definition auftaucht.</li>
  476. </ul></li>
  477. <li>Folgende spezielle Ereignisse werden f&uuml;r das Ger&auml;t "global"
  478. erzeugt:
  479. <ul>
  480. <li>INITIALIZED sobald die Initialization vollst&auml;ndig ist.</li>
  481. <li>REREADCFG nachdem die Konfiguration erneut eingelesen wurde.</li>
  482. <li>SAVE bevor die Konfiguration gespeichert wird.</li>
  483. <li>SHUTDOWN bevor FHEM heruntergefahren wird.</li>
  484. <li>DEFINED &lt;devname&gt; nach dem Definieren eines
  485. Ger&auml;tes.</li>
  486. <li>DELETED &lt;devname&gt; nach dem L&ouml;schen eines
  487. Ger&auml;tes.</li>
  488. <li>RENAMED &lt;old&gt; &lt;new&gt; nach dem Umbenennen eines
  489. Ger&auml;tes.</li>
  490. <li>UNDEFINED &lt;defspec&gt; beim Auftreten einer Nachricht f&uuml;r
  491. ein undefiniertes Ger&auml;t.</li>
  492. </ul></li>
  493. <li>Notify kann dazu benutzt werden, um Makros f&uuml;r eine manuelle
  494. Ausf&uuml;hrung zu speichern. Mit einem <a
  495. href="#trigger">trigger</a> Kommando k&ouml;nnen solche Makros dann
  496. ausgef&uuml;hrt werden. Z.B.<br> <code>fhem> define MyMacro notify
  497. MyMacro { Log 1, "Hello"}</code><br> <code>fhem> trigger
  498. MyMacro</code><br> </li>
  499. </ul>
  500. </ul>
  501. <br>
  502. <a name="notifyset"></a>
  503. <b>Set </b>
  504. <ul>
  505. <li>addRegexpPart &lt;device&gt; &lt;regexp&gt;<br>
  506. F&uuml;gt ein regexp Teil hinzu, der als device:regexp aufgebaut ist.
  507. Die Teile werden nach Regexp-Regeln mit | getrennt. Achtung: durch
  508. hinzuf&uuml;gen k&ouml;nnen manuell erzeugte Regexps ung&uuml;ltig
  509. werden.</li>
  510. <li>removeRegexpPart &lt;re&gt;<br>
  511. Entfernt ein regexp Teil. Die Inkonsistenz von addRegexpPart /
  512. removeRegexPart-Argumenten hat seinen Ursprung in der Wiederverwendung
  513. von Javascript-Funktionen.</li>
  514. <li>inactive<br>
  515. Deaktiviert das entsprechende Ger&auml;t. Beachte den leichten
  516. semantischen Unterschied zum disable Attribut: "set inactive"
  517. wird bei einem shutdown automatisch in fhem.state gespeichert, es ist
  518. kein save notwendig.<br>
  519. Der Einsatzzweck sind Skripte, um das notify tempor&auml;r zu
  520. deaktivieren.<br>
  521. Das gleichzeitige Verwenden des disable Attributes wird nicht empfohlen.
  522. </li>
  523. <li>active<br>
  524. Aktiviert das entsprechende Ger&auml;t, siehe inactive.
  525. </li>
  526. </ul>
  527. <br>
  528. <a name="notifyget"></a>
  529. <b>Get</b> <ul>N/A</ul><br>
  530. <a name="notifyattr"></a>
  531. <b>Attribute</b>
  532. <ul>
  533. <li><a href="#disable">disable</a></li>
  534. <li><a href="#disabledForIntervals">disabledForIntervals</a></li>
  535. <a name="addStateEvent"></a>
  536. <li>addStateEvent<br>
  537. Das mit dem state Reading verkn&uuml;pfte Event ist speziell, da das
  538. dazugeh&ouml;rige Prefix "state: " entfernt wird, d.h. $EVENT ist nicht
  539. "state: on", sondern nur "on". In manchen F&auml;llen ist es aber
  540. erw&uuml;nscht das unmodifizierte Event zu bekommen, d.h. wo "state: "
  541. nicht entfernt ist. F&uuml;r diese F&auml;lle sollte addStateEvent auf 1
  542. gesetzt werden, die Voreinstellung ist 0 (deaktiviert).<br>
  543. Achtung:
  544. <ul>
  545. <li>dieses Attribut muss beim Empf&auml;nger (notify, FileLog, etc)
  546. gesetzt werden.</li>
  547. <li>dieses Attribut zeigt nur f&uuml;r solche Ger&auml;te-Events eine
  548. Wirkung, die <a href="#readingFnAttributes">readingFnAttributes</a>
  549. unterst&uuml;tzen.</li>
  550. </ul>
  551. </li>
  552. <a name="forwardReturnValue"></a>
  553. <li>forwardReturnValue<br>
  554. R&uuml;ckgabe der Werte eines ausgef&uuml;hrten Kommandos an den
  555. Aufrufer. Die Voreinstellung ist 0 (ausgeschaltet), um weniger
  556. Meldungen im Log zu haben.
  557. </li>
  558. <a name="readLog"></a>
  559. <li>readLog<br>
  560. Das notify wird f&uuml;r Meldungen, die im FHEM-Log erscheinen,
  561. ausgegef&uuml;hrt. Das "Event-Generierende-Ger&auml;t" wird auf dem
  562. notify selbst gesetzt. Z.Bsp. kann man mit folgendem notify auf die
  563. Startup Meldung reagieren:
  564. <ul><code>
  565. define n notify n:.*Server.started.* { Log 1, "Wirklich" }<br>
  566. attr n readLog
  567. </code></ul>
  568. </li>
  569. <a name="perlSyntaxCheck"></a>
  570. <li>perlSyntaxCheck<br>
  571. nach setzen des <b>global</b> Attributes perlSyntaxCheck wird eine
  572. Syntax-Pr&uuml;fung der Anweisung durchgef&uuml;hrt bei jeder
  573. &Auml;nderung (define oder modify), falls die Anweisung Perl ist, und
  574. FHEM bereits gestartet ist. </li>
  575. </ul>
  576. <br>
  577. </ul>
  578. =end html_DE
  579. =cut