98_monitoring.pm 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473
  1. # Id ##########################################################################
  2. # $Id: 98_monitoring.pm 15160 2017-10-01 10:17:12Z igami $
  3. # copyright ###################################################################
  4. #
  5. # 98_monitoring.pm
  6. #
  7. # Copyright by igami
  8. #
  9. # This file is part of FHEM.
  10. #
  11. # FHEM is free software: you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation, either version 2 of the License, or
  14. # (at your option) any later version.
  15. #
  16. # FHEM is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. # GNU General Public License for more details.
  20. #
  21. # You should have received a copy of the GNU General Public License
  22. # along with FHEM. If not, see <http://www.gnu.org/licenses/>.
  23. # packages ####################################################################
  24. package main;
  25. use strict;
  26. use warnings;
  27. # forward declarations ########################################################
  28. sub monitoring_Initialize($);
  29. sub monitoring_Define($$);
  30. sub monitoring_Undefine($$);
  31. sub monitoring_Set($@);
  32. sub monitoring_Get($@);
  33. sub archetype_Attr(@);
  34. sub monitoring_Notify($$);
  35. sub monitoring_modify($);
  36. sub monitoring_RemoveInternalTimer($);
  37. sub monitoring_return($$);
  38. sub monitoring_setActive($);
  39. # initialize ##################################################################
  40. sub monitoring_Initialize($) {
  41. my ($hash) = @_;
  42. my $TYPE = "monitoring";
  43. $hash->{DefFn} = $TYPE."_Define";
  44. $hash->{UndefFn} = $TYPE."_Undefine";
  45. $hash->{SetFn} = $TYPE."_Set";
  46. $hash->{GetFn} = $TYPE."_Get";
  47. $hash->{AttrFn} = $TYPE."_Attr";
  48. $hash->{NotifyFn} = $TYPE."_Notify";
  49. $hash->{AttrList} = ""
  50. . "addStateEvent:1,0 "
  51. . "blacklist:textField-long "
  52. . "disable:1,0 "
  53. . "disabledForIntervals "
  54. . "errorFuncAdd:textField-long "
  55. . "errorFuncRemove:textField-long "
  56. . "errorWait "
  57. . "errorReturn:textField-long "
  58. . "getDefault:all,error,warning "
  59. . "setActiveFunc:textField-long "
  60. . "warningFuncAdd:textField-long "
  61. . "warningFuncRemove:textField-long "
  62. . "warningWait "
  63. . "warningReturn:textField-long "
  64. . "whitelist:textField-long "
  65. . $readingFnAttributes
  66. ;
  67. }
  68. # regular Fn ##################################################################
  69. sub monitoring_Define($$) {
  70. my ($hash, $def) = @_;
  71. my ($SELF, $TYPE, @re) = split(/[\s]+/, $def, 5);
  72. return("Usage: define <name> $TYPE <add-event> [<remove-event>]")
  73. if(int(@re) < 1 || int(@re) > 2);
  74. monitoring_setActive($hash) if($init_done);
  75. return;
  76. }
  77. sub monitoring_Undefine($$) {
  78. my ($hash, $arg) = @_;
  79. monitoring_RemoveInternalTimer($hash);
  80. return;
  81. }
  82. sub monitoring_Set($@) {
  83. my ($hash, @a) = @_;
  84. my $TYPE = $hash->{TYPE};
  85. return("\"set $TYPE\" needs at least one argument") if(@a < 2);
  86. my $SELF = shift @a;
  87. my $argument = shift @a;
  88. my $value = join(" ", @a) if (@a);
  89. my %monitoring_sets = (
  90. "active" => "active:noArg"
  91. , "clear" => "clear:all,error,warning"
  92. , "errorAdd" => "errorAdd:textField"
  93. , "errorRemove" => "errorRemove:"
  94. . join(",", ReadingsVal($SELF, "error", ""))
  95. , "inactive" => "inactive:noArg"
  96. , "warningAdd" => "warningAdd:textField"
  97. , "warningRemove" => "warningRemove:"
  98. . join(",", ReadingsVal($SELF, "warning", ""))
  99. );
  100. return(
  101. "Unknown argument $argument, choose one of "
  102. . join(" ", sort(values %monitoring_sets))
  103. ) unless(exists($monitoring_sets{$argument}));
  104. if($argument eq "active"){
  105. monitoring_setActive($hash);
  106. }
  107. elsif($argument eq "inactive"){
  108. readingsSingleUpdate($hash, "state", $argument, 0);
  109. Log3($SELF, 3, "$SELF ($TYPE) set $SELF inactive");
  110. monitoring_RemoveInternalTimer($hash);
  111. }
  112. elsif($argument eq "clear"){
  113. readingsBeginUpdate($hash);
  114. if($value =~ m/^(warning|all)$/){
  115. readingsBulkUpdate($hash, "warning", "", 0);
  116. foreach my $r (keys %{$hash->{READINGS}}){
  117. if($r =~ m/(warning)Add_(.+)/){
  118. RemoveInternalTimer("$SELF|$1|add|$2");
  119. delete $hash->{READINGS}{$r};
  120. }
  121. }
  122. }
  123. if($value =~ m/^(error|all)$/){
  124. readingsBulkUpdate($hash, "error", "", 0);
  125. foreach my $r (keys %{$hash->{READINGS}}){
  126. if($r =~ m/(error)Add_(.+)/){
  127. RemoveInternalTimer("$SELF|$1|add|$2");
  128. delete $hash->{READINGS}{$r};
  129. }
  130. }
  131. }
  132. readingsBulkUpdate($hash, "state", "$argument $value", 0)
  133. unless(IsDisabled($SELF));
  134. readingsEndUpdate($hash, 0);
  135. Log3($SELF, 2, "$TYPE ($SELF) set $SELF $argument $value");
  136. }
  137. elsif($argument =~ /^(error|warning)(Add|Remove)$/){
  138. monitoring_modify("$SELF|$1|".lc($2)."|$value");
  139. }
  140. return;
  141. }
  142. sub monitoring_Get($@) {
  143. my ($hash, @a) = @_;
  144. my $TYPE = $hash->{TYPE};
  145. my $SELF = shift @a;
  146. return if(IsDisabled($SELF));
  147. return("\"get $TYPE\" needs at least one argument") if(@a < 1);
  148. my $argument = shift @a;
  149. my $value = join(" ", @a) if (@a);
  150. my $default = AttrVal($SELF, "getDefault", "all");
  151. my %monitoring_gets = (
  152. "all" => "all:noArg"
  153. , "default" => "default:noArg"
  154. , "error" => "error:noArg"
  155. , "warning" => "warning:noArg"
  156. );
  157. my @ret;
  158. return(
  159. "Unknown argument $argument, choose one of "
  160. . join(" ", sort(values %monitoring_gets))
  161. ) unless(exists($monitoring_gets{$argument}));
  162. if($argument eq "all" || ($argument eq "default" && $default eq "all")){
  163. push(@ret, monitoring_return($hash, "error"));
  164. push(@ret, monitoring_return($hash, "warning"));
  165. }
  166. elsif($argument eq "default"){
  167. push(@ret, monitoring_return($hash, $default));
  168. }
  169. elsif($argument eq "error"){
  170. push(@ret, monitoring_return($hash, "error"));
  171. }
  172. elsif($argument eq "warning"){
  173. push(@ret, monitoring_return($hash, "warning"));
  174. }
  175. return(join("\n\n", @ret)."\n") if(@ret);
  176. return;
  177. }
  178. sub monitoring_Attr(@) {
  179. my ($cmd, $SELF, $attribute, $value) = @_;
  180. my ($hash) = $defs{$SELF};
  181. if($attribute =~ "blacklist" && $value){
  182. my @blacklist;
  183. push(@blacklist, devspec2array($_)) foreach (split(/[\s]+/, $value));
  184. my %blacklist = map{$_, 1} @blacklist;
  185. foreach my $name (sort(keys %blacklist)){
  186. monitoring_modify("$SELF|warning|remove|$name");
  187. monitoring_modify("$SELF|error|remove|$name");
  188. }
  189. }
  190. elsif($attribute eq "whitelist" && $value){
  191. my @whitelist;
  192. push(@whitelist, devspec2array($_)) foreach (split(/[\s]+/, $value));
  193. foreach my $list ("warning", "error"){
  194. foreach my $name (split(",", ReadingsVal($SELF, $list, ""))){
  195. monitoring_modify("$SELF|$list|remove|$name")
  196. unless(grep(/$name/, @whitelist));
  197. }
  198. }
  199. }
  200. elsif($attribute eq "disable"){
  201. if($cmd eq "set" and $value == 1){
  202. monitoring_setActive($hash);
  203. }
  204. else{
  205. readingsSingleUpdate($hash, "state", "disabled", 0);
  206. Log3($SELF, 3, "$hash->{TYPE} ($SELF) attr $SELF disabled");
  207. }
  208. }
  209. return;
  210. }
  211. sub monitoring_Notify($$) {
  212. my ($hash, $dev_hash) = @_;
  213. my $SELF = $hash->{NAME};
  214. my $name = $dev_hash->{NAME};
  215. my $TYPE = $hash->{TYPE};
  216. return if(
  217. !$init_done
  218. || IsDisabled($SELF)
  219. || IsDisabled($name)
  220. || $SELF eq $name # do not process own events
  221. );
  222. my $events = deviceEvents($dev_hash, AttrVal($SELF, "addStateEvent", 0));
  223. return unless($events);
  224. if($name eq "global" && "INITIALIZED" =~ m/\Q@{$events}\E/){
  225. monitoring_setActive($hash);
  226. return;
  227. }
  228. my ($addRegex, $removeRegex) = split(/[\s]+/, InternalVal($SELF, "DEF", ""));
  229. return unless(
  230. $addRegex =~ m/^$name:/
  231. || $removeRegex && $removeRegex =~ m/^$name:/
  232. || $events
  233. );
  234. my @blacklist;
  235. push(@blacklist, devspec2array($_))
  236. foreach (split(/[\s]+/, AttrVal($SELF, "blacklist", "")));
  237. return if(@blacklist && grep(/$name/, @blacklist));
  238. my @whitelist;
  239. push(@whitelist, devspec2array($_))
  240. foreach (split(/[\s]+/, AttrVal($SELF, "whitelist", "")));
  241. return if(@whitelist && !(grep(/$name/, @whitelist)));
  242. foreach my $event (@{$events}){
  243. next unless($event);
  244. my $addMatch = "$name:$event" =~ m/^$addRegex$/;
  245. my $removeMatch = $removeRegex ? "$name:$event" =~ m/^$removeRegex$/ : 0;
  246. next unless(defined($event) && ($addMatch || $removeMatch));
  247. Log3($SELF, 4 , "$TYPE ($SELF) triggered by \"$name $event\"");
  248. foreach my $list ("warning", "error"){
  249. my $listFuncAdd = AttrVal($SELF, $list."FuncAdd", "preset");
  250. my $listFuncRemove = AttrVal($SELF, $list."FuncRemove", "preset");
  251. my $listWait = eval(AttrVal($SELF, $list."Wait", 0));
  252. $listWait = 0 unless(looks_like_number($listWait));
  253. if($listFuncAdd eq "preset" && $listFuncRemove eq "preset"){
  254. Log3($SELF, 5
  255. , "$TYPE ($SELF) "
  256. . $list."FuncAdd and "
  257. . $list."FuncRemove are preset"
  258. );
  259. if(!$removeRegex){
  260. if($listWait == 0){
  261. Log3($SELF, 2
  262. , "$TYPE ($SELF) set \"$list"."Wait\" while \"$list"
  263. . "FuncAdd\" and \"$list"."FuncRemove\" are same"
  264. ) if($list eq "error");
  265. next;
  266. }
  267. Log3($SELF, 5, "$TYPE ($SELF) only addRegex is defined");
  268. monitoring_modify("$SELF|$list|remove|$name");
  269. monitoring_modify(
  270. "$SELF|$list|add|$name|$listWait"
  271. );
  272. next;
  273. }
  274. else{
  275. next unless($list eq "error" || AttrVal($SELF, "errorWait", undef));
  276. Log3($SELF, 5
  277. , "$TYPE ($SELF) addRegex ($addRegex) "
  278. . "and removeRegex ($removeRegex) are defined"
  279. );
  280. monitoring_modify("$SELF|$list|remove|$name") if($removeMatch);
  281. monitoring_modify("$SELF|$list|add|$name|$listWait") if($addMatch);
  282. next;
  283. }
  284. }
  285. $listFuncAdd = 1 if($listFuncAdd eq "preset" && $addMatch);
  286. if(!$removeRegex){
  287. Log3($SELF, 5, "$TYPE ($SELF) only addRegex is defined");
  288. if($listFuncRemove eq "preset"){
  289. if($listWait == 0){
  290. Log3($SELF, 2
  291. , "$TYPE ($SELF) set \"$list"."Wait\" while \"$list"
  292. . "FuncAdd\" and \"$list"."FuncRemove\" are same"
  293. ) if($list eq "error");
  294. next;
  295. }
  296. $listFuncRemove = $listFuncAdd;
  297. }
  298. }
  299. else{
  300. Log3($SELF, 5
  301. , "$TYPE ($SELF) addRegex ($addRegex) "
  302. . "and removeRegex ($removeRegex) are defined"
  303. );
  304. $listFuncRemove = 1 if($listFuncRemove eq "preset" && $removeMatch);
  305. }
  306. $listFuncAdd = eval($listFuncAdd) if($listFuncAdd =~ /^\{.*\}$/s);
  307. $listFuncRemove = eval($listFuncRemove)
  308. if($listFuncRemove =~ /^\{.*\}$/s);
  309. monitoring_modify("$SELF|$list|remove|$name")
  310. if($listFuncRemove && $listFuncRemove eq "1");
  311. monitoring_modify("$SELF|$list|add|$name|$listWait")
  312. if($listFuncAdd && $listFuncAdd eq "1");
  313. next;
  314. }
  315. }
  316. return;
  317. }
  318. # module Fn ###################################################################
  319. sub monitoring_modify($) {
  320. my ($SELF, $list, $operation, $value, $wait) = split("\\|", shift);
  321. my ($hash) = $defs{$SELF};
  322. return unless(defined($hash));
  323. return if(IsDisabled($SELF));
  324. my $at = eval($wait + gettimeofday()) if($wait);
  325. my $TYPE = $hash->{TYPE};
  326. my (@change, %readings);
  327. %readings = map{$_, 1} split(",", ReadingsVal($SELF, $list, ""));
  328. my $arg = "$SELF|$list|$operation|$value";
  329. my $reading = $list."Add_".$value;
  330. Log3(
  331. $SELF, 5 , "$TYPE ($SELF)"
  332. . "\n entering monitoring_modify"
  333. . "\n reading: $list"
  334. . "\n operation: $operation"
  335. . "\n value: $value"
  336. . "\n at: ".($at ? FmtDateTime($at) : "now")
  337. );
  338. if($operation eq "add"){
  339. return if($readings{$value});
  340. if($at){
  341. return if($hash->{READINGS}{$reading});
  342. readingsSingleUpdate(
  343. $hash, $reading, FmtDateTime($at), 0
  344. );
  345. InternalTimer($at, "monitoring_modify", $arg);
  346. return;
  347. }
  348. else{
  349. monitoring_modify("$SELF|warning|remove|$value") if($list eq "error");
  350. $readings{$value} = 1;
  351. delete $hash->{READINGS}{$reading};
  352. }
  353. }
  354. elsif($operation eq "remove"){
  355. push(@change, 1) if(delete $readings{$value});
  356. delete $hash->{READINGS}{"$reading"};
  357. }
  358. RemoveInternalTimer("$SELF|$list|add|$value");
  359. return unless(@change || $operation eq "add");
  360. readingsBeginUpdate($hash);
  361. readingsBulkUpdate($hash, "state", "$list $operation: $value");
  362. readingsBulkUpdate($hash, $list, join(",", sort(keys %readings)));
  363. readingsEndUpdate($hash, 1);
  364. return;
  365. }
  366. sub monitoring_RemoveInternalTimer($) {
  367. my ($hash) = @_;
  368. my $SELF = $hash->{NAME};
  369. foreach my $reading (sort(keys %{$hash->{READINGS}})){
  370. RemoveInternalTimer("$SELF|$1|add|$2")
  371. if($reading =~ m/(error|warning)Add_(.+)/);
  372. }
  373. return;
  374. }
  375. sub monitoring_return($$) {
  376. my ($hash, $list) = @_;
  377. my $SELF = $hash->{NAME};
  378. my @errors = split(",", ReadingsVal($SELF, "error", ""));
  379. my @warnings = split(",", ReadingsVal($SELF, "warning", ""));
  380. my $value = ReadingsVal($SELF, $list, undef);
  381. my $ret = AttrVal($SELF, $list."Return", undef);
  382. $ret = '"$list: $value"' if(!$ret && $value);
  383. return unless($ret);
  384. return eval($ret);
  385. }
  386. sub monitoring_setActive($) {
  387. my ($hash) = @_;
  388. my $SELF = $hash->{NAME};
  389. my $TYPE = $hash->{TYPE};
  390. readingsSingleUpdate($hash, "state", "active", 0);
  391. Log3($SELF, 3, "$TYPE ($SELF) set $SELF active");
  392. foreach my $reading (sort(keys %{$hash->{READINGS}})){
  393. if($reading =~ m/(error|warning)Add_(.+)/){
  394. my $wait = time_str2num(ReadingsVal($SELF, $reading, ""));
  395. next unless(looks_like_number($wait));
  396. $wait -= gettimeofday();
  397. if($wait > 0){
  398. Log3($SELF, 4 , "$TYPE ($SELF) restore Timer \"$SELF|$1|add|$2\"");
  399. monitoring_modify("$SELF|$1|add|$2|$wait");
  400. }
  401. else{
  402. monitoring_modify("$SELF|$1|add|$2");
  403. }
  404. }
  405. }
  406. AnalyzeCommandChain(undef, AttrVal($SELF, "setActiveFunc", "preset"));
  407. return;
  408. }
  409. 1;
  410. # commandref ##################################################################
  411. =pod
  412. =item helper
  413. =item summary monitors devices towards events and stores them in two lists
  414. =item summary_DE überwacht Geräte auf Events und speichert diese in zwei Listen
  415. =begin html
  416. <a name="monitoring"></a>
  417. <h3>monitoring</h3>
  418. ( en | <a href="commandref_DE.html#monitoring"><u>de</u></a> )
  419. <div>
  420. <ul>
  421. Each monitoring has a warning and an error list, which are stored
  422. as readings. <br>
  423. When a defined add-event occurs, the device is set to the warning
  424. list after a predefined time.<br>
  425. After a further predefined time, the device is deleted from the
  426. warning list and set to the error list.<br>
  427. If a defined remove-event occurs, the device is deleted from both
  428. lists and still running timers are canceled.<br>
  429. This makes it easy to create group messages and send them
  430. formatted by two attributes.<br>
  431. <br>
  432. The following applications are possible and are described
  433. <a href="#monitoringexamples"><u>below</u></a>:<br>
  434. <ul>
  435. <li>opened windows</li>
  436. <li>battery warnings</li>
  437. <li>activity monitor</li>
  438. <li>
  439. regular maintenance (for example changing the table water
  440. filter or cleaning rooms)
  441. </li>
  442. <li>
  443. operating hours dependent maintenance (for example clean the
  444. Beamer filter)
  445. </li>
  446. </ul>
  447. <br>
  448. The monitor does not send a message by itself, a notify or DOIF is
  449. necessary, which responds to the event "&lt;monitoring-name&gt; error
  450. add: &lt;name&gt;" and then sends the return value of "get
  451. &lt;monitoring-name&gt; default".
  452. <br>
  453. <br>
  454. <a name="monitoringdefine"></a>
  455. <b>Define</b>
  456. <ul>
  457. <code>
  458. define &lt;name&gt; &lt;add-event&gt; [&lt;remove-event&gt;]
  459. </code>
  460. <br>
  461. The syntax for &lt;add-event&gt; and &lt;remove-event&gt; is the
  462. same as the pattern for <a href="#notify">notify</a>
  463. (device-name or device-name:event).<br>
  464. If only an &lt;add-event&gt; is defined, the device is deleted from
  465. both lists as it occurs and the timers for warning and error are
  466. started.<br>
  467. </ul>
  468. <br>
  469. <a name="monitoringset"></a>
  470. <b>Set</b>
  471. <ul>
  472. <li>
  473. <code>active</code><br>
  474. Two things will happen:<br>
  475. 1. Restores pending timers, or sets the devices immediately to the
  476. corresponding list if the time is in the past.<br>
  477. 2. Executes the commands specified under the "setActiveFunc" attribute.
  478. </li>
  479. <li>
  480. <code>clear (warning|error|all)</code><br>
  481. Removes all devices from the specified list and aborts timers for this
  482. list. With "all", all devices are removed from both lists and all
  483. running timers are aborted.
  484. </li>
  485. <li>
  486. <code>errorAdd &lt;name&gt;</code><br>
  487. Add &lt;name&gt; to the error list.
  488. </li>
  489. <li>
  490. <code>errorRemove &lt;name&gt;</code><br>
  491. Removes &lt;name&gt; from the error list.
  492. </li>
  493. <li>
  494. <code>inactive</code><br>
  495. Inactivates the current device. Note the slight difference to the
  496. disable attribute: using set inactive the state is automatically saved
  497. to the statefile on shutdown, there is no explicit save necesary.
  498. </li>
  499. <li>
  500. <code>warningAdd &lt;name&gt;</code><br>
  501. Add &lt;name&gt; to the warning list.
  502. </li>
  503. <li>
  504. <code>warningRemove &lt;name&gt;</code><br>
  505. Removes &lt;name&gt; from the warning list.
  506. </li>
  507. </ul>
  508. <br>
  509. <a name="monitoringget"></a>
  510. <b>Get</b>
  511. <ul>
  512. <li>
  513. <code>all</code><br>
  514. Returns the error and warning list, separated by a blank line.<br>
  515. The formatting can be set with the attributes "errorReturn" and
  516. "warningReturn".
  517. </li>
  518. <li>
  519. <code>default</code><br>
  520. The "default" value can be set in the attribute "getDefault" and is
  521. intended to leave the configuration for the return value in the
  522. monitoring device. If nothing is specified "all" is used.
  523. </li>
  524. <li>
  525. <code>error</code><br>
  526. Returns the error list.<br>
  527. The formatting can be set with the attribute "errorReturn".
  528. </li>
  529. <li>
  530. <code>warning</code><br>
  531. Returns the warning list.<br>
  532. The formatting can be set with the attribute "warningReturn".
  533. </li>
  534. </ul>
  535. <br>
  536. <a name="monitoringreadings"></a>
  537. <b>Readings</b><br>
  538. <ul>
  539. <li>
  540. <code>error</code><br>
  541. Comma-separated list of devices.
  542. </li>
  543. <li>
  544. <code>errorAdd_&lt;name&gt;</code><br>
  545. Displays the time when the device will be set to the error list.
  546. </li>
  547. <li>
  548. <code>state</code><br>
  549. Displays the status (active, inactive, or disabled). In "active" it
  550. displays which device added to which list or was removed from which
  551. list.
  552. </li>
  553. <li>
  554. <code>warning</code><br>
  555. Comma-separated list of devices.
  556. </li>
  557. <li>
  558. <code>warningAdd_&lt;name&gt;</code><br>
  559. Displays the time when the device will be set to the warning list.
  560. </li>
  561. </ul>
  562. <br>
  563. <a name="monitoringattr"></a>
  564. <b>Attribute</b>
  565. <ul>
  566. <li>
  567. <a href="#addStateEvent">
  568. <u><code>addStateEvent</code></u>
  569. </a>
  570. </li>
  571. <li>
  572. <code>blacklist</code><br>
  573. Space-separated list of devspecs which will be ignored.<br>
  574. If the attribute is set all devices which are specified by the devspecs
  575. are removed from both lists.
  576. </li>
  577. <li>
  578. <code>disable (1|0)</code><br>
  579. 1: Disables the monitoring.<br>
  580.         0: see "set active"
  581. </li>
  582. <li>
  583. <a href="#disabledForIntervals">
  584. <u><code>disabledForIntervals HH:MM-HH:MM HH:MM-HH-MM ...</code></u>
  585. </a>
  586. </li>
  587. <li>
  588. <code>errorFuncAdd {&lt;perl code&gt;}</code><br>
  589. The following variables are available in this function:
  590. <br>
  591. <ul>
  592. <li>
  593. <code>$name</code><br>
  594. Name of the event triggering device
  595. </li>
  596. <li>
  597. <code>$event</code><br>
  598. Includes the complete event, e.g.
  599. <code>measured-temp: 21.7 (Celsius)</code>
  600. </li>
  601. <li>
  602. <code>$addMatch</code><br>
  603. Has the value 1 if the add-event is true
  604. </li>
  605. <li>
  606. <code>$removeMatch</code><br>
  607. Has the value 1 if the remove-event is true
  608. </li>
  609. <li>
  610. <code>$SELF</code><br>
  611. Name of the monitoring
  612. </li>
  613. </ul>
  614. If the function returns a 1, the device is set to the error list after
  615. the wait time.<br>
  616. If the attribute is not set, it will be checked for
  617. <code>$addMatch</code>.
  618. </li>
  619. <li>
  620. <code>errorFuncRemove {&lt;perl code&gt;}</code><br>
  621. This function provides the same variables as for "errorFuncAdd".<br>
  622. If the function returns a 1, the device is removed from the error list
  623. and still running timers are canceled.<br>
  624. If the attribute is not set, it will be checked for
  625. <code>$removeMatch</code> if there is a
  626. <code>&lt;remove-event&gt;</code> in the DEF, otherwise it will be
  627. checked for <code>errorFuncAdd</code>.
  628. </li>
  629. <li>
  630. <code>errorWait &lt;perl code&gt;</code><br>
  631. Wait until the device is set to the error list.
  632. </li>
  633. <li>
  634. <code>errorReturn {&lt;perl code&gt;}</code><br>
  635. The following variables are available in this attribute:
  636. <ul>
  637. <li>
  638. <code>@errors</code><br>
  639. Array with all devices on the error list.
  640. </li>
  641. <li>
  642. <code>@warnings</code><br>
  643. Array with all devices on the warning list.
  644. </li>
  645. <li>
  646. <code>$SELF</code><br>
  647. Name of the monitoring
  648. </li>
  649. </ul>
  650. With this attribute the output created with "get &lt;name&gt; error"
  651. can be formatted.
  652. </li>
  653. <li>
  654. <code>getDefault (all|error|warning)</code><br>
  655. This attribute can be used to specify which list(s) are / are returned
  656. by "get &lt;name&gt; default". If the attribute is not set, "all" will
  657. be used.
  658. </li>
  659. <li>
  660. <code>setActiveFunc &lt;Anweisung&gt;</code><br>
  661. The statement is one of the FHEM command types and is executed when you
  662. define the monitoring or "set active".<br>
  663. For a battery message <code>"trigger battery=low battery: low"</code>
  664. can be useful.
  665. </li>
  666. <li>
  667. <code>warningFuncAdd {&lt;perl code&gt;}</code><br>
  668. Like errorFuncAdd, just for the warning list.
  669. </li>
  670. <li>
  671. <code>warningFuncRemove {&lt;perl code&gt;}</code><br>
  672. Like errorFuncRemove, just for the warning list.
  673. </li>
  674. <li>
  675. <code>warningWait &lt;perl code&gt;</code><br>
  676. Like errorWait, just for the warning list.
  677. </li>
  678. <li>
  679. <code>warningReturn {&lt;perl code&gt;}</code><br>
  680. Like errorReturn, just for the warning list.
  681. </li>
  682. <li>
  683. <code>whitelist {&lt;perl code&gt;}</code><br>
  684. Space-separated list of devspecs which are allowed.<br>
  685. If the attribute is set all devices which are not specified by the
  686. devspecs are removed from both lists.
  687. </li>
  688. <li>
  689. <a href="#readingFnAttributes">
  690. <u><code>readingFnAttributes</code></u>
  691. </a>
  692. </li>
  693. </ul>
  694. <br>
  695. <a name="monitoringexamples"></a>
  696. <b>Examples</b>
  697. <ul>
  698. <a href="https://wiki.fhem.de/wiki/Import_von_Code_Snippets">
  699. <u>The following sample codes can be imported via "Raw definition".</u>
  700. </a>
  701. <br><br>
  702. <li>
  703. <b>
  704. Global, flexible opened windows/doors message
  705. <a href="https://forum.fhem.de/index.php/topic,36504">
  706. <u>(similar to those described in the forum)</u>
  707. </a>
  708. </b>
  709. <br>
  710. <pre>defmod Fenster_monitoring monitoring .*:(open|tilted) .*:closed
  711. attr Fenster_monitoring errorReturn {return unless(@errors);;\
  712. $_ = AttrVal($_, "alias", $_) foreach(@errors);;\
  713. return("Das Fenster \"$errors[0]\" ist schon l&auml;nger ge&ouml;ffnet.") if(int(@errors) == 1);;\
  714. @errors = sort {lc($a) cmp lc($b)} @errors;;\
  715. return(join("\n - ", "Die folgenden ".@errors." Fenster sind schon l&auml;nger ge&ouml;ffnet:", @errors))\
  716. }
  717. attr Fenster_monitoring errorWait {AttrVal($name, "winOpenTimer", 60*10)}
  718. attr Fenster_monitoring warningReturn {return unless(@warnings);;\
  719. $_ = AttrVal($_, "alias", $_) foreach(@warnings);;\
  720. return("Das Fenster \"$warnings[0]\" ist seit kurzem ge&ouml;ffnet.") if(int(@warnings) == 1);;\
  721. @warnings = sort {lc($a) cmp lc($b)} @warnings;;\
  722. return(join("\n - ", "Die folgenden ".@warnings." Fenster sind seit kurzem ge&ouml;ffnet:", @warnings))\
  723. }</pre>
  724. As soon as a device triggers an "open" or "tilded" event, the device is
  725. set to the warning list and a timer is started after which the device
  726. is moved from the warning to the error list. The waiting time can be
  727. set for each device via userattr "winOpenTimer". The default value is
  728. 10 minutes.<br>
  729. As soon as a device triggers a "closed" event, the device is deleted
  730. from both lists and still running timers are stopped.
  731. </li>
  732. <br>
  733. <li>
  734. <b>Battery monitoring</b><br>
  735. <pre>defmod Batterie_monitoring monitoring .*:battery:.low .*:battery:.ok
  736. attr Batterie_monitoring errorReturn {return unless(@errors);;\
  737. $_ = AttrVal($_, "alias", $_) foreach(@errors);;\
  738. return("Bei dem Ger&auml;t \"$errors[0]\" muss die Batterie gewechselt werden.") if(int(@errors) == 1);;\
  739. @errors = sort {lc($a) cmp lc($b)} @errors;;\
  740. return(join("\n - ", "Die folgenden ".@errors." Ger&auml;ten muss die Batterie gewechselt werden:", @errors))\
  741. }
  742. attr Batterie_monitoring errorWait 60*60*24*14
  743. attr Batterie_monitoring warningReturn {return unless(@warnings);;\
  744. $_ = AttrVal($_, "alias", $_) foreach(@warnings);;\
  745. return("Bei dem Ger&auml;t \"$warnings[0]\" muss die Batterie demn&auml;chst gewechselt werden.") if(int(@warnings) == 1);;\
  746. @warnings = sort {lc($a) cmp lc($b)} @warnings;;\
  747. return(join("\n - ", "Die folgenden ".@warnings." Ger&auml;ten muss die Batterie demn&auml;chst gewechselt werden:", @warnings))\
  748. }</pre>
  749. As soon as a device triggers a "battery: low" event, the device is set
  750. to the warning list and a timer is started after which the device is
  751. moved from the warning to the error list. The waiting time is set to 14
  752. days.<br>
  753. As soon as a device triggers a "battery: ok" event, the device is
  754. deleted from both lists and still running timers are stopped.
  755. </li>
  756. <br>
  757. <li>
  758. <b>Activity Monitor</b><br>
  759. <pre>defmod Activity_monitoring monitoring .*:.*
  760. attr Activity_monitoring errorReturn {return unless(@errors);;\
  761. $_ = AttrVal($_, "alias", $_) foreach(@errors);;\
  762. return("Das Ger&auml;t \"$errors[0]\" hat sich seit mehr als 24 Stunden nicht mehr gemeldet.") if(int(@errors) == 1);;\
  763. @errors = sort {lc($a) cmp lc($b)} @errors;;\
  764. return(join("\n - ", "Die folgenden ".@errors." Ger&auml;ten haben sich seit mehr als 24 Stunden nicht mehr gemeldet:", @errors))\
  765. }
  766. attr Activity_monitoring errorWait 60*60*24
  767. attr Activity_monitoring warningReturn {return unless(@warnings);;\
  768. $_ = AttrVal($_, "alias", $_) foreach(@warnings);;\
  769. return("Das Ger&auml;t \"$warnings[0]\" hat sich seit mehr als 12 Stunden nicht mehr gemeldet.") if(int(@warnings) == 1);;\
  770. @warnings = sort {lc($a) cmp lc($b)} @warnings;;\
  771. return(join("\n - ", "Die folgenden ".@warnings." Ger&auml;ten haben sich seit mehr als 12 Stunden nicht mehr gemeldet:", @warnings))\
  772. }
  773. attr Activity_monitoring warningWait 60*60*12</pre>
  774. Devices are not monitored until they have triggered at least one event.
  775. If the device does not trigger another event in 12 hours, it will be
  776. set to the warning list. If the device does not trigger another event
  777. within 24 hours, it will be moved from the warning list to the error
  778. list.
  779. </li>
  780. <br>
  781. <li>
  782. <b>Regular maintenance (for example changing the table water filter)</b>
  783. <br>
  784. <pre>defmod Wasserfilter_monitoring monitoring Wasserfilter_DashButton:.*:.short
  785. attr Wasserfilter_monitoring errorReturn {return unless(@errors);;\
  786. return "Der Wasserfilter muss gewechselt werden.";;\
  787. }
  788. attr Wasserfilter_monitoring errorWait 60*60*24*30
  789. attr Wasserfilter_monitoring warningReturn {return unless(@warnings);;\
  790. return "Der Wasserfilter muss demn&auml;chst gewechselt werden.";;\
  791. }
  792. attr Wasserfilter_monitoring warningWait 60*60*24*25</pre>
  793. A <a href="#dash_dhcp"><u>DashButton</u></a> is used to tell FHEM that
  794. the water filter has been changed.<br>
  795. After 30 days, the DashButton is set to the error list.
  796. </li>
  797. <br>
  798. <li>
  799. <b>Regular maintenance (for example cleaning rooms)</b>
  800. <br>
  801. <pre>defmod putzen_DashButton dash_dhcp
  802. attr putzen_DashButton allowed AC:63:BE:2E:19:AF,AC:63:BE:49:23:48,AC:63:BE:49:5E:FD,50:F5:DA:93:2B:EE,AC:63:BE:B2:07:78
  803. attr putzen_DashButton devAlias ac-63-be-2e-19-af:Badezimmer\
  804. ac-63-be-49-23-48:Küche\
  805. ac-63-be-49-5e-fd:Schlafzimmer\
  806. 50-f5-da-93-2b-ee:Arbeitszimmer\
  807. ac-63-be-b2-07-78:Wohnzimmer
  808. attr putzen_DashButton event-min-interval .*:5
  809. attr putzen_DashButton port 6767
  810. attr putzen_DashButton userReadings state {return (split(":", @{$hash->{CHANGED}}[0]))[0];;}
  811. attr putzen_DashButton widgetOverride allowed:textField-long devAlias:textField-long
  812. defmod putzen_monitoring monitoring putzen_DashButton:.*:.short
  813. attr putzen_monitoring errorFuncAdd {$event =~ m/^(.+):/;;\
  814. $name = $1;;\
  815. return 1;;\
  816. }
  817. attr putzen_monitoring errorReturn {return unless(@errors);;\
  818. return("Der Raum \"$errors[0]\" muss wieder geputzt werden.") if(int(@errors) == 1);;\
  819. return(join("\n - ", "Die folgenden Räume müssen wieder geputzt werden:", @errors))\
  820. }
  821. attr putzen_monitoring errorWait 60*60*24*7</pre>
  822. Several <a href="#dash_dhcp"><u>DashButton</u></a> are used to inform
  823. FHEM that the rooms have been cleaned.<br>
  824. After 7 days, the room is set to the error list.<br>
  825. However, the room name is not the device name but the readings name and
  826. is changed in the <code>errorFuncAdd</code> attribute.
  827. </li>
  828. <br>
  829. <li>
  830. <b>
  831. Operating hours dependent maintenance
  832. (for example, clean the Beamer filter)
  833. </b>
  834. <br>
  835. <pre>defmod BeamerFilter_monitoring monitoring Beamer_HourCounter:pulseTimeOverall BeamerFilter_DashButton:.*:.short
  836. attr BeamerFilter_monitoring userattr errorInterval
  837. attr BeamerFilter_monitoring errorFuncAdd {return 1\
  838. if(ReadingsVal($name, "pulseTimeOverall", 0) >= \
  839. ReadingsVal($name, "pulseTimeService", 0)\
  840. + (AttrVal($SELF, "errorInterval", 0))\
  841. && $addMatch\
  842. );;\
  843. return;;\
  844. }
  845. attr BeamerFilter_monitoring errorFuncRemove {return unless($removeMatch);;\
  846. fhem(\
  847. "setreading $name pulseTimeService "\
  848. .ReadingsVal($name, "pulseTimeOverall", 0)\
  849. );;\
  850. return 1;;\
  851. }
  852. attr BeamerFilter_monitoring errorInterval 60*60*200
  853. attr BeamerFilter_monitoring errorReturn {return unless(@errors);;\
  854. return "Der Filter vom Beamer muss gereinigt werden.";;\
  855. }
  856. attr BeamerFilter_monitoring warningFuncAdd {return}
  857. attr BeamerFilter_monitoring warningFuncRemove {return}</pre>
  858. An <a href="#HourCounter"><u>HourCounter</u></a> is used to record the
  859. operating hours of a beamer and a
  860. <a href="#dash_dhcp"><u>DashButton</u></a> to tell FHEM that the filter
  861. has been cleaned.<br>
  862. If the filter has not been cleaned for more than 200 hours, the device
  863. is set to the error list.<br>
  864. If cleaning is acknowledged with the DashButton, the device is removed
  865. from the error list and the current operating hours are stored in the
  866. HourCounter device.
  867. </li>
  868. </ul>
  869. </ul>
  870. </div>
  871. =end html
  872. =begin html_DE
  873. <a name="monitoring"></a>
  874. <h3>monitoring</h3>
  875. ( <a href="commandref.html#monitoring"><u>en</u></a> | de )
  876. <div>
  877. <ul>
  878. Jedes monitoring verf&uuml;gt &uuml;ber eine warning- und eine error-Liste,
  879. welche als Readings gespeichert werden.<br>
  880. Beim auftreten eines definierten add-events wird das Ger&auml;t nach einer
  881. vorgegeben Zeit auf die warning-Liste gesetzt.<br>
  882. Nach einer weiteren vorgegeben Zeit wird das Ger&auml;t von der
  883. warning-Liste gel&ouml;scht und auf die error-Liste gesetzt.<br>
  884. Beim auftreten eines definierten remove-events wird das Ger&auml;t von
  885. beiden Listen gel&ouml;scht und noch laufende Timer abgebrochen.<br>
  886. Hiermit lassen sich auf einfache Weise Sammelmeldungen erstellen und durch
  887. zwei Attribute formatiert ausgeben.<br>
  888. <br>
  889. Folgende Anwendungen sind m&ouml;glich und werden
  890. <a href="#monitoringexamples"><u>unten</u></a> beschrieben:<br>
  891. <ul>
  892. <li>ge&ouml;ffnete Fenster</li>
  893. <li>Batterie Warnungen</li>
  894. <li>Activity Monitor</li>
  895. <li>
  896. regelm&auml;&szlig;ige Wartungsarbeiten
  897. (z.B. Tischwasserfilter wechseln oder Räume putzen)
  898. </li>
  899. <li>
  900. Betriebsstunden abh&auml;ngige Wartungsarbeiten
  901. (z.B. Beamer Filter reinigen)
  902. </li>
  903. </ul>
  904. <br>
  905. Das monitor sendet selbst keine Benachrichtung, hierf&uuml;r ist ein notify
  906. oder DOIF notwendig, welches auf das Event "&lt;monitoring-name&gt; error
  907. add: &lt;name&gt;" reagiert und dann den R&uuml;ckgabewert von
  908. "get &lt;monitoring-name&gt; default" versendet.
  909. <br>
  910. <br>
  911. <a name="monitoringdefine"></a>
  912. <b>Define</b>
  913. <ul>
  914. <code>
  915. define &lt;name&gt; &lt;add-event&gt; [&lt;remove-event&gt;]
  916. </code>
  917. <br>
  918. Die Syntax f&uuml;r &lt;add-event&gt; und &lt;remove-event&gt; ist die
  919. gleiche wie f&uuml;r das Suchmuster von
  920. <a href="commandref_DE.html#notify"><u>notify</u></a> (Ger&auml;tename
  921. oder Ger&auml;tename:Event).<br>
  922. Ist nur ein &lt;add-event&gt; definiert wird beim auftreten das
  923. Ger&auml;t von beiden Listen gel&ouml;scht und die Timer f&uuml;r warning
  924. und error werden gestartet.<br>
  925. </ul>
  926. <br>
  927. <a name="monitoringset"></a>
  928. <b>Set</b>
  929. <ul>
  930. <li>
  931. <code>active</code><br>
  932. Es passieren zwei Dinge:<br>
  933. 1. Stellt noch ausstehende Timer wieder her, bzw. setzt die Ger&auml;te
  934. sofort auf die entsprechende Liste, falls der Zeitpunkt in der
  935. Vergangenheit liegt.<br>
  936. 2. F&uuml;hrt die unter dem Attribut "setActiveFunc" angegeben Befehle
  937. aus.
  938. </li>
  939. <li>
  940. <code>clear (warning|error|all)</code><br>
  941. Entfernt alle Ger&auml;te von der angegeben Liste und bricht f&uuml;r
  942. diese Liste laufende Timer ab. Bei "all" werden alle Ger&auml;te von
  943. beiden Listen entfernt und alle laufenden Timer abgebrochen.
  944. </li>
  945. <li>
  946. <code>errorAdd &lt;name&gt;</code><br>
  947. F&uuml;gt &lt;name&gt; zu der error-Liste hinzu.
  948. </li>
  949. <li>
  950. <code>errorRemove &lt;name&gt;</code><br>
  951. Entfernt &lt;name&gt; von der error-Liste.
  952. </li>
  953. <li>
  954. <code>inactive</code><br>
  955. Deaktiviert das monitoring. Beachte den leichten semantischen
  956. Unterschied zum disable Attribut: "set inactive" wird bei einem
  957. shutdown automatisch in fhem.state gespeichert, es ist kein save
  958. notwendig.
  959. </li>
  960. <li>
  961. <code>warningAdd &lt;name&gt;</code><br>
  962. F&uuml;gt &lt;name&gt; zu der warning-Liste hinzu.
  963. </li>
  964. <li>
  965. <code>warningRemove &lt;name&gt;</code><br>
  966. Entfernt &lt;name&gt; von der warning-Liste.
  967. </li>
  968. </ul>
  969. <br>
  970. <a name="monitoringget"></a>
  971. <b>Get</b>
  972. <ul>
  973. <li>
  974. <code>all</code><br>
  975. Gibt, durch eine Leerzeile getrennt, die error- und warning-Liste
  976. zur&uuml;ck.<br>
  977. Die Formatierung kann dabei mit den Attributen "errorReturn" und
  978. "warningReturn" eingestellt werden.
  979. </li>
  980. <li>
  981. <code>default</code><br>
  982. Der "default" Wert kann in dem Attribut "getDefault" festgelegt werden
  983. und ist dazu gedacht um die Konfiguration f&uuml;r den
  984. R&uuml;ckgabewert im monitoring Ger&auml;t zu belassen. Wird nichts
  985. angegeben wird "all" verwendent.
  986. </li>
  987. <li>
  988. <code>error</code><br>
  989. Gibt die error-Liste zur&uuml;ck.<br>
  990. Die Formatierung kann dabei mit dem Attribut "errorReturn" eingestellt
  991. werden.
  992. </li>
  993. <li>
  994. <code>warning</code><br>
  995. Gibt die warning-Liste zur&uuml;ck.<br>
  996. Die Formatierung kann dabei mit dem Attribut "warningReturn"
  997. eingestellt werden.
  998. </li>
  999. </ul>
  1000. <br>
  1001. <a name="monitoringreadings"></a>
  1002. <b>Readings</b><br>
  1003. <ul>
  1004. <li>
  1005. <code>error</code><br>
  1006. Durch Komma getrennte Liste von Ger&auml;ten.
  1007. </li>
  1008. <li>
  1009. <code>errorAdd_&lt;name&gt;</code><br>
  1010. Zeigt den Zeitpunkt an wann das Ger&auml;t auf die error-Liste gesetzt
  1011. wird.
  1012. </li>
  1013. <li>
  1014. <code>state</code><br>
  1015. Zeigt den Status (active, inactive oder disabled) an. Bei "active" wird
  1016. angezeigt welches Gerät zu welcher Liste hinzugefügt bzw. von welcher
  1017. Liste entfernt wurde.
  1018. </li>
  1019. <li>
  1020. <code>warning</code><br>
  1021. Durch Komma getrennte Liste von Ger&auml;ten.
  1022. </li>
  1023. <li>
  1024. <code>warningAdd_&lt;name&gt;</code><br>
  1025. Zeigt den Zeitpunkt an wann das Ger&auml;t auf die warning-Liste
  1026. gesetzt wird.
  1027. </li>
  1028. </ul>
  1029. <br>
  1030. <a name="monitoringattr"></a>
  1031. <b>Attribute</b>
  1032. <ul>
  1033. <li>
  1034. <a href="#addStateEvent">
  1035. <u><code>addStateEvent</code></u>
  1036. </a>
  1037. </li>
  1038. <li>
  1039. <code>blacklist</code><br>
  1040. Durch Leerzeichen getrennte Liste von devspecs die ignoriert werden.<br>
  1041. Wenn das Attribut gesetzt wird werden alle Geräte die durch die
  1042. devspecs definiert sind von beiden Listen gelöscht.
  1043. </li>
  1044. <li>
  1045. <code>disable (1|0)</code><br>
  1046. 1: Deaktiviert das monitoring.<br>
  1047. 0: siehe "set active"
  1048. </li>
  1049. <li>
  1050. <a href="#disabledForIntervals">
  1051. <u><code>disabledForIntervals HH:MM-HH:MM HH:MM-HH-MM ...</code></u>
  1052. </a>
  1053. </li>
  1054. <li>
  1055. <code>errorFuncAdd {&lt;perl code&gt;}</code><br>
  1056. In dieser Funktion stehen die folgende Variablen zur Verf&uuml;gung:
  1057. <br>
  1058. <ul>
  1059. <li>
  1060. <code>$name</code><br>
  1061. Name des Event ausl&ouml;senden Ger&auml;tes
  1062. </li>
  1063. <li>
  1064. <code>$event</code><br>
  1065. Beinhaltet das komplette Event, z.B.
  1066. <code>measured-temp: 21.7 (Celsius)</code>
  1067. </li>
  1068. <li>
  1069. <code>$addMatch</code><br>
  1070. Hat den Wert 1, falls das add-event zutrifft
  1071. </li>
  1072. <li>
  1073. <code>$removeMatch</code><br>
  1074. Hat den Wert 1, falls das remove-event zutrifft
  1075. </li>
  1076. <li>
  1077. <code>$SELF</code><br>
  1078. Eigenname des monitoring
  1079. </li>
  1080. </ul>
  1081. Gibt die Funktion eine 1 zur&uuml;ck, wird das Ger&auml;t, nach der
  1082. Wartezeit, auf die error-Liste gesetzt.<br>
  1083. Wenn das Attribut nicht gesetzt ist wird auf <code>$addMatch</code>
  1084. gepr&uuml;ft.
  1085. </li>
  1086. <li>
  1087. <code>errorFuncRemove {&lt;perl code&gt;}</code><br>
  1088. In dieser Funktion stehen die selben Variablen wie bei "errorFuncAdd"
  1089. zur Verf&uuml;gung.<br>
  1090. Gibt die Funktion eine 1 zur&uuml;ck, wird das Ger&auml;t von der
  1091. error-Liste entfernt und noch laufende Timer werden abgebrochen.<br>
  1092. Wenn das Attribut nicht gesetzt ist wird bei einer DEF mit
  1093. <code>&lt;remove-event&gt;</code> auf <code>$removeMatch</code>
  1094. gepr&uuml;ft und bei einer DEF ohne <code>&lt;remove-event&gt;</code>
  1095. auf <code>errorFuncAdd</code>.
  1096. </li>
  1097. <li>
  1098. <code>errorWait &lt;perl code&gt;</code><br>
  1099. Wartezeit bis das Ger&auml;t auf die error-Liste gesetzt wird.
  1100. </li>
  1101. <li>
  1102. <code>errorReturn {&lt;perl code&gt;}</code><br>
  1103. In diesem Attribut stehen folgende Variablen zur Verf&uuml;gung:
  1104. <ul>
  1105. <li>
  1106. <code>@errors</code><br>
  1107. Array mit allen Ger&auml;ten auf der error-Liste.
  1108. </li>
  1109. <li>
  1110. <code>@warnings</code><br>
  1111. Array mit allen Ger&auml;ten auf der warning-Liste.
  1112. </li>
  1113. <li>
  1114. <code>$SELF</code><br>
  1115. Eigenname des monitoring
  1116. </li>
  1117. </ul>
  1118. Mit diesem Attribut kann die Ausgabe die mit "get &lt;name&gt; error"
  1119. erzeugt wird angepasst werden.
  1120. </li>
  1121. <li>
  1122. <code>getDefault (all|error|warning)</code><br>
  1123. Mit diesem Attribut kann festgelegt werden welche Liste/n mit "get
  1124. &lt;name&gt; default" zur&uuml;ck gegeben wird/werden. Wenn das
  1125. Attribut nicht gesetzt ist wird "all" verwendet.
  1126. </li>
  1127. <li>
  1128. <code>setActiveFunc &lt;Anweisung&gt;</code><br>
  1129. Die Anweisung ist einer der FHEM
  1130. <a href="#command"><u>Befehlstypen</u></a> und wird beim definieren des
  1131. monitoring oder bei "set active" ausgef&uuml;hrt.<br>
  1132. F&uuml;r eine Batterie Meldung kann <code>"trigger battery=low
  1133. battery:low"</code> sinnvoll sein.
  1134. </li>
  1135. <li>
  1136. <code>warningFuncAdd {&lt;perl code&gt;}</code><br>
  1137. Wie errorFuncAdd, nur f&uuml;r die warning-Liste.
  1138. </li>
  1139. <li>
  1140. <code>warningFuncRemove {&lt;perl code&gt;}</code><br>
  1141. Wie errorFuncRemove, nur f&uuml;r die warning-Liste.
  1142. </li>
  1143. <li>
  1144. <code>warningWait &lt;perl code&gt;</code><br>
  1145. Wie errorWait, nur f&uuml;r die warning-Liste.
  1146. </li>
  1147. <li>
  1148. <code>warningReturn {&lt;perl code&gt;}</code><br>
  1149. Wie errorReturn, nur f&uuml;r die warning-Liste.
  1150. </li>
  1151. <li>
  1152. <code>whitelist {&lt;perl code&gt;}</code><br>
  1153. Durch Leerzeichen getrennte Liste von devspecs die erlaubt sind
  1154. werden.<br>
  1155. Wenn das Attribut gesetzt wird werden alle Geräte die nicht durch die
  1156. devspecs definiert sind von beiden Listen gelöscht.
  1157. </li>
  1158. <li>
  1159. <a href="#readingFnAttributes">
  1160. <u><code>readingFnAttributes</code></u>
  1161. </a>
  1162. </li>
  1163. </ul>
  1164. <br>
  1165. <a name="monitoringexamples"></a>
  1166. <b>Beispiele</b>
  1167. <ul>
  1168. <a href="https://wiki.fhem.de/wiki/Import_von_Code_Snippets">
  1169. <u>
  1170. Die folgenden beispiel Codes k&ouml;nnen per "Raw defnition"
  1171. importiert werden.
  1172. </u>
  1173. </a>
  1174. <br><br>
  1175. <li>
  1176. <b>
  1177. Globale, flexible Fenster-/T&uuml;r-Offen-Meldungen
  1178. <a href="https://forum.fhem.de/index.php/topic,36504">
  1179. <u>(&auml;hnlich wie im Forum beschrieben)</u>
  1180. </a>
  1181. </b>
  1182. <br>
  1183. <pre>defmod Fenster_monitoring monitoring .*:(open|tilted) .*:closed
  1184. attr Fenster_monitoring errorReturn {return unless(@errors);;\
  1185. $_ = AttrVal($_, "alias", $_) foreach(@errors);;\
  1186. return("Das Fenster \"$errors[0]\" ist schon l&auml;nger ge&ouml;ffnet.") if(int(@errors) == 1);;\
  1187. @errors = sort {lc($a) cmp lc($b)} @errors;;\
  1188. return(join("\n - ", "Die folgenden ".@errors." Fenster sind schon l&auml;nger ge&ouml;ffnet:", @errors))\
  1189. }
  1190. attr Fenster_monitoring errorWait {AttrVal($name, "winOpenTimer", 60*10)}
  1191. attr Fenster_monitoring warningReturn {return unless(@warnings);;\
  1192. $_ = AttrVal($_, "alias", $_) foreach(@warnings);;\
  1193. return("Das Fenster \"$warnings[0]\" ist seit kurzem ge&ouml;ffnet.") if(int(@warnings) == 1);;\
  1194. @warnings = sort {lc($a) cmp lc($b)} @warnings;;\
  1195. return(join("\n - ", "Die folgenden ".@warnings." Fenster sind seit kurzem ge&ouml;ffnet:", @warnings))\
  1196. }</pre>
  1197. Sobald ein Ger&auml;t ein "open" oder "tilded" Event ausl&ouml;st wird
  1198. das Ger&auml;t auf die warning-Liste gesetzt und es wird ein Timer
  1199. gestartet nach dessen Ablauf das Ger&auml;t von der warning- auf die
  1200. error-Liste verschoben wird. Die Wartezeit kann f&uuml;r jedes
  1201. Ger&auml;t per userattr "winOpenTimer" festgelegt werden. Der
  1202. Vorgabewert sind 10 Minuten.<br>
  1203. Sobald ein Ger&auml;t ein "closed" Event ausl&ouml;st wird das
  1204. Ger&auml;t von beiden Listen gel&ouml;scht und noch laufende Timer
  1205. werden gestoppt.
  1206. </li>
  1207. <br>
  1208. <li>
  1209. <b>Batterie&uuml;berwachung</b><br>
  1210. <pre>defmod Batterie_monitoring monitoring .*:battery:.low .*:battery:.ok
  1211. attr Batterie_monitoring errorReturn {return unless(@errors);;\
  1212. $_ = AttrVal($_, "alias", $_) foreach(@errors);;\
  1213. return("Bei dem Ger&auml;t \"$errors[0]\" muss die Batterie gewechselt werden.") if(int(@errors) == 1);;\
  1214. @errors = sort {lc($a) cmp lc($b)} @errors;;\
  1215. return(join("\n - ", "Die folgenden ".@errors." Ger&auml;ten muss die Batterie gewechselt werden:", @errors))\
  1216. }
  1217. attr Batterie_monitoring errorWait 60*60*24*14
  1218. attr Batterie_monitoring warningReturn {return unless(@warnings);;\
  1219. $_ = AttrVal($_, "alias", $_) foreach(@warnings);;\
  1220. return("Bei dem Ger&auml;t \"$warnings[0]\" muss die Batterie demn&auml;chst gewechselt werden.") if(int(@warnings) == 1);;\
  1221. @warnings = sort {lc($a) cmp lc($b)} @warnings;;\
  1222. return(join("\n - ", "Die folgenden ".@warnings." Ger&auml;ten muss die Batterie demn&auml;chst gewechselt werden:", @warnings))\
  1223. }</pre>
  1224. Sobald ein Ger&auml;t ein "battery: low" Event ausl&ouml;st wird das
  1225. Ger&auml;t auf die warning-Liste gesetzt und es wird ein Timer
  1226. gestartet nach dessen Ablauf das Ger&auml;t von der warning- auf die
  1227. error-Liste verschoben wird. Die Wartezeit ist auf 14 Tage
  1228. eingestellt.<br>
  1229. Sobald ein Ger&auml;t ein "battery: ok" Event ausl&ouml;st wird das
  1230. Ger&auml;t von beiden Listen gel&ouml;scht und noch laufende Timer
  1231. werden gestoppt.
  1232. </li>
  1233. <br>
  1234. <li>
  1235. <b>Activity Monitor</b><br>
  1236. <pre>defmod Activity_monitoring monitoring .*:.*
  1237. attr Activity_monitoring errorReturn {return unless(@errors);;\
  1238. $_ = AttrVal($_, "alias", $_) foreach(@errors);;\
  1239. return("Das Ger&auml;t \"$errors[0]\" hat sich seit mehr als 24 Stunden nicht mehr gemeldet.") if(int(@errors) == 1);;\
  1240. @errors = sort {lc($a) cmp lc($b)} @errors;;\
  1241. return(join("\n - ", "Die folgenden ".@errors." Ger&auml;ten haben sich seit mehr als 24 Stunden nicht mehr gemeldet:", @errors))\
  1242. }
  1243. attr Activity_monitoring errorWait 60*60*24
  1244. attr Activity_monitoring warningReturn {return unless(@warnings);;\
  1245. $_ = AttrVal($_, "alias", $_) foreach(@warnings);;\
  1246. return("Das Ger&auml;t \"$warnings[0]\" hat sich seit mehr als 12 Stunden nicht mehr gemeldet.") if(int(@warnings) == 1);;\
  1247. @warnings = sort {lc($a) cmp lc($b)} @warnings;;\
  1248. return(join("\n - ", "Die folgenden ".@warnings." Ger&auml;ten haben sich seit mehr als 12 Stunden nicht mehr gemeldet:", @warnings))\
  1249. }
  1250. attr Activity_monitoring warningWait 60*60*12</pre>
  1251. Ger&auml;te werden erst &uuml;berwacht, wenn sie mindestens ein Event
  1252. ausgel&ouml;st haben. Sollte das Ger&auml;t in 12 Stunden kein weiterer
  1253. Event ausl&ouml;sen, wird es auf die warning-Liste gesetzt. Sollte das
  1254. Ger&auml;t in 24 Stunden kein weiteres Event ausl&ouml;sen, wird es von
  1255. der warning- auf die error-Liste verschoben.
  1256. </li>
  1257. <br>
  1258. <li>
  1259. <b>
  1260. regelm&auml;&szlig;ige Wartungsarbeiten
  1261. (z.B. Tischwasserfilter wechseln)
  1262. </b>
  1263. <br>
  1264. <pre>defmod Wasserfilter_monitoring monitoring Wasserfilter_DashButton:.*:.short
  1265. attr Wasserfilter_monitoring errorReturn {return unless(@errors);;\
  1266. return "Der Wasserfilter muss gewechselt werden.";;\
  1267. }
  1268. attr Wasserfilter_monitoring errorWait 60*60*24*30
  1269. attr Wasserfilter_monitoring warningReturn {return unless(@warnings);;\
  1270. return "Der Wasserfilter muss demn&auml;chst gewechselt werden.";;\
  1271. }
  1272. attr Wasserfilter_monitoring warningWait 60*60*24*25</pre>
  1273. Hierbei wird ein <a href="#dash_dhcp"><u>DashButton</u></a> genutzt um
  1274. FHEM mitzuteilen, dass der Wasserfilter gewechselt wurde.<br>
  1275. Nach 30 Tagen wird der DashButton auf die error-Liste gesetzt.
  1276. </li>
  1277. <br>
  1278. <li>
  1279. <b>
  1280. regelm&auml;&szlig;ige Wartungsarbeiten
  1281. (z.B. Räume putzen)
  1282. </b>
  1283. <br>
  1284. <pre>defmod putzen_DashButton dash_dhcp
  1285. attr putzen_DashButton allowed AC:63:BE:2E:19:AF,AC:63:BE:49:23:48,AC:63:BE:49:5E:FD,50:F5:DA:93:2B:EE,AC:63:BE:B2:07:78
  1286. attr putzen_DashButton devAlias ac-63-be-2e-19-af:Badezimmer\
  1287. ac-63-be-49-23-48:Küche\
  1288. ac-63-be-49-5e-fd:Schlafzimmer\
  1289. 50-f5-da-93-2b-ee:Arbeitszimmer\
  1290. ac-63-be-b2-07-78:Wohnzimmer
  1291. attr putzen_DashButton event-min-interval .*:5
  1292. attr putzen_DashButton port 6767
  1293. attr putzen_DashButton userReadings state {return (split(":", @{$hash->{CHANGED}}[0]))[0];;}
  1294. attr putzen_DashButton widgetOverride allowed:textField-long devAlias:textField-long
  1295. defmod putzen_monitoring monitoring putzen_DashButton:.*:.short
  1296. attr putzen_monitoring errorFuncAdd {$event =~ m/^(.+):/;;\
  1297. $name = $1;;\
  1298. return 1;;\
  1299. }
  1300. attr putzen_monitoring errorReturn {return unless(@errors);;\
  1301. return("Der Raum \"$errors[0]\" muss wieder geputzt werden.") if(int(@errors) == 1);;\
  1302. return(join("\n - ", "Die folgenden Räume müssen wieder geputzt werden:", @errors))\
  1303. }
  1304. attr putzen_monitoring errorWait 60*60*24*7</pre>
  1305. Hierbei werden mehrere <a href="#dash_dhcp"><u>DashButton</u></a>
  1306. genutzt um FHEM mitzuteilen, dass die Räume geputzt wurden.<br>
  1307. Nach 7 Tagen wird der Raum auf die error-Liste gesetzt.<br>
  1308. Der Raum Name ist hierbei jedoch nicht der Geräte-Name, sondern der
  1309. Readings-Name und wird in dem <code>errorFuncAdd</code>-Attribut
  1310. geändert.
  1311. </li>
  1312. <br>
  1313. <li>
  1314. <b>
  1315. Betriebsstunden abh&auml;ngige Wartungsarbeiten
  1316. (z.B. Beamer Filter reinigen)
  1317. </b>
  1318. <br>
  1319. <pre>defmod BeamerFilter_monitoring monitoring Beamer_HourCounter:pulseTimeOverall BeamerFilter_DashButton:.*:.short
  1320. attr BeamerFilter_monitoring userattr errorInterval
  1321. attr BeamerFilter_monitoring errorFuncAdd {return 1\
  1322. if(ReadingsVal($name, "pulseTimeOverall", 0) >= \
  1323. ReadingsVal($name, "pulseTimeService", 0)\
  1324. + (AttrVal($SELF, "errorInterval", 0))\
  1325. && $addMatch\
  1326. );;\
  1327. return;;\
  1328. }
  1329. attr BeamerFilter_monitoring errorFuncRemove {return unless($removeMatch);;\
  1330. fhem(\
  1331. "setreading $name pulseTimeService "\
  1332. .ReadingsVal($name, "pulseTimeOverall", 0)\
  1333. );;\
  1334. return 1;;\
  1335. }
  1336. attr BeamerFilter_monitoring errorInterval 60*60*200
  1337. attr BeamerFilter_monitoring errorReturn {return unless(@errors);;\
  1338. return "Der Filter vom Beamer muss gereinigt werden.";;\
  1339. }
  1340. attr BeamerFilter_monitoring warningFuncAdd {return}
  1341. attr BeamerFilter_monitoring warningFuncRemove {return}</pre>
  1342. Hierbei wird ein <a href="#HourCounter"><u>HourCounter</u></a> genutzt
  1343. um die Betriebsstunden eine Beamer zu erfassen und ein
  1344. <a href="#dash_dhcp"><u>DashButton</u></a> um FHEM mitzuteilen, dass der
  1345. Filter gereinigt wurde.<br>
  1346. Wurde der Filter l&auml;nger als 200 Betriebsstunden nicht gereinigt
  1347. wird das Ger&auml;t auf die error-Liste gesetzt.<br>
  1348. Wurde die Reinigung mit dem DashButton quittiert wird das Ger&auml;t
  1349. von der error-Liste entfernt und der aktuelle Betriebsstunden-Stand in
  1350. dem HourCounter Ger&auml;t gespeichert.
  1351. </li>
  1352. </ul>
  1353. </ul>
  1354. </div>
  1355. =end html_DE
  1356. =cut