14_CUL_TX.pm 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. ##############################################
  2. # $Id: 14_CUL_TX.pm 14784 2017-07-25 15:06:43Z rudolfkoenig $
  3. package main;
  4. # From peterp
  5. # Lacrosse TX3-TH thermo/hygro sensor
  6. use strict;
  7. use warnings;
  8. sub
  9. CUL_TX_Initialize($)
  10. {
  11. my ($hash) = @_;
  12. $hash->{Match} = "^TX.........."; # Need TX to avoid FHTTK
  13. $hash->{DefFn} = "CUL_TX_Define";
  14. $hash->{UndefFn} = "CUL_TX_Undef";
  15. $hash->{ParseFn} = "CUL_TX_Parse";
  16. $hash->{AttrList} = "IODev do_not_notify:1,0 ignore:0,1 showtime:1,0 " .
  17. $readingFnAttributes;
  18. $hash->{AutoCreate}=
  19. { "CUL_TX.*" => { GPLOT => "temp4hum4:Temp/Hum,", FILTER => "%NAME" } };
  20. }
  21. #############################
  22. sub
  23. CUL_TX_Define($$)
  24. {
  25. my ($hash, $def) = @_;
  26. my @a = split("[ \t][ \t]*", $def);
  27. return "wrong syntax: define <name> CUL_TX <code> [corr] [minsecs]"
  28. if(int(@a) < 3 || int(@a) > 5);
  29. $hash->{CODE} = $a[2];
  30. $hash->{corr} = ((int(@a) > 3) ? $a[3] : 0);
  31. $hash->{minsecs} = ((int(@a) > 4) ? $a[4] : 0);
  32. $hash->{lastT} = 0;
  33. $hash->{lastH} = 0;
  34. $modules{CUL_TX}{defptr}{$a[2]} = $hash;
  35. $hash->{STATE} = "Defined";
  36. return undef;
  37. }
  38. #####################################
  39. sub
  40. CUL_TX_Undef($$)
  41. {
  42. my ($hash, $name) = @_;
  43. delete($modules{CUL_TX}{defptr}{$hash->{CODE}})
  44. if(defined($hash->{CODE}) &&
  45. defined($modules{CUL_TX}{defptr}{$hash->{CODE}}));
  46. return undef;
  47. }
  48. ###################################
  49. sub
  50. CUL_TX_Parse($$)
  51. {
  52. my ($hash, $msg) = @_;
  53. $msg = substr($msg, 1);
  54. # Msg format: TXTHHXYZXY, see http://www.f6fbb.org/domo/sensors/tx3_th.php
  55. my @a = split("", $msg);
  56. my $id2 = hex($a[4]) & 1; #meaning unknown
  57. my $id3 = (hex($a[3])<<3) + (hex($a[4])>>1);
  58. if($a[5] ne $a[8] || $a[6] ne $a[9]) {
  59. Log3 $hash, 4, "CUL_TX $id3 ($msg) data error";
  60. return "";
  61. }
  62. my $def = $modules{CUL_TX}{defptr}{$id3};
  63. if(!$def) {
  64. Log3 $hash, 2, "CUL_TX Unknown device $id3, please define it";
  65. return "UNDEFINED CUL_TX_$id3 CUL_TX $id3" if(!$def);
  66. }
  67. my $now = time();
  68. my $name = $def->{NAME};
  69. return "" if(IsIgnored($name));
  70. Log3 $name, 4, "CUL_TX $name $id3 ($msg)";
  71. my ($msgtype, $val);
  72. my $valraw = (hex($a[5]).$a[6].".".$a[7]);
  73. my $type = $a[2];
  74. if($type eq "0") {
  75. if($now - $def->{lastT} < $def->{minsecs} ) {
  76. return "";
  77. }
  78. $def->{lastT} = $now;
  79. $msgtype = "temperature";
  80. $val = sprintf("%2.1f", ($valraw - 50 + $def->{corr}) );
  81. Log3 $name, 4, "CUL_TX $msgtype $name $id3 T: $val UnknownFlag: $id2";
  82. } elsif ($type eq "E") {
  83. if($now - $def->{lastH} < $def->{minsecs} ) {
  84. return "";
  85. }
  86. $def->{lastH} = $now;
  87. $msgtype = "humidity";
  88. $val = $valraw;
  89. Log3 $name, 4, "CUL_TX $msgtype $name $id3 H: $val UnknownFlag: $id2";
  90. } else {
  91. Log3 $name, 2, "CUL_TX $type $name $id3 ($msg) unknown type";
  92. return "";
  93. }
  94. # I suspect that humidity 0F.F is battery warning. Can someone verify?
  95. if($val !~ m/^[0-9.-]*$/) {
  96. Log3 $name, 5, "CUL_TX $type $name bogus value $val ($msg)";
  97. return "";
  98. }
  99. my $state="";
  100. my $t = ReadingsVal($name, "temperature", undef);
  101. my $h = ReadingsVal($name, "humidity", undef);
  102. $t = $val if($msgtype eq "temperature");
  103. $h = $val if($msgtype eq "humidity");
  104. if(defined($t) && defined($h)) {
  105. $state="T: $t H: $h";
  106. } elsif(defined($t)) {
  107. $state="T: $t";
  108. } elsif(defined($h)) {
  109. $state="H: $h";
  110. }
  111. readingsBeginUpdate($def);
  112. readingsBulkUpdate($def, "state", $state);
  113. readingsBulkUpdate($def, $msgtype, $val);
  114. readingsEndUpdate($def, 1);
  115. return $name;
  116. }
  117. 1;
  118. =pod
  119. =item summary Some Lacrosse sensors (TX-3TH, etc)
  120. =item summary_DE Einige Lacrosse Sensoren (TX-3TH, usw.)
  121. =begin html
  122. <a name="CUL_TX"></a>
  123. <h3>CUL_TX</h3>
  124. <ul>
  125. The CUL_TX module interprets TX2/TX3 type of messages received by the CUL,
  126. see also http://www.f6fbb.org/domo/sensors/tx3_th.php.
  127. This protocol is used by the La Crosse TX3-TH thermo/hygro sensor and other
  128. wireless themperature sensors. Please report the manufacturer/model of other
  129. working devices. <br><br>
  130. <a name="CUL_TXdefine"></a>
  131. <b>Define</b>
  132. <ul>
  133. <code>define &lt;name&gt; CUL_TX &lt;code&gt; [corr] [minsecs]</code> <br>
  134. <br>
  135. &lt;code&gt; is the code of the autogenerated address of the TX device (0
  136. to 127)<br>
  137. corr is a correction factor, which will be added to the value received from
  138. the device.<br>
  139. minsecs are the minimum seconds between two log entries or notifications
  140. from this device. <br>E.g. if set to 300, logs of the same type will occure
  141. with a minimum rate of one per 5 minutes even if the device sends a message
  142. every minute. (Reduces the log file size and reduces the time to display
  143. the plots)
  144. </ul>
  145. <br>
  146. <a name="CUL_TXset"></a>
  147. <b>Set</b> <ul>N/A</ul><br>
  148. <a name="CUL_TXget"></a>
  149. <b>Get</b> <ul>N/A</ul><br>
  150. <a name="CUL_TXattr"></a>
  151. <b>Attributes</b>
  152. <ul>
  153. <li><a href="#ignore">ignore</a></li><br>
  154. <li><a href="#do_not_notify">do_not_notify</a></li><br>
  155. <li><a href="#showtime">showtime</a></li><br>
  156. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  157. </ul>
  158. <br>
  159. <a name="CUL_TXevents"></a>
  160. <b>Generated events:</b>
  161. <ul>
  162. <li>temperature: $temp</li>
  163. <li>humidity: $hum</li>
  164. </ul>
  165. <br>
  166. </ul>
  167. =end html
  168. =cut