98_structure.pm 27 KB

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