12_HProtocolTank.pm 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. # $Id: 12_HProtocolTank.pm 17508 2018-10-11 12:41:53Z eisler $
  2. ####################################################################################################
  3. #
  4. # 12_HProtocolTank.pm
  5. #
  6. # Copyright: Stephan Eisler
  7. # Email: fhem.dev@hausautomatisierung.co
  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. #
  24. ####################################################################################################
  25. package main;
  26. sub HProtocolTank_Initialize($) {
  27. my ($hash) = @_;
  28. $hash->{DefFn} = "HProtocolTank_Define";
  29. $hash->{ParseFn} = "HProtocolTank_Parse";
  30. $hash->{FingerprintFn} = "HProtocolTank_Fingerprint";
  31. $hash->{AttrFn} = "HProtocolGateway_Attr";
  32. $hash->{Match} = "^[a-zA-Z0-9_]+ [a-zA-Z0-9_]+ [+-]*[0-9]+([.][0-9]+)?";
  33. $hash->{AttrList} = "hID " .
  34. "mode:FillLevel,Volume,Ullage " .
  35. "type " .
  36. $readingFnAttributes;
  37. }
  38. sub HProtocolTank_Define($$) {
  39. my ($hash, $def) = @_;
  40. my @a = split("[ \t][ \t]*", $def);
  41. return "Wrong syntax: use define <name> HProtocolTank <gateway_name>" if(int(@a) != 3);
  42. my $name = $a[0];
  43. my $gateway = $a[2];
  44. if (!$hash->{IODev}) {
  45. AssignIoPort($hash, $gateway);
  46. }
  47. if (defined($hash->{IODev})) {
  48. Log3 $name, 3, "$name: I/O device is " . $hash->{IODev}->{NAME};
  49. } else {
  50. Log3 $name, 1, "$name: no I/O device";
  51. }
  52. if (defined($hash->{IODev})) {
  53. $iodev = $hash->{IODev}->{NAME};
  54. }
  55. $hash->{STATE} = "Initialized";
  56. $attr{$name}{room} = "HProtocol";
  57. # TODO This has to be updated when renaming the device.
  58. $modules{HProtocolTank}{defptr}{$name} = $hash;
  59. # TODO A Tank has to be unregistered when it's removed or renamed.
  60. HProtocolGateway_RegisterTank($hash);
  61. return undef;
  62. }
  63. sub HProtocolTank_Parse($$) {
  64. my ($iohash, $message) = @_;
  65. # $message = "<tankName> <reading> <value>"
  66. my @array = split("[ \t][ \t]*", $message);
  67. my $tankName = @array[0];
  68. my $reading = @array[1];
  69. my $value = @array[2];
  70. my $hash = $modules{HProtocolTank}{defptr}{$tankName};
  71. readingsSingleUpdate($hash, $reading, $value, 1);
  72. return $tankName;
  73. }
  74. sub HProtocolTank_Fingerprint($$) {
  75. # this subroutine is called before running Parse to check if
  76. # this message is a duplicate message. Refer to FHEM Wiki.
  77. }
  78. sub HProtocolTank_Attr (@) {
  79. my ($command, $name, $attr, $val) = @_;
  80. my $hash = $defs{$name};
  81. my $msg = '';
  82. if ($attr eq 'type') {
  83. $attr{$name}{type} = $val;
  84. } elsif ($attr eq 'mode') {
  85. $attr{$name}{mode} = $val;
  86. }
  87. }
  88. 1;
  89. =pod
  90. =item summary devices communicating via the HProtocolGateway
  91. =begin html
  92. <a name="HProtocolTank"></a>
  93. <h3>HProtocolTank</h3>
  94. <ul>
  95. The HProtocolTank is a fhem module defines a device connected to a HProtocolGateway.
  96. <br /><br /><br />
  97. <a name="HProtocolTank"></a>
  98. <b>Define</b>
  99. <ul>
  100. <code>define tank01 HProtocolTank HProtocolGateway<br />
  101. </code>
  102. <br />
  103. Defines an HProtocolTank connected to a HProtocolGateway.<br /><br />
  104. </ul><br />
  105. <a name="HProtocolTank"></a>
  106. <b>Readings</b>
  107. <ul>
  108. <li>ullage<br />
  109. 0..999999 Ullage in litres</li>
  110. <li>filllevel<br />
  111. 0..99999 Fill level in cm</li>
  112. <li>volume<br />
  113. 0..999999 Volume in litres</li>
  114. <li>volume_15C<br />
  115. 0..999999 Volume in litres at 15 °C</li>
  116. <li>temperature<br />
  117. -999 - +999 Temperature in °C</li>
  118. <li>waterlevel<br />
  119. 0..9999 Water level in mm</li>
  120. <li>probe_offset<br />
  121. -9999 - +9999 Probe offset in mm</li>
  122. <li>version<br />
  123. 00..999 Software version</li>
  124. <li>error<br />
  125. 0..9 00.. Probe error</li>
  126. </ul><br />
  127. <a name="HProtocolTank"></a>
  128. <b>Attributes</b>
  129. <ul>
  130. <li>hID<br />
  131. 01 - 32 Tank Number / Tank Address (99 for testing only)</li>
  132. <li>mode<br />
  133. FillLevel, Volume, Ullage</li>
  134. <li>type<br />
  135. Strapping Table csv file / tank01.csv</li>
  136. </ul><br />
  137. </ul><br />
  138. =end html
  139. =cut