11_FHT8V.pm 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. #############################################
  2. # $Id: 11_FHT8V.pm 14888 2017-08-13 12:07:12Z rudolfkoenig $
  3. package main;
  4. use strict;
  5. use warnings;
  6. sub
  7. FHT8V_Initialize($)
  8. {
  9. my ($hash) = @_;
  10. $hash->{DefFn} = "FHT8V_Define";
  11. $hash->{SetFn} = "FHT8V_Set";
  12. $hash->{GetFn} = "FHT8V_Get";
  13. $hash->{AttrList} = "IODev dummy:1,0 ignore:1,0 ".
  14. $readingFnAttributes;
  15. }
  16. #############################
  17. sub
  18. FHT8V_Define($$)
  19. {
  20. my ($hash, $def) = @_;
  21. my @a = split("[ \t][ \t]*", $def);
  22. my $n = $a[0];
  23. return "wrong syntax: define <name> FHT8V housecode [IODev|FHTID]" if(@a < 3);
  24. return "wrong housecode format: specify a 4 digit hex value "
  25. if(($a[2] !~ m/^[a-f0-9]{4}$/i));
  26. my $fhtid;
  27. if(@a > 3 && $defs{$a[3]}) {
  28. $hash->{IODev} = $defs{$a[3]};
  29. } else {
  30. AssignIoPort($hash);
  31. $fhtid = $a[3] if($a[3]);
  32. }
  33. return "$n: No IODev found" if(!$hash->{IODev});
  34. $fhtid = $hash->{IODev}->{FHTID} if(!$fhtid);
  35. return "$n: Wrong IODev $hash->{IODev}{NAME}, has no FHTID" if(!$fhtid);
  36. #####################
  37. # Check if the address corresponds to the CUL
  38. my $ioaddr = hex($fhtid);
  39. my $myaddr = hex($a[2]);
  40. my ($io1, $io0) = (int($ioaddr/255), $ioaddr % 256);
  41. my ($my1, $my0) = (int($myaddr/255), $myaddr % 256);
  42. if($my1 < $io1 || $my1 > $io1+7 || $io0 != $my0) {
  43. my $vals = "";
  44. for(my $m = 0; $m <= 7; $m++) {
  45. $vals .= sprintf(" %2x%2x", $io1+$m, $io0);
  46. }
  47. return sprintf("Wrong housecode: must be one of$vals");
  48. }
  49. $hash->{addr} = uc($a[2]);
  50. $hash->{idx} = sprintf("%02X", $my1-$io1);
  51. $hash->{STATE} = "defined";
  52. return "";
  53. }
  54. sub
  55. FHT8V_Set($@)
  56. {
  57. my ($hash, @a) = @_;
  58. my $n = $hash->{NAME};
  59. return "Need a parameter for set" if(@a < 2);
  60. my $arg = $a[1];
  61. if($arg eq "valve" ) {
  62. return "Set valve needs a numeric parameter between 0 and 100"
  63. if(@a != 3 || $a[2] !~ m/^\d+$/ || $a[2] < 0 || $a[2] > 100);
  64. Log3 $n, 3, "FHT8V set $n $arg $a[2]";
  65. $hash->{STATE} = sprintf("%d %%", $a[2]);
  66. readingsSingleUpdate($hash, "valve", $a[2], 1);
  67. IOWrite($hash, "", sprintf("T%s0026%02X", $hash->{addr}, $a[2]*2.55));
  68. } elsif ($arg eq "pair" ) {
  69. Log3 $n, 3, "FHT8V set $n $arg";
  70. IOWrite($hash, "", sprintf("T%s002f00", $hash->{addr}));
  71. } elsif ($arg eq "decalc" ) {
  72. Log3 $n, 3, "FHT8V set $n $arg";
  73. $hash->{STATE} = "lime-protection";
  74. IOWrite($hash, "", sprintf("T%s000A00", $hash->{addr}));
  75. } else {
  76. return "Unknown argument $a[1], choose one of valve pair decalc"
  77. }
  78. return "";
  79. }
  80. sub
  81. FHT8V_Get($@)
  82. {
  83. my ($hash, @a) = @_;
  84. my $n = $hash->{NAME};
  85. return "Need a parameter for get" if(@a < 2);
  86. my $arg = $a[1];
  87. if($arg eq "valve" ) {
  88. my $io = $hash->{IODev};
  89. my $msg = CallFn($io->{NAME}, "GetFn", $io, (" ", "raw", "T10"));
  90. my $idx = $hash->{idx};
  91. return int(hex($1)/2.55) if($msg =~ m/$idx:26(..)/);
  92. return "N/A";
  93. }
  94. return "Unknown argument $a[1], choose one of valve"
  95. }
  96. 1;
  97. =pod
  98. =item summary module for the FHT8v controlled directly by a culfw device
  99. =item summary_DE Anbindung von FHT8v Ventilen &uuml;ber ein culfw Ger&auml;t
  100. =begin html
  101. <a name="FHT8V"></a>
  102. <h3>FHT8V</h3>
  103. <ul>
  104. Fhem can directly control FHT8V type valves via a <a href="#CUL">CUL</a>
  105. device without an intermediate FHT. This paragraph documents one of the
  106. building blocks, the other is the <a href="#PID">PID</a> device.
  107. <br>
  108. <br>
  109. <a name="FHT8Vdefine"></a>
  110. <b>Define</b>
  111. <ul>
  112. <code>define &lt;name&gt; FHT8V &lt;housecode&gt; [IODev|FHTID]</code>
  113. <br><br>
  114. <code>&lt;housecode&gt;</code> is a four digit hex number,
  115. and must have the following relation to the housecode of the corresponding CUL
  116. device:
  117. <ul>given the CUL housecode as AABB, then this housecode must be
  118. of the form CCBB, where CC is greater or equal to AA, but less then AA+8.
  119. </ul>
  120. This form is chosen so that the CUL can update all FHT8V valve states
  121. within 2 minutes.
  122. <br>
  123. <br>
  124. <code>&lt;IODev&gt;</code> must be specified if the last defined CUL device
  125. is not the one to use. Usually this is done voa the <a
  126. href="#IODev">IODev</a> attribute, but as the address checked is performed
  127. at the definition, we must use an exception here.<br>
  128. As an alternative you can specify the FHTID of the assigned IODev device
  129. (instead of the IODev itself), this method is needed if you are using FHT8V
  130. through FHEM2FHEM.
  131. <br>
  132. Examples:
  133. <ul>
  134. <code>define wz FHT8V 3232</code><br>
  135. </ul>
  136. </ul>
  137. <br>
  138. <a name="FHT8Vset"></a>
  139. <b>Set </b>
  140. <ul>
  141. <li>set &lt;name&gt; valve &lt;value;&gt;<br>
  142. Set the valve to the given value (in percent, from 0 to 100).
  143. </li>
  144. <li>set &lt;name&gt; pair<br>
  145. Pair the valve with the CUL.
  146. </li>
  147. <li>set &lt;name&gt; decalc<br>
  148. Start a decalcifying cycle on the given valve
  149. </li>
  150. </ul>
  151. <br>
  152. <a name="FHT8Vget"></a>
  153. <b>Get </b>
  154. <ul>
  155. <li>get &lt;name&gt; valve<br>
  156. Read back the valve position from the CUL FHT buffer, and convert it to percent (from 0 to 100).
  157. </li>
  158. </ul>
  159. <br>
  160. <a name="FHT8Vattr"></a>
  161. <b>Attributes</b>
  162. <ul>
  163. <li><a href="#IODev">IODev</a></li>
  164. <li><a href="#dummy">dummy</a></li>
  165. <li><a href="#ignore">ignore</a></li>
  166. <li><a href="#eventMap">eventMap</a></li><br>
  167. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  168. </ul>
  169. <br>
  170. </ul>
  171. =end html
  172. =begin html_DE
  173. <a name="FHT8V"></a>
  174. <h3>FHT8V</h3>
  175. <ul>
  176. Fhem kann die Ventile vom Typ FHT8V durch einen <a href="#CUL">CUL</a>
  177. direkt, ohne zwischengeschalteten FHT, ansteuern. Dieser Abschnitt
  178. beschreibt einen der Bausteine, der andere ist das <a href="#PID">PID</a> Device.
  179. <br>
  180. <br>
  181. <a name="FHT8Vdefine"></a>
  182. <b>Define</b>
  183. <ul>
  184. <code>define &lt;name&gt; FHT8V &lt;Hauscode&gt; [IODev|FHTID]</code>
  185. <br><br>
  186. <code>&lt;Hauscode&gt;</code> ist eine vierstellige hexadezimale Zahl, die
  187. folgende Beziehung zum zust&auml;ndigen CUL-Device aufweisen muss:
  188. <ul>Bei gegebenem Hauscode des CUL als AABB muss dieser Hauscode die Form CCBB
  189. haben, wobei CC gr&ouml;&szlig;er oder gleich AA, aber kleiner AA+8 sein muss.
  190. </ul>
  191. Diese Form wurde gew&auml;hlt, damit der CUL alle FHT8V-Ventilstellungen
  192. innerhalb von zwei Minuten aktualisieren kann. <br><br>
  193. <code>&lt;IODev&gt;</code> mu&szlig; angegeben werden, wenn der als letzter
  194. definierte CUL nicht der zust&auml;ndige ist. Normalerweise wird dies mit
  195. dem <a href="#IODev">IODev</a>-Attribut gesetzt, da die
  196. &Uuml;berpr&uuml;fung der Adresse aber w&auml;hrend der Definition erfolgt,
  197. brauchen wir hier eine Ausnahme. <br>
  198. Als Alternative kann man die FHTID des zust&auml;ndigen IODev-Ger&auml;tes
  199. (anstelle des IODev selbst) setzen. Diese Methode ist n&ouml;tig, wenn man
  200. FHT8V &uuml;ber FHEM2FHEM betreibt. <br>
  201. Beispiel:
  202. <ul>
  203. <code>define wz FHT8V 3232</code><br>
  204. </ul>
  205. </ul>
  206. <br>
  207. <a name="FHT8Vset"></a>
  208. <b>Set </b>
  209. <ul>
  210. <li>set &lt;name&gt; valve &lt;Wert&gt;<br>
  211. &Ouml;ffnet das Ventil auf den angegebenen Wert (in Prozent, von 0 bis 100).
  212. </li>
  213. <li>set &lt;name&gt; pair<br>
  214. Verbindet das Ventil mit dem CUL.
  215. </li>
  216. <li>set &lt;name&gt; decalc<br>
  217. Startet einen Entkalkungslauf des angegebenen Ventils.
  218. </li>
  219. </ul>
  220. <br>
  221. <a name="FHT8Vget"></a>
  222. <b>Get </b>
  223. <ul>
  224. <li>get &lt;name&gt; valve<br>
  225. Liest die Ventil&ouml;ffnung aus dem FHT-Puffer des CUL und wandelt sie
  226. in Prozent (von 0 bis 100) um.
  227. </li>
  228. </ul>
  229. <br>
  230. <a name="FHT8Vattr"></a>
  231. <b>Attributes</b>
  232. <ul>
  233. <li><a href="#IODev">IODev</a></li>
  234. <li><a href="#dummy">dummy</a></li>
  235. <li><a href="#ignore">ignore</a></li>
  236. <li><a href="#eventMap">eventMap</a></li><br>
  237. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  238. </ul>
  239. <br>
  240. </ul>
  241. =end html_DE
  242. =cut