98_monitoring.pm 51 KB

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