98_structure.pm 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. # $Id: 98_structure.pm 15129 2017-09-24 08:58:57Z rudolfkoenig $
  2. ##############################################################################
  3. #
  4. # 98_structure.pm
  5. # Copyright by
  6. # e-mail:
  7. #
  8. # This file is part of fhem.
  9. #
  10. # Fhem is free software: you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License as published by
  12. # the Free Software Foundation, either version 2 of the License, or
  13. # (at your option) any later version.
  14. #
  15. # Fhem is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License
  21. # along with fhem. If not, see <http://www.gnu.org/licenses/>.
  22. #
  23. ##############################################################################
  24. package main;
  25. use strict;
  26. use warnings;
  27. #use Data::Dumper;
  28. sub structure_getChangedDevice($);
  29. #####################################
  30. sub
  31. structure_Initialize($)
  32. {
  33. my ($hash) = @_;
  34. $hash->{DefFn} = "structure_Define";
  35. $hash->{UndefFn} = "structure_Undef";
  36. $hash->{NotifyFn} = "structure_Notify";
  37. $hash->{SetFn} = "structure_Set";
  38. $hash->{AttrFn} = "structure_Attr";
  39. $hash->{AttrList} = "async_delay clientstate_priority ".
  40. "clientstate_behavior:relative,relativeKnown,absolute,last ".
  41. "disable disabledForIntervals evaluateSetResult:1,0 ".
  42. $readingFnAttributes;
  43. my %ahash = ( Fn=>"CommandAddStruct",
  44. Hlp=>"<structure> <devspec>,add <devspec> to <structure>" );
  45. $cmds{addstruct} = \%ahash;
  46. my %dhash = ( Fn=>"CommandDelStruct",
  47. Hlp=>"<structure> <devspec>,delete <devspec> from <structure>");
  48. $cmds{delstruct} = \%dhash;
  49. }
  50. sub structAdd($$);
  51. sub
  52. structAdd($$)
  53. {
  54. my ($d, $attrList) = @_;
  55. return if(!$defs{$d});
  56. $defs{$d}{INstructAdd} = 1;
  57. foreach my $c (keys %{$defs{$d}{CONTENT}}) {
  58. if($defs{$c} && $defs{$c}{INstructAdd}) {
  59. Log 1, "recursive structure definition"
  60. } else {
  61. addToDevAttrList($c, $attrList);
  62. structAdd($c, $attrList) if($defs{$c} && $defs{$c}{TYPE} eq "structure");
  63. }
  64. }
  65. delete $defs{$d}{INstructAdd} if($defs{$d});
  66. }
  67. #############################
  68. sub
  69. structure_Define($$)
  70. {
  71. my ($hash, $def) = @_;
  72. my @a = split("[ \t][ \t]*", $def);
  73. my $u = "wrong syntax: define <name> structure <struct-type> [device ...]";
  74. return $u if(int(@a) < 4);
  75. my $devname = shift(@a);
  76. my $modname = shift(@a);
  77. my $stype = shift(@a);
  78. $hash->{ATTR} = $stype;
  79. $hash->{CHANGEDCNT} = 0;
  80. my %list;
  81. my $aList = "$stype ${stype}_map structexclude";
  82. foreach my $a (@a) {
  83. foreach my $d (devspec2array($a)) {
  84. $list{$d} = 1;
  85. addToDevAttrList($d, $aList);
  86. structAdd($d, $aList) if($defs{$d} && $defs{$d}{TYPE} eq "structure");
  87. }
  88. }
  89. $hash->{CONTENT} = \%list;
  90. my @arr = ();
  91. $hash->{".asyncQueue"} = \@arr;
  92. delete $hash->{".cachedHelp"};
  93. @a = ( "set", $devname, $stype, $devname );
  94. structure_Attr(@a);
  95. return undef;
  96. }
  97. #############################
  98. sub
  99. structure_Undef($$)
  100. {
  101. my ($hash, $def) = @_;
  102. my @a = ( "del", $hash->{NAME}, $hash->{ATTR} );
  103. structure_Attr(@a);
  104. return undef;
  105. }
  106. #############################
  107. # returns the really changed Device
  108. #############################
  109. sub
  110. structure_getChangedDevice($)
  111. {
  112. my ($dev) = @_;
  113. my $lastDevice = ReadingsVal($dev, "LastDevice", undef);
  114. $dev = structure_getChangedDevice($lastDevice)
  115. if($lastDevice && $defs{$dev}->{TYPE} eq "structure");
  116. return $dev;
  117. }
  118. #############################
  119. sub
  120. structure_Notify($$)
  121. {
  122. my ($hash, $dev) = @_;
  123. my $me = $hash->{NAME};
  124. my $devmap = $hash->{ATTR}."_map";
  125. if( $dev->{NAME} eq "global" ) {
  126. my $max = int(@{$dev->{CHANGED}});
  127. for (my $i = 0; $i < $max; $i++) {
  128. my $s = $dev->{CHANGED}[$i];
  129. $s = "" if(!defined($s));
  130. if($s =~ m/^RENAMED ([^ ]*) ([^ ]*)$/) {
  131. my ($old, $new) = ($1, $2);
  132. if( exists($hash->{CONTENT}{$old}) ) {
  133. $hash->{DEF} =~ s/(\s+)$old(\s*)/$1$new$2/;
  134. delete( $hash->{CONTENT}{$old} );
  135. $hash->{CONTENT}{$new} = 1;
  136. }
  137. } elsif($s =~ m/^DELETED ([^ ]*)$/) {
  138. my ($name) = ($1);
  139. if( exists($hash->{CONTENT}{$name}) ) {
  140. $hash->{DEF} =~ s/(\s+)$name(\s*)/ /;
  141. $hash->{DEF} =~ s/^ //;
  142. $hash->{DEF} =~ s/ $//;
  143. delete $hash->{CONTENT}{$name};
  144. delete $hash->{".cachedHelp"};
  145. }
  146. }
  147. }
  148. }
  149. return "" if(IsDisabled($me));
  150. #pruefen ob Devices welches das notify ausgeloest hat Mitglied dieser
  151. # Struktur ist
  152. return "" if (! exists $hash->{CONTENT}->{$dev->{NAME}});
  153. # lade das Verhalten, Standard ist absolute
  154. my $behavior = AttrVal($me, "clientstate_behavior", "absolute");
  155. my %clientstate;
  156. my @structPrio = attrSplit($attr{$me}{clientstate_priority})
  157. if($attr{$me} && $attr{$me}{clientstate_priority});
  158. return "" if($hash->{INSET} && !AttrVal($me, "evaluateSetResult", 0));
  159. return "" if(@{$hash->{".asyncQueue"}}); # Do not trigger during async set
  160. if($hash->{INNTFY}) {
  161. Log3 $me, 1, "ERROR: endless loop detected in structure_Notify $me";
  162. return "";
  163. }
  164. $hash->{INNTFY} = 1;
  165. my %priority;
  166. my (@priority, @foo);
  167. for (my $i=0; $i<@structPrio; $i++) {
  168. @foo = split(/\|/, $structPrio[$i]);
  169. for (my $j=0; $j<@foo;$j++) {
  170. $priority{$foo[$j]} = $i+1;
  171. $priority[$i+1]=$foo[0];
  172. }
  173. }
  174. my $minprio = 99999;
  175. my $devstate;
  176. foreach my $d (sort keys %{ $hash->{CONTENT} }) {
  177. next if(!$defs{$d});
  178. if($attr{$d} && $attr{$d}{$devmap}) {
  179. my @gruppe = attrSplit($attr{$d}{$devmap});
  180. my @value;
  181. for (my $i=0; $i<@gruppe; $i++) {
  182. @value = split(":", $gruppe[$i]);
  183. if(@value == 1) { # value[0]:.* -> .*
  184. $devstate = ReadingsVal($d, $value[0], undef);
  185. } elsif(@value == 2) { # state:value[0] -> value[1]
  186. $devstate = ReadingsVal($d, "state", undef);
  187. $devstate = $defs{$d}{STATE} if(!defined($devstate));
  188. if(defined($devstate) && $devstate =~ m/^$value[0]/){
  189. $devstate = $value[1];
  190. $i=99999; # RKO: ??
  191. } else {
  192. $devstate = undef;
  193. }
  194. } elsif(@value == 3) { # value[0]:value[1] -> value[2]
  195. $devstate = ReadingsVal($d, $value[0], undef);
  196. if(defined($devstate) && $devstate =~ m/^$value[1]/){
  197. $devstate = $value[2];
  198. } else {
  199. $devstate = undef;
  200. }
  201. }
  202. if(defined($devstate)) {
  203. if(!$priority{$devstate} && $behavior eq "relativeKnown") {
  204. delete($hash->{INNTFY});
  205. return "";
  206. }
  207. $minprio = $priority{$devstate}
  208. if($priority{$devstate} && $priority{$devstate} < $minprio);
  209. $clientstate{$devstate} = 1;
  210. }
  211. }
  212. } else {
  213. $devstate = ReadingsVal($d, "state", undef);
  214. $devstate = $defs{$d}{STATE} if(!defined($devstate));
  215. if(defined($devstate)) {
  216. if(!$priority{$devstate} && $behavior eq "relativeKnown") {
  217. delete($hash->{INNTFY});
  218. return "";
  219. }
  220. $minprio = $priority{$devstate}
  221. if($priority{$devstate} && $priority{$devstate} < $minprio);
  222. $clientstate{$devstate} = 1;
  223. }
  224. }
  225. $hash->{CONTENT}{$d} = $devstate;
  226. }
  227. my $newState = "undefined";
  228. if($behavior eq "absolute"){
  229. my @cKeys = keys %clientstate;
  230. $newState = (@cKeys == 1 ? $cKeys[0] : "undefined");
  231. } elsif($behavior =~ "^relative" && $minprio < 99999) {
  232. $newState = $priority[$minprio];
  233. } elsif($behavior eq "last"){
  234. my $readingName = AttrVal($dev->{NAME}, $devmap, "state");
  235. $newState = ReadingsVal($dev->{NAME}, $readingName, undef);
  236. $newState = "undefined" if(!defined($newState));
  237. }
  238. Log3 $me, 5, "Update structure '$me' to $newState" .
  239. " because device $dev->{NAME} has changed";
  240. readingsBeginUpdate($hash);
  241. readingsBulkUpdate($hash, "LastDevice", $dev->{NAME}, 0);
  242. readingsBulkUpdate($hash, "LastDevice_Abs",
  243. structure_getChangedDevice($dev->{NAME}), 0);
  244. readingsBulkUpdate($hash, "state", $newState);
  245. readingsEndUpdate($hash, 1);
  246. $hash->{CHANGEDCNT}++;
  247. delete($hash->{INNTFY});
  248. undef;
  249. }
  250. #####################################
  251. sub
  252. CommandAddStruct($)
  253. {
  254. my ($cl, $param) = @_;
  255. my @a = split(" ", $param);
  256. if(int(@a) != 2) {
  257. return "Usage: addstruct <structure_device> <devspec>";
  258. }
  259. my $name = shift(@a);
  260. my $hash = $defs{$name};
  261. if(!$hash || $hash->{TYPE} ne "structure") {
  262. return "$a is not a structure device";
  263. }
  264. foreach my $d (devspec2array($a[0])) {
  265. $hash->{CONTENT}{$d} = 1;
  266. $hash->{DEF} .= " $d";
  267. }
  268. @a = ( "set", $hash->{NAME}, $hash->{ATTR}, $hash->{NAME} );
  269. structure_Attr(@a);
  270. delete $hash->{".cachedHelp"};
  271. return undef;
  272. }
  273. #####################################
  274. sub
  275. CommandDelStruct($)
  276. {
  277. my ($cl, $param) = @_;
  278. my @a = split(" ", $param);
  279. if(int(@a) != 2) {
  280. return "Usage: delstruct <structure_device> <devspec>";
  281. }
  282. my $name = shift(@a);
  283. my $hash = $defs{$name};
  284. if(!$hash || $hash->{TYPE} ne "structure") {
  285. return "$a is not a structure device";
  286. }
  287. foreach my $d (devspec2array($a[0])) {
  288. delete($hash->{CONTENT}{$d});
  289. $hash->{DEF} =~ s/\b$d\b//g;
  290. }
  291. $hash->{DEF} =~ s/ / /g;
  292. @a = ( "del", $hash->{NAME}, $hash->{ATTR} );
  293. structure_Attr(@a);
  294. delete $hash->{".cachedHelp"};
  295. return undef;
  296. }
  297. ###################################
  298. sub
  299. structure_Set($@)
  300. {
  301. my ($hash, @list) = @_;
  302. my $ret = "";
  303. my %pars;
  304. # see Forum # 28623 for .cachedHelp
  305. return $hash->{".cachedHelp"} if($list[1] eq "?" && $hash->{".cachedHelp"});
  306. $hash->{INSET} = 1;
  307. my $startAsyncProcessing;
  308. my $filter;
  309. if($list[1] ne "?") {
  310. my $state = join(" ", @list[1..@list-1]);
  311. readingsSingleUpdate($hash, "state", $state, 1);
  312. if($state =~ /^\[(FILTER=.*)]/) {
  313. delete($hash->{INSET}); # Experimental, Forum #35382
  314. $filter = $1;
  315. @list = split(" ", $list[0] ." ". substr($state, length($filter)+2));
  316. }
  317. }
  318. my @devList = split("[ \t][ \t]*", $hash->{DEF});
  319. shift @devList;
  320. if(@list > 1 && $list[$#list] eq "reverse") {
  321. pop @list;
  322. @devList = reverse @devList;
  323. }
  324. foreach my $d (@devList) {
  325. next if(!$defs{$d});
  326. if($defs{$d}{INSET}) {
  327. Log3 $hash, 1, "ERROR: endless loop detected for $d in " . $hash->{NAME};
  328. next;
  329. }
  330. if($attr{$d} && $attr{$d}{structexclude}) {
  331. my $se = $attr{$d}{structexclude};
  332. next if($hash->{NAME} =~ m/$se/);
  333. }
  334. $list[0] = $d;
  335. my $sret;
  336. if($filter) {
  337. my $ret;
  338. my $dl0 = $defs{$list[0]};
  339. if(defined($dl0) && $dl0->{TYPE} eq "structure") {
  340. my ($ostate,$ocnt) = ($dl0->{STATE}, $dl0->{CHANGEDCNT});
  341. $ret = AnalyzeCommand(undef, "set $list[0] [$filter] ".
  342. join(" ", @list[1..@list-1]) );
  343. if($dl0->{CHANGEDCNT} == $ocnt) { # Forum #70488
  344. $dl0->{STATE} = $dl0->{READINGS}{state}{VAL} = $ostate;
  345. structure_Notify($hash, $dl0);
  346. }
  347. } else {
  348. $ret = AnalyzeCommand(undef, "set $list[0]:$filter ".
  349. join(" ", @list[1..@list-1]) );
  350. }
  351. $sret .= $ret if( $ret );
  352. } else {
  353. my $async_delay = AttrVal($hash->{NAME}, "async_delay", undef);
  354. if(defined($async_delay) && $list[1] ne "?") {
  355. $startAsyncProcessing = $async_delay if(!@{$hash->{".asyncQueue"}});
  356. push @{$hash->{".asyncQueue"}}, join(" ", @list);
  357. } else {
  358. $sret .= CommandSet(undef, join(" ", @list));
  359. }
  360. }
  361. if($sret) {
  362. $ret .= "\n" if($ret);
  363. $ret .= $sret;
  364. if($list[1] eq "?") {
  365. $sret =~ s/.*one of //;
  366. map { $pars{$_} = 1 } split(" ", $sret);
  367. }
  368. }
  369. }
  370. delete($hash->{INSET});
  371. Log3 $hash, 5, "SET: $ret" if($ret);
  372. if(defined($startAsyncProcessing)) {
  373. InternalTimer(gettimeofday()+$startAsyncProcessing,
  374. "structure_asyncQueue", $hash, 0);
  375. }
  376. return undef if($list[1] ne "?");
  377. $hash->{".cachedHelp"} = "Unknown argument ?, choose one of " .
  378. join(" ", sort keys(%pars));
  379. return $hash->{".cachedHelp"};
  380. }
  381. sub
  382. structure_asyncQueue(@)
  383. {
  384. my ($hash) = @_;
  385. my $next_cmd = shift @{$hash->{".asyncQueue"}};
  386. if(defined $next_cmd) {
  387. CommandSet(undef, $next_cmd);
  388. my $async_delay = AttrVal($hash->{NAME}, "async_delay", 0);
  389. InternalTimer(gettimeofday()+$async_delay,"structure_asyncQueue",$hash,0);
  390. }
  391. return undef;
  392. }
  393. ###################################
  394. sub
  395. structure_Attr($@)
  396. {
  397. my ($type, @list) = @_;
  398. my %ignore = (
  399. alias=>1,
  400. async_delay=>1,
  401. clientstate_behavior=>1,
  402. clientstate_priority=>1,
  403. devStateIcon=>1,
  404. disable=>1,
  405. disabledForIntervals=>1,
  406. group=>1,
  407. icon=>1,
  408. room=>1,
  409. stateFormat=>1,
  410. webCmd=>1,
  411. userattr=>1
  412. );
  413. return undef if($ignore{$list[1]});
  414. my $me = $list[0];
  415. my $hash = $defs{$me};
  416. if($hash->{INATTR}) {
  417. Log3 $me, 1, "ERROR: endless loop detected in structure_Attr for $me";
  418. return;
  419. }
  420. $hash->{INATTR} = 1;
  421. my $ret = "";
  422. my @devList = split("[ \t][ \t]*", $hash->{DEF});
  423. shift @devList;
  424. foreach my $d (@devList) {
  425. next if(!$defs{$d});
  426. if($attr{$d} && $attr{$d}{structexclude}) {
  427. my $se = $attr{$d}{structexclude};
  428. next if("$me:$list[1]" =~ m/$se/);
  429. }
  430. $list[0] = $d;
  431. my $sret;
  432. if($type eq "del") {
  433. $sret .= CommandDeleteAttr(undef, join(" ", @list));
  434. } else {
  435. $sret .= CommandAttr(undef, join(" ", @list));
  436. }
  437. if($sret) {
  438. $ret .= "\n" if($ret);
  439. $ret .= $sret;
  440. }
  441. }
  442. delete($hash->{INATTR});
  443. Log3 $me, 4, "Stucture attr $type: $ret" if($ret);
  444. return undef;
  445. }
  446. 1;
  447. =pod
  448. =item helper
  449. =item summary organize/structure multiple devices
  450. =item summary_DE mehrere Ger&auml;te zu einem zusammenfassen
  451. =begin html
  452. <a name="structure"></a>
  453. <h3>structure</h3>
  454. <ul>
  455. <br>
  456. <a name="structuredefine"></a>
  457. <b>Define</b>
  458. <ul>
  459. <code>define &lt;name&gt; structure &lt;struct_type&gt; &lt;dev1&gt; &lt;dev2&gt; ...</code>
  460. <br><br>
  461. The structure device is used to organize/structure devices in order to
  462. set groups of them at once (e.g. switching everything off in a house).<br>
  463. The list of attached devices can be modified through the addstruct /
  464. delstruct commands. Each attached device will get the attribute
  465. &lt;struct_type&gt;=&lt;name&gt;<br> when it is added to the list, and the
  466. attribute will be deleted if the device is deleted from the structure.
  467. <br>
  468. The structure devices can also be added to a structure, e.g. you can have
  469. a building consisting of levels which consists of rooms of devices.
  470. <br>
  471. Example:<br>
  472. <ul>
  473. <li>define kitchen structure room lamp1 lamp2</li>
  474. <li>addstruct kitchen TYPE=FS20</li>
  475. <li>delstruct kitchen lamp1</li>
  476. <li>define house structure building kitchen living</li>
  477. <li>set house off</li>
  478. </ul>
  479. <br>
  480. </ul>
  481. <br>
  482. <a name="structureset"></a>
  483. <b>Set</b>
  484. <ul>
  485. Every set command is propagated to the attached devices. Exception: if an
  486. attached device has an attribute structexclude, and the attribute value
  487. matches (as a regexp) the name of the current structure.<br>
  488. If the set is of the form <code>set &lt;structure&gt;
  489. [FILTER=&lt;filter&gt;] &lt;type-specific&gt;</code> then
  490. :FILTER=&lt;filter&gt; will be appended to the device name in the
  491. propagated set for the attached devices like this: <code>set
  492. <devN>:FILTER=&lt;filter&gt; &lt;type-specific&gt;</code><br>
  493. If the last set parameter is "reverse", then execute the set commands in
  494. the reverse order.
  495. </ul>
  496. <br>
  497. <a name="structureget"></a>
  498. <b>Get</b>
  499. <ul>
  500. get is not supported through a structure device.
  501. </ul>
  502. <br>
  503. <a name="structureattr"></a>
  504. <b>Attributes</b>
  505. <ul>
  506. <a name="async_delay"></a>
  507. <li>async_delay<br>
  508. If this attribute is defined, unfiltered set commands will not be
  509. executed in the clients immediately. Instead, they are added to a queue
  510. to be executed later. The set command returns immediately, whereas the
  511. clients will be set timer-driven, one at a time. The delay between two
  512. timercalls is given by the value of async_delay (in seconds) and may be
  513. 0 for fastest possible execution. This way, excessive delays often
  514. known from large structures, can be broken down in smaller junks.
  515. </li>
  516. <li><a href="#disable">disable</a></li>
  517. <li><a href="#disabledForIntervals">disabledForIntervals</a></li>
  518. <a name="clientstate_behavior"></a>
  519. <li>clientstate_behavior<br>
  520. The backward propagated status change from the devices to this structure
  521. works in two different ways.
  522. <ul>
  523. <li>absolute<br>
  524. The structure status will changed to the common device status of all
  525. defined devices to this structure if all devices are identical.
  526. Otherwise the structure status is "undefined".
  527. </li>
  528. <li>relative<br>
  529. See below for clientstate_priority.
  530. </li>
  531. <li>relativeKnown<br>
  532. Like relative, but do not trigger on events not described in
  533. clientstate_priority. Needed e.g. for HomeMatic devices.
  534. </li>
  535. <li>last<br>
  536. The structure state corresponds to the state of the device last changed.
  537. </li>
  538. </ul>
  539. </li>
  540. <a name="clientstate_priority"></a>
  541. <li>clientstate_priority<br>
  542. If clientstate_behavior is set to relative, then you have to set the
  543. attribute "clientstate_priority" with all states of the defined devices
  544. to this structure in descending order. Each group is delemited by
  545. space or /. Each entry of one group is delimited by "pipe". The status
  546. represented by the structure is the first entry of each group.
  547. Example:<br>
  548. <ul>
  549. <li>attr kitchen clientstate_behavior relative</li>
  550. <li>attr kitchen clientstate_priority An|On|on Aus|Off|off</li>
  551. <li>attr house clientstate_priority Any_On|An All_Off|Aus</li>
  552. </ul>
  553. In this example the status of kitchen is either on or off. The status
  554. of house is either Any_on or All_off.
  555. </li>
  556. <li>&lt;struct_type&gt;_map<br>
  557. With this attribute, which has to specified for the structure-
  558. <b>member</b>, you can redefine the value reported by a specific
  559. structure-member for the structure value. The attribute has three
  560. variants:
  561. <ul>
  562. <li>readingName<br>
  563. take the value from readingName instead of state.
  564. </li>
  565. <li>oldVal:newVal<br>
  566. if the state reading matches oldVal, then replace it with newVal
  567. </li>
  568. <li>readingName:oldVal:newVal<br>
  569. if readingName matches oldVal, then replace it with newVal
  570. </li>
  571. </ul>
  572. Example:
  573. <ul>
  574. <li>define door OWSWITCH &lt;ROMID&gt</li>
  575. <li>define lamp1 dummy</li>
  576. <li>attr lamp1 cmdlist on off</li>
  577. <li>define kitchen structure struct_kitchen lamp1 door</li>
  578. <li>attr kitchen clientstate_priority An|on OK|Aus|off</li>
  579. <li>attr lamp1 struct_kitchen_map on:An off:Aus</li>
  580. <li>attr door struct_kitchen_map A:open:on A:closed:off</li>
  581. <li>attr door2 struct_kitchen_map A</li>
  582. </ul>
  583. </li>
  584. <a name="evaluateSetResult"></a>
  585. <li>evaluateSetResult<br>
  586. if a set command sets the state of the structure members to something
  587. different from the set command (like set statusRequest), then you have to
  588. set this attribute to 1 in order to enable the structure instance to
  589. compute the new status.
  590. </li>
  591. <a name="structexclude"></a>
  592. <li>structexclude<br>
  593. exclude the device from set/notify or attribute operations. For the set
  594. and notify the value of structexclude must match the structure name,
  595. for the attr/deleteattr commands ist must match the combination of
  596. structure_name:attribute_name. Examples:<br>
  597. <ul>
  598. <code>
  599. define kitchen structure room lamp1 lamp2<br>
  600. attr lamp1 structexclude kitchen<br>
  601. attr lamp1 structexclude kitchen:stateFormat<br>
  602. </code>
  603. </ul>
  604. </li>
  605. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  606. </ul>
  607. <br>
  608. </ul>
  609. =end html
  610. =begin html_DE
  611. <a name="structure"></a>
  612. <h3>structure</h3>
  613. <ul>
  614. <br>
  615. <a name="structuredefine"></a>
  616. <b>Define</b>
  617. <ul>
  618. <code>define &lt;name&gt; structure &lt;struct_type&gt; &lt;dev1&gt;
  619. &lt;dev2&gt; ...</code> <br><br>
  620. Mit dem Device "Structure" werden Strukturen/Zusammenstellungen von anderen
  621. Devices erstellt um sie zu Gruppen zusammenzufassen. (Beispiel: im Haus
  622. alles ausschalten) <br>
  623. Die Liste der Devices die einer Struktur zugeordnet sind kann duch das
  624. Kommando <code>addstruct / delstruct</code> im laufenden Betrieb
  625. ver&auml;ndert werden. Es k&ouml;nnen sowohl einzelne Devices als auch
  626. Gruppen von Devices (TYPE=FS20) zugef&uuml;gt werden. Jedes zugef&uuml;gt
  627. Device erh&auml;lt zwei neue Attribute &lt;struct_type&gt;=&lt;name&gt;
  628. sowie &lt;struct_type&gt;_map wenn es zu einer Struktur zugef&uuml;gt
  629. wurde. Diese Attribute werden wieder automatisch entfernt, sobald das
  630. Device von der Struktur entfernt wird.<br>
  631. Eine Struktur kann ebenfalls zu einer anderen Struktur zugef&uuml;gt
  632. werden. Somit k&ouml;nnen z b. kaskadierende Strukturen erstellt werden.
  633. (Z.b. KG,EG,OG, Haus)
  634. Beispiel:<br>
  635. <ul>
  636. <li>define Kueche structure room lampe1 lampe2</li>
  637. <li>addstruct Kueche TYPE=FS20</li>
  638. <li>delstruct Kueche lampe1</li>
  639. <li>define house structure building kitchen living</li>
  640. <li>set house off</li>
  641. </ul>
  642. <br>
  643. </ul>
  644. <br>
  645. <a name="structureset"></a>
  646. <b>Set</b>
  647. <ul>
  648. Jedes set Kommando wird an alle Devices dieser Struktur weitergegeben.<br>
  649. Aussnahme: das Attribut structexclude ist in einem Device definiert und
  650. dessen Attributwert matched als Regexp zum Namen der aktuellen
  651. Struktur.<br> Wenn das set Kommando diese Form hat <code>set
  652. &lt;structure&gt; [FILTER=&lt;filter&gt;] &lt;type-specific&gt;</code> wird
  653. :FILTER=&lt;filter&gt; bei der Weitergebe der set an jeden Devicenamen wie
  654. folgt angehängt: <code>set <devN>:FILTER=&lt;filter&gt;
  655. &lt;type-specific&gt;</code><br>
  656. Falls der letzte Parameter reverse ist, dann werden die Befehle in der
  657. umgekehrten Reihenfolge ausgef&uuml;hrt.
  658. </ul>
  659. <br>
  660. <a name="structureget"></a>
  661. <b>Get</b>
  662. <ul>
  663. Get wird im Structur-Device nicht unterst&uuml;tzt.
  664. </ul>
  665. <br>
  666. <a name="structureattr"></a>
  667. <b>Attribute</b>
  668. <ul>
  669. <a name="async_delay"></a>
  670. <li>async_delay<br>
  671. Wenn dieses Attribut gesetzt ist, werden ungefilterte set Kommandos nicht
  672. sofort an die Clients weitergereicht. Stattdessen werden sie einer
  673. Warteschlange hinzugef&uuml;gt, um sp&auml;ter ausgef&uuml;hrt zu werden.
  674. Das set Kommando kehrt sofort zur&uuml;ck, die Clients werden danach
  675. timer-gesteuert einzeln abgearbeitet. Die Zeit zwischen den
  676. Timer-Aufrufen ist dabei durch den Wert von async_delay (in Sekunden)
  677. gegeben, ein Wert von 0 entspricht der schnellstm&ouml;glichen Abfolge.
  678. So k&ouml;nnen besonders lange Verz&ouml;gerungen, die gerade bei
  679. gro&szlig;en structures vorkommen k&ouml;nnen, in unproblematischere
  680. H&auml;ppchen zerlegt werden.
  681. </li>
  682. <li><a href="#disable">disable</a></li>
  683. <li><a href="#disabledForIntervals">disabledForIntervals</a></li>
  684. <a name="clientstate_behavior"></a>
  685. <li>clientstate_behavior<br>
  686. Der Status einer Struktur h&auml;ngt von den Status der zugef&uuml;gten
  687. Devices ab. Dabei wird das propagieren der Status der Devices in zwei
  688. Gruppen klassifiziert und mittels diesem Attribut definiert:
  689. <ul>
  690. <li>absolute<br>
  691. Die Struktur wird erst dann den Status der zugef&uuml;gten Devices
  692. annehmen, wenn alle Devices einen identischen Status vorweisen. Bei
  693. unterschiedlichen Devictypen kann dies per Attribut
  694. &lt;struct_type&gt;_map pro Device beinflusst werden. Andernfalls hat
  695. die Struktur den Status "undefined".
  696. </li>
  697. <li>relative<br>
  698. S.u. clientstate_priority.
  699. </li>
  700. <li>relativeKnown<br>
  701. wie relative, reagiert aber nicht auf unbekannte, in
  702. clientstate_priority nicht beschriebene Ereignisse. Wird f&uuml;r
  703. HomeMatic Ger&auml;te ben&ouml;tigt.
  704. </li>
  705. <li>last<br>
  706. Die Struktur &uuml;bernimmt den Status des zuletzt ge&auml;nderten
  707. Ger&auml;tes.
  708. </li>
  709. </ul>
  710. </li>
  711. <a name="clientstate_priority"></a>
  712. <li>clientstate_priority<br>
  713. Wird die Struktur auf ein relatives Verhalten eingestellt, so wird die
  714. Priorit&auml;t der Devicestatus &uuml;ber das Attribut
  715. <code>clientstate_priority</code> beinflusst. Die Priorit&auml;ten sind
  716. in absteigender Reihenfolge anzugeben. Dabei k&ouml;nnen Gruppen mit
  717. identischer Priorit&auml;t angegeben werden, um zb. unterschiedliche
  718. Devicetypen zusammenfassen zu k&ouml;nnen. Jede Gruppe wird durch
  719. Leerzeichen oder /, jeder Eintrag pro Gruppe durch Pipe getrennt. Der
  720. Status der Struktur ist der erste Eintrag in der entsprechenden Gruppe.
  721. <br>Beispiel:
  722. <ul>
  723. <li>attr kueche clientstate_behavior relative</li>
  724. <li>attr kueche clientstate_priority An|On|on Aus|Off|off</li>
  725. <li>attr haus clientstate_priority Any_On|An All_Off|Aus</li>
  726. </ul>
  727. In diesem Beipiel nimmt die Struktur <code>kueche</code>entweder den
  728. Status <code>An</code> oder <code>Aus</code> an. Die Struktur
  729. <code>haus</code> nimmt entweder den Status <code>Any_on</code> oder
  730. <code>All_off</code> an. Sobald ein Device der Struktur
  731. <code>haus</code> den Status <code>An</code> hat nimmt die Struktur den
  732. Status <code>Any_On</code> an. Um dagegen den Status <code>All_off</code>
  733. anzunehmen, m&uuml;ssen alle Devices dieser Struktur auf <code>off</code>
  734. stehen.
  735. </li>
  736. <li>&lt;struct_type&gt;_map<br>
  737. Mit diesem Attribut, das dem Struktur-<b>Mitglied</b> zugewiesen werden
  738. muss, koennen die Werte, die die einzelnen Struktur- Mitglieder melden,
  739. umdefiniert werden, damit man unterschiedliche Geraeteklassen
  740. zusammenfassen kann. Es existieren drei Varianten:
  741. <ul>
  742. <li>readingName<br>
  743. nehme den Wert von readingName anstatt von state
  744. </li>
  745. <li>oldVal:newVal<br>
  746. falls der Wert der state Reading oldVal (als regex) ist, dann ersetze
  747. diesen mit newVal.
  748. </li>
  749. <li>readingName:oldVal:newVal<br>
  750. falls der Wert der readingName oldVal (als regex) ist, dann ersetze
  751. diesen mit newVal.
  752. </li>
  753. </ul>
  754. Beispiel:<br>
  755. <ul>
  756. <li>define tuer OWSWITCH &lt;ROMID&gt</li>
  757. <li>define lampe1 dummy</li>
  758. <li>attr lampe1 cmdlist on off</li>
  759. <li>define kueche structure struct_kitchen lamp1 door</li>
  760. <li>attr kueche clientstate_priority An|on OK|Aus|off</li>
  761. <li>attr lampe1 struct_kitchen_map on:An off:Aus</li>
  762. <li>attr tuer struct_kitchen_map A:open:on A:closed:off</li>
  763. <li>attr tuer2 struct_kitchen_map A</li>
  764. </ul>
  765. </li>
  766. <a name="evaluateSetResult"></a>
  767. <li>evaluateSetResult<br>
  768. Falls ein set Befehl den Status der Struktur-Mitglieder auf was
  769. unterschiedliches setzt (wie z.Bsp. beim set statusRequest), dann muss
  770. dieses Attribut auf 1 gesetzt werden, wenn die Struktur Instanz diesen
  771. neuen Status auswerten soll.
  772. </li>
  773. <li>structexclude<br>
  774. Bei gesetztem Attribut wird set, attr/deleteattr ignoriert. Dies
  775. trifft ebenfalls auf die Weitergabe des Devicestatus an die Struktur zu.
  776. Fuer set und fuer die Status-Weitergabe muss der Wert den Strukturnamen
  777. matchen, bei einem Attribut-Befehl die Kombination
  778. Strukturname:Attributname.
  779. Beispiel:
  780. <ul>
  781. <code>
  782. define kitchen structure room lamp1 lamp2<br>
  783. attr lamp1 structexclude kitchen<br>
  784. attr lamp1 structexclude kitchen:stateFormat<br>
  785. </code>
  786. </ul>
  787. </li>
  788. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  789. </ul>
  790. <br>
  791. </ul>
  792. =end html_DE
  793. =cut