36_WMBUS.pm 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. #
  2. # kaihs@FHEM_Forum (forum.fhem.de)
  3. #
  4. # $Id: 36_WMBUS.pm 16320 2018-03-03 20:25:22Z kaihs $
  5. #
  6. #
  7. package main;
  8. use strict;
  9. use warnings;
  10. use SetExtensions;
  11. use WMBus;
  12. sub WMBUS_Parse($$);
  13. sub WMBUS_SetReadings($$$);
  14. sub WMBUS_SetRSSI($$$);
  15. sub WMBUS_RSSIAsRaw($);
  16. sub WMBUS_Initialize($) {
  17. my ($hash) = @_;
  18. $hash->{Match} = "^b.*";
  19. #$hash->{SetFn} = "WMBUS_Set";
  20. #$hash->{GetFn} = "WMBUS_Get";
  21. $hash->{DefFn} = "WMBUS_Define";
  22. $hash->{UndefFn} = "WMBUS_Undef";
  23. #$hash->{FingerprintFn} = "WMBUS_Fingerprint";
  24. $hash->{ParseFn} = "WMBUS_Parse";
  25. $hash->{AttrFn} = "WMBUS_Attr";
  26. $hash->{AttrList} = "IODev".
  27. " AESkey".
  28. " ignore:0,1".
  29. " rawmsg_as_reading:0,1".
  30. " $readingFnAttributes";
  31. }
  32. sub
  33. WMBUS_HandleEncoding($$)
  34. {
  35. my ($mb, $msg) = @_;
  36. my $encoding = "CUL";
  37. my $rssi;
  38. ($msg, $rssi) = split(/::/,$msg);
  39. if (substr($msg,1,3) eq "AMB") {
  40. # Amber Wireless AMB8425-M encoding, does not include CRC16
  41. $encoding = "AMB";
  42. $mb->setCRCsize(0);
  43. # message length (first byte) contains 1 byte for rssi,
  44. # remove it
  45. my $msglen = sprintf("%1x", hex(substr($msg,4,1)) - 1);
  46. $msg = "b" . $msglen . substr($msg,5);
  47. } else {
  48. $msg .= WMBUS_RSSIAsRaw($rssi);
  49. }
  50. return ($msg, $rssi, $encoding);
  51. }
  52. sub
  53. WMBUS_Define($$)
  54. {
  55. my ($hash, $def) = @_;
  56. my @a = split("[ \t][ \t]*", $def);
  57. my $mb;
  58. my $rssi;
  59. if(@a != 6 && @a != 3) {
  60. my $msg = "wrong syntax: define <name> WMBUS [<ManufacturerID> <SerialNo> <Version> <Type> [<MessageEncoding>]]|b<HexMessage>";
  61. Log3 undef, 2, $msg;
  62. return $msg;
  63. }
  64. my $name = $a[0];
  65. if (@a == 3) {
  66. # unparsed message
  67. my $msg = $a[2];
  68. $mb = new WMBus;
  69. ($msg, $rssi, $hash->{MessageEncoding}) = WMBUS_HandleEncoding($mb, $msg);
  70. my $minSize = ($mb->getCRCsize() + WMBus::TL_BLOCK_SIZE) * 2;
  71. my $reMinSize = qr/b[a-zA-Z0-9]{${minSize},}/;
  72. return "a WMBus message must be a least $minSize bytes long, $msg" if $msg !~ m/${reMinSize}/;
  73. if ($mb->parseLinkLayer(pack('H*',substr($msg,1)))) {
  74. $hash->{Manufacturer} = $mb->{manufacturer};
  75. $hash->{IdentNumber} = $mb->{afield_id};
  76. $hash->{Version} = $mb->{afield_ver};
  77. $hash->{DeviceType} = $mb->{afield_type};
  78. if ($mb->{errormsg}) {
  79. $hash->{Error} = $mb->{errormsg};
  80. } else {
  81. delete $hash->{Error};
  82. }
  83. WMBUS_SetRSSI($hash, $mb, $rssi);
  84. } else {
  85. my $error = "failed to parse msg: $mb->{errormsg}";
  86. if ($mb->{errorcode} == WMBus::ERR_MSG_TOO_SHORT && $hash->{MessageEncoding} eq 'CUL') {
  87. $error .= ". Please make sure that TTY_BUFSIZE in culfw is at least two times the message length + 1";
  88. }
  89. return $error;
  90. }
  91. } else {
  92. my $encoding = "CUL";
  93. # manual specification
  94. if ($a[2] !~ m/[A-Z]{3}/) {
  95. return "$a[2] is not a valid WMBUS manufacturer id";
  96. }
  97. if ($a[3] !~ m/[0-9]{1,8}/) {
  98. return "$a[3] is not a valid WMBUS serial number";
  99. }
  100. if ($a[4] !~ m/[0-9]{1,2}/) {
  101. return "$a[4] is not a valid WMBUS version";
  102. }
  103. if ($a[5] !~ m/[0-9]{1,2}/) {
  104. return "$a[5] is not a valid WMBUS type";
  105. }
  106. if (defined($a[6])) {
  107. $encoding = $a[6];
  108. }
  109. if ($encoding ne "CUL" && $encoding ne "AMB") {
  110. return "$a[6] isn't a supported encoding, use either CUL or AMB";
  111. }
  112. $hash->{Manufacturer} = $a[2];
  113. $hash->{IdentNumber} = sprintf("%08d",$a[3]);
  114. $hash->{Version} = $a[4];
  115. $hash->{DeviceType} = $a[5];
  116. $hash->{MessageEncoding} = $encoding;
  117. }
  118. my $addr = join("_", $hash->{Manufacturer},$hash->{IdentNumber},$hash->{Version},$hash->{DeviceType}) ;
  119. return "WMBUS device $addr already used for $modules{WMBUS}{defptr}{$addr}->{NAME}." if( $modules{WMBUS}{defptr}{$addr}
  120. && $modules{WMBUS}{defptr}{$addr}->{NAME} ne $name );
  121. $hash->{addr} = $addr;
  122. $modules{WMBUS}{defptr}{$addr} = $hash;
  123. AssignIoPort($hash);
  124. if(defined($hash->{IODev}->{NAME})) {
  125. Log3 $name, 3, "$name: I/O device is " . $hash->{IODev}->{NAME};
  126. } else {
  127. Log3 $name, 1, "$name: no I/O device";
  128. }
  129. $hash->{DEF} = join(" ", $hash->{Manufacturer},$hash->{IdentNumber},$hash->{Version},$hash->{DeviceType});
  130. $hash->{DeviceMedium} = WMBus::->type2string($hash->{DeviceType});
  131. if (defined($mb)) {
  132. if ($mb->parseApplicationLayer()) {
  133. if ($mb->{cifield} == WMBus::CI_RESP_12) {
  134. $hash->{Meter_Id} = $mb->{meter_id};
  135. $hash->{Meter_Manufacturer} = $mb->{meter_manufacturer};
  136. $hash->{Meter_Version} = $mb->{meter_vers};
  137. $hash->{Meter_Dev} = $mb->{meter_devtypestring};
  138. $hash->{Access_No} = $mb->{access_no};
  139. $hash->{Status} = $mb->{status};
  140. }
  141. WMBUS_SetReadings($hash, $name, $mb);
  142. } else {
  143. $hash->{Error} = $mb->{errormsg};
  144. }
  145. }
  146. return undef;
  147. }
  148. #####################################
  149. sub
  150. WMBUS_Undef($$)
  151. {
  152. my ($hash, $arg) = @_;
  153. my $name = $hash->{NAME};
  154. my $addr = $hash->{addr};
  155. delete( $modules{WMBUS}{defptr}{$addr} );
  156. return undef;
  157. }
  158. #####################################
  159. sub
  160. WMBUS_Get($@)
  161. {
  162. my ($hash, $name, $cmd, @args) = @_;
  163. return "\"get $name\" needs at least one parameter" if(@_ < 3);
  164. my $list = "";
  165. return "Unknown argument $cmd, choose one of $list";
  166. }
  167. sub
  168. WMBUS_Fingerprint($$)
  169. {
  170. my ($name, $msg) = @_;
  171. return ( "", $msg );
  172. }
  173. sub
  174. WMBUS_Parse($$)
  175. {
  176. my ($hash, $rawMsg) = @_;
  177. my $name = $hash->{NAME};
  178. my $addr;
  179. my $rhash;
  180. my $rssi;
  181. my $msg;
  182. # $hash is the hash of the IODev!
  183. if( $rawMsg =~ m/^b/ ) {
  184. # WMBus message received
  185. Log3 $name, 5, "WMBUS raw msg " . $rawMsg;
  186. my $mb = new WMBus;
  187. ($msg, $rssi, $hash->{MessageEncoding}) = WMBUS_HandleEncoding($mb, $rawMsg);
  188. if ($mb->parseLinkLayer(pack('H*',substr($msg,1)))) {
  189. $addr = join("_", $mb->{manufacturer}, $mb->{afield_id}, $mb->{afield_ver}, $mb->{afield_type});
  190. $rhash = $modules{WMBUS}{defptr}{$addr};
  191. if( !$rhash ) {
  192. Log3 $name, 3, "WMBUS Unknown device $rawMsg, please define it";
  193. return "UNDEFINED WMBUS_$addr WMBUS $rawMsg";
  194. }
  195. my $rname = $rhash->{NAME};
  196. return "" if(IsIgnored($rname));
  197. WMBUS_SetRSSI($rhash, $mb, $rssi);
  198. my $aeskey;
  199. if ($aeskey = AttrVal($rname, 'AESkey', undef)) {
  200. $mb->{aeskey} = pack("H*",$aeskey);
  201. } else {
  202. $mb->{aeskey} = undef;
  203. }
  204. if ($mb->parseApplicationLayer()) {
  205. return WMBUS_SetReadings($rhash, $rname, $mb);
  206. } else {
  207. Log3 $rname, 2, "WMBUS $rname Error during ApplicationLayer parse:" . $mb->{errormsg};
  208. readingsSingleUpdate($rhash, "state", $mb->{errormsg}, 1);
  209. return $rname;
  210. }
  211. } else {
  212. # error
  213. Log3 $name, 2, "WMBUS Error during LinkLayer parse:" . $mb->{errormsg};
  214. if ($mb->{errorcode} == WMBus::ERR_MSG_TOO_SHORT && $hash->{MessageEncoding} eq 'CUL') {
  215. Log3 $name, 2, "Please make sure that TTY_BUFSIZE in culfw is at least two times the message length + 1";
  216. }
  217. return undef;
  218. }
  219. } else {
  220. DoTrigger($name, "UNKNOWNCODE $rawMsg");
  221. Log3 $name, 3, "$name: Unknown code $rawMsg, help me!";
  222. return undef;
  223. }
  224. }
  225. # if the culfw doesn't send the RSSI value (because it is an old version that doesn't implement this) but 00_CUL.pm already expects it
  226. # one byte is missing from the data which leads to CRC errors
  227. # To avoid this calculate the raw data byte from the RSSI and append it to the data.
  228. # If it is a valid RSSI it will be ignored by the WMBus parser (the data contains the length of the data itself
  229. # and only that much is parsed).
  230. sub WMBUS_RSSIAsRaw($) {
  231. my $rssi = shift;
  232. if (defined $rssi) {
  233. if ($rssi < -74) {
  234. $b = ($rssi+74)*2+256;
  235. } else {
  236. $b = ($rssi+74)*2;
  237. }
  238. return sprintf("%02X", $b);
  239. } else {
  240. return "";
  241. }
  242. }
  243. sub WMBUS_SetRSSI($$$) {
  244. my ($hash, $mb, $rssi) = @_;
  245. if (defined $mb->{remainingData} && length($mb->{remainingData}) >= 2) {
  246. # if there are trailing bytes after the WMBUS message it is the LQI and the RSSI
  247. readingsBeginUpdate($hash);
  248. my ($lqi, $rssi) = unpack("CC", $mb->{remainingData});
  249. $rssi = ($rssi>=128 ? (($rssi-256)/2-74) : ($rssi/2-74));
  250. readingsBulkUpdate($hash, "RSSI", $rssi);
  251. readingsBulkUpdate($hash, "LQI", unpack("C", $mb->{remainingData}));
  252. readingsEndUpdate($hash,1);
  253. }
  254. }
  255. sub WMBUS_SetReadings($$$)
  256. {
  257. my ($hash, $name, $mb) = @_;
  258. my @list;
  259. push(@list, $name);
  260. readingsBeginUpdate($hash);
  261. if ($mb->{decrypted}) {
  262. my $dataBlocks = $mb->{datablocks};
  263. my $dataBlock;
  264. for $dataBlock ( @$dataBlocks ) {
  265. readingsBulkUpdate($hash, "$dataBlock->{number}_storage_no", $dataBlock->{storageNo});
  266. readingsBulkUpdate($hash, "$dataBlock->{number}_type", $dataBlock->{type});
  267. readingsBulkUpdate($hash, "$dataBlock->{number}_value", $dataBlock->{value});
  268. readingsBulkUpdate($hash, "$dataBlock->{number}_unit", $dataBlock->{unit});
  269. readingsBulkUpdate($hash, "$dataBlock->{number}_value_type", $dataBlock->{functionFieldText});
  270. if (defined($dataBlock->{extension})) {
  271. readingsBulkUpdate($hash, "$dataBlock->{number}_extension", $dataBlock->{extension});
  272. }
  273. if ($dataBlock->{errormsg}) {
  274. readingsBulkUpdate($hash, "$dataBlock->{number}_errormsg", $dataBlock->{errormsg});
  275. }
  276. }
  277. readingsBulkUpdate($hash, "battery", $mb->{status} & 4 ? "low" : "ok");
  278. WMBUS_SetDeviceSpecificReadings($hash, $name, $mb);
  279. }
  280. readingsBulkUpdate($hash, "is_encrypted", $mb->{isEncrypted});
  281. readingsBulkUpdate($hash, "decryption_ok", $mb->{decrypted});
  282. if ($mb->{decrypted}) {
  283. readingsBulkUpdate($hash, "state", $mb->{statusstring});
  284. } else {
  285. readingsBulkUpdate($hash, "state", 'decryption failed');
  286. }
  287. if (AttrVal($name, "rawmsg_as_reading", 0)) {
  288. readingsBulkUpdate($hash, "rawmsg", unpack("H*",$mb->{msg}));
  289. }
  290. readingsEndUpdate($hash,1);
  291. return @list;
  292. }
  293. sub WMBUS_SetDeviceSpecificReadings($$$)
  294. {
  295. my ($hash, $name, $mb) = @_;
  296. if ($mb->{manufacturer} eq 'FFD') {
  297. # Fast Forward AG
  298. if ($mb->{afield_ver} == 1) {
  299. #EnergyCam
  300. if ($mb->{afield_type} == 2) {
  301. # electricity
  302. readingsBulkUpdate($hash, "energy", ReadingsVal($name, "1_value", 0) / 1000);
  303. readingsBulkUpdate($hash, "unit", "kWh");
  304. } elsif ($mb->{afield_type} == 3 || $mb->{afield_type} == 7) {
  305. # gas/water
  306. readingsBulkUpdate($hash, "volume", ReadingsVal($name, "1_value", 0));
  307. readingsBulkUpdate($hash, "unit", "m³");
  308. }
  309. }
  310. } elsif ($mb->{afield_type} == 3 || $mb->{afield_type} == 7) {
  311. # general gas/water meter
  312. my $dataBlock;
  313. my $dataBlocks = $mb->{datablocks};
  314. for $dataBlock ( @$dataBlocks ) {
  315. # search for VIF_VOLUME
  316. if ($dataBlock->{type} eq 'VIF_VOLUME' && $dataBlock->{functionFieldText} eq "Instantaneous value") {
  317. readingsBulkUpdate($hash, "volume", $dataBlock->{value});
  318. readingsBulkUpdate($hash, "unit", $dataBlock->{unit});
  319. }
  320. }
  321. }
  322. }
  323. #####################################
  324. sub
  325. WMBUS_Set($@)
  326. {
  327. my ($hash, @a) = @_;
  328. my $name = shift @a;
  329. my $cmd = shift @a;
  330. my $arg = join(" ", @a);
  331. my $list = "resetAccumulatedPower";
  332. return $list if( $cmd eq '?' || $cmd eq '');
  333. if($cmd eq "resetAccumulatedPower") {
  334. CommandAttr(undef, "$name accumulatedPowerOffset " . $hash->{READINGS}{accumulatedPowerMeasured}{VAL});
  335. }
  336. else {
  337. return "Unknown argument $cmd, choose one of ".$list;
  338. }
  339. return undef;
  340. }
  341. sub
  342. WMBUS_Attr(@)
  343. {
  344. my ($cmd, $name, $attrName, $attrVal) = @_;
  345. my $hash = $defs{$name};
  346. my $msg = '';
  347. if ($attrName eq 'AESkey') {
  348. if ($attrVal =~ /^[0-9A-Fa-f]{32}$/) {
  349. $hash->{wmbus}->{aeskey} = $attrVal;
  350. } else {
  351. $msg = "AESkey must be a 32 digit hexadecimal value";
  352. }
  353. }
  354. return ($msg) ? $msg : undef;
  355. }
  356. 1;
  357. =pod
  358. =item device
  359. =item summary Reception of Wireless M-Bus messages from e.g. electicity meters
  360. =item summary_DE Empfang von Wireless M-Bus Nachrichten z. B. von Stromzählern
  361. =begin html
  362. <a name="WMBUS"></a>
  363. <h3>WMBUS - Wireless M-Bus</h3>
  364. <ul>
  365. This module supports Wireless M-Bus meters for e.g. water, heat, gas or electricity.
  366. Wireless M-Bus is a standard protocol supported by various manufacturers.
  367. It uses the 868 MHz band for radio transmissions.
  368. Therefore you need a device which can receive Wireless M-Bus messages, e.g. a <a href="#CUL">CUL</a> with culfw >= 1.59 or an AMBER Wireless AMB8465M.
  369. <br>
  370. WMBus uses two different radio protocols, T-Mode and S-Mode. The receiver must be configured to use the same protocol as the sender.
  371. In case of a CUL this can be done by setting <a href="#rfmode">rfmode</a> to WMBus_T or WMBus_S respectively.
  372. <br>
  373. WMBus devices send data periodically depending on their configuration. It can take days between individual messages or they might be sent
  374. every minute.
  375. <br>
  376. WMBus messages can be optionally encrypted. In that case the matching AESkey must be specified with attr AESkey. Otherwise the decryption
  377. will fail and no relevant data will be available.
  378. <br><br>
  379. <b>Prerequisites</b><br>
  380. This module requires the perl modules Crypt::CBC, Digest::CRC and Crypt::OpenSSL::AES (AES only if encrypted messages should be processed).<br>
  381. On a debian based system these can be installed with<br>
  382. <code>
  383. sudo apt-get install libcrypt-cbc-perl libdigest-crc-perl libssl-dev<br>
  384. sudo cpan -i Crypt::OpenSSL::AES
  385. </code>
  386. <br><br>
  387. <a name="WMBUSdefine"></a>
  388. <b>Define</b>
  389. <ul>
  390. <code>define &lt;name&gt; WMBUS [&lt;manufacturer id&gt; &lt;identification number&gt; &lt;version&gt; &lt;type&gt; [&lt;MessageEncoding&gt;]]|&lt;bHexCode&gt;</code> <br>
  391. <br>
  392. Normally a WMBus device isn't defined manually but automatically through the <a href="#autocreate">autocreate</a> mechanism upon the first reception of a message.
  393. <br>
  394. For a manual definition there are two ways.
  395. <ul>
  396. <li>
  397. By specifying a raw WMBus message as received by a CUL. Such a message starts with a lower case 'b' and contains at least 24 hexadecimal digits.
  398. The WMBUS module extracts all relevant information from such a message.
  399. </li>
  400. <li>
  401. Explictly specify the information that uniquely identifies a WMBus device. <br>
  402. The manufacturer code, which is is a three letter shortcut of the manufacturer name. See
  403. <a href="http://dlms.com/organization/flagmanufacturesids/index.html">dlms.com</a> for a list of registered ids.<br>
  404. The identification number is the serial no of the meter.<br>
  405. version is the version code of the meter<br>
  406. type is the type of the meter, e.g. water or electricity encoded as a number.<br>
  407. MessageEncoding is either CUL or AMB, depending on which kind of IODev is used.
  408. </li>
  409. <br>
  410. </ul>
  411. </ul>
  412. <br>
  413. <a name="WMBUSset"></a>
  414. <b>Set</b> <ul>N/A</ul><br>
  415. <a name="WMBUSget"></a>
  416. <b>Get</b> <ul>N/A</ul><br>
  417. <a name="WMBUSattr"></a>
  418. <b>Attributes</b>
  419. <ul>
  420. <li><a href="#IODev">IODev</a><br>
  421. Set the IO or physical device which should be used for receiving signals
  422. for this "logical" device. An example for the physical device is a CUL.
  423. </li><br>
  424. <li>AESKey<br>
  425. A 16 byte AES-Key in hexadecimal digits. Used to decrypt messages from meters which have encryption enabled.
  426. </li><br>
  427. <li>
  428. <a href="#ignore">ignore</a>
  429. </li><br>
  430. <li>rawmsg_as_reading<br>
  431. If set to 1, received raw messages will be stored in the reading rawmsg. This can be used to log raw messages to help with debugging.
  432. </li>
  433. </ul>
  434. <br>
  435. <a name="WMBUSreadings"></a>
  436. <b>Readings</b><br>
  437. <ul>
  438. Meters can send a lot of different information depending on their type. An electricity meter will send other data than a water meter.
  439. The information also depends on the manufacturer of the meter. See the WMBus specification on <a href="http://www.oms-group.org">oms-group.org</a> for details.
  440. <br><br>
  441. The readings are generated in blocks starting with block 1. A meter can send several data blocks.
  442. Each block has at least a type, a value and a unit, e.g. for an electricity meter it might look like<br>
  443. <ul>
  444. <code>1_type VIF_ENERGY_WATT</code><br>
  445. <code>1_unit Wh</code><br>
  446. <code>1_value 2948787</code><br>
  447. </ul>
  448. <br>
  449. There is also a fixed set of readings.
  450. <ul>
  451. <li><code>is_encrypted</code> is 1 if the received message is encrypted.</li>
  452. <li><code>decryption_ok</code> is 1 if a message has either been successfully decrypted or if it is unencrypted.</li>
  453. <li><code>state</code> contains the state of the meter and may contain error message like battery low. Normally it contains 'no error'.</li>
  454. <li><code>battery</code> contains ok or low.</li>
  455. </ul>
  456. For some well known devices specific readings like the energy consumption in kWh created.
  457. </ul>
  458. </ul>
  459. =end html
  460. =begin html_DE
  461. <a name="WMBUS"></a>
  462. <h3>WMBUS - Wireless M-Bus</h3>
  463. <ul>
  464. Dieses Modul unterst&uuml;tzt Z&auml;hler mit Wireless M-Bus, z. B. f&uuml;r Wasser, Gas oder Elektrizit&auml;t.
  465. Wireless M-Bus ist ein standardisiertes Protokoll das von unterschiedlichen Herstellern unterst&uuml;tzt wird.
  466. Es verwendet das 868 MHz Band f&uuml;r Radio&uuml;bertragungen.
  467. Daher wird ein Ger&auml;t ben&ouml;tigt das die Wireless M-Bus Nachrichten empfangen kann, z. B. ein <a href="#CUL">CUL</a> mit culfw >= 1.59 oder ein AMBER Wireless AMB8465-M.
  468. <br>
  469. WMBus verwendet zwei unterschiedliche Radioprotokolle, T-Mode und S-Mode. Der Empf&auml;nger muss daher so konfiguriert werden, dass er das selbe Protokoll
  470. verwendet wie der Sender. Im Falle eines CUL kann das erreicht werden, in dem das Attribut <a href="#rfmode">rfmode</a> auf WMBus_T bzw. WMBus_S gesetzt wird.
  471. <br>
  472. WMBus Ger&auml;te senden Daten periodisch abh&auml;ngig von ihrer Konfiguration. Es k&ouml;nnen u. U. Tage zwischen einzelnen Nachrichten vergehen oder sie k&ouml;nnen im
  473. Minutentakt gesendet werden.
  474. <br>
  475. WMBus Nachrichten k&ouml;nnen optional verschl&uuml;sselt werden. Bei verschl&uuml;sselten Nachrichten muss der passende Schl&uuml;ssel mit dem Attribut AESkey angegeben werden.
  476. Andernfalls wird die Entschl&uuml;sselung fehlschlagen und es k&ouml;nnen keine relevanten Daten ausgelesen werden.
  477. <br><br>
  478. <b>Voraussetzungen</b><br>
  479. Dieses Modul ben&ouml;tigt die perl Module Crypt::CBC, Digest::CRC and Crypt::OpenSSL::AES (AES wird nur ben&ouml;tigt wenn verschl&uuml;sselte Nachrichten verarbeitet werden sollen).<br>
  480. Bei einem Debian basierten System k&ouml;nnen diese so installiert werden<br>
  481. <code>
  482. sudo apt-get install libcrypt-cbc-perl libdigest-crc-perl libssl-dev<br>
  483. sudo cpan -i Crypt::OpenSSL::AES
  484. </code>
  485. <br><br>
  486. <a name="WMBUSdefine"></a>
  487. <b>Define</b>
  488. <ul>
  489. <code>define &lt;name&gt; WMBUS [&lt;manufacturer id&gt; &lt;identification number&gt; &lt;version&gt; &lt;type&gt; [&lt;MessageEncoding&gt;]]|&lt;bHexCode&gt;</code> <br>
  490. <br>
  491. Normalerweise wird ein WMBus Device nicht manuell angelegt. Dies geschieht automatisch bem Empfang der ersten Nachrichten eines Ger&auml;tes &uuml;ber den
  492. fhem <a href="#autocreate">autocreate</a> Mechanismus.
  493. <br>
  494. F&uuml;r eine manuelle Definition gibt es zwei Wege.
  495. <ul>
  496. <li>
  497. Durch Verwendung einer WMBus Rohnachricht wie sie vom IODev empfangen wurde. So eine Nachricht beginnt mit einem kleinen 'b' und enth&auml;lt mindestens
  498. 24 hexadezimale Zeichen.
  499. Das WMBUS Modul extrahiert daraus alle ben&ouml;tigten Informationen.
  500. </li>
  501. <li>
  502. Durch explizite Angabe der Informationen die ein WMBus Ger&auml;t eindeutig identfizieren.<br>
  503. Der Hersteller Code, besteht aus drei Buchstaben als Abk&uuml;rzung des Herstellernamens. Eine Liste der Abk&uuml;rzungen findet sich unter
  504. <a href="http://dlms.com/organization/flagmanufacturesids/index.html">dlms.com</a><br>
  505. Die Idenitfikationsnummer ist die Seriennummer des Z&auml;hlers.<br>
  506. Version ist ein Versionscode des Z&auml;hlers.<br>
  507. Typ ist die Art des Z&auml;hlers, z. B. Wasser oder Elektrizit&auml;t, kodiert als Zahl.<br>
  508. MessageEncoding ist entweder CUL oder AMB, je nachdem welche Art von IODev verwendet wird
  509. </li>
  510. <br>
  511. </ul>
  512. </ul>
  513. <br>
  514. <a name="WMBUSset"></a>
  515. <b>Set</b> <ul>N/A</ul><br>
  516. <a name="WMBUSget"></a>
  517. <b>Get</b> <ul>N/A</ul><br>
  518. <a name="WMBUSattr"></a>
  519. <b>Attributes</b>
  520. <ul>
  521. <li><a href="#IODev">IODev</a><br>
  522. Setzt den IO oder physisches Ger&auml;t welches f&uuml;r den Empfang der Signale f&uuml;r dieses 'logische' Ger&auml;t verwendet werden soll.
  523. Ein Beispiel f&uuml;r ein solches Ger&auml;t ist ein CUL.
  524. </li><br>
  525. <li>AESKey<br>
  526. Ein 16 Bytes langer AES-Schl&uuml;ssel in hexadezimaler Schreibweise. Wird verwendet um Nachrichten von Z&auml;hlern zu entschl&uuml;sseln bei denen
  527. die Verschl&uuml;sselung aktiviert ist.
  528. </li><br>
  529. <li>
  530. <a href="#ignore">ignore</a>
  531. </li><br>
  532. <li>rawmsg_as_reading<br>
  533. Wenn auf 1 gesetzt so werden empfangene Nachrichten im Reading rawmsg gespeichert. Das kann verwendet werden um Rohnachrichten zu loggen und beim Debugging zu helfen.
  534. </li>
  535. </ul>
  536. <br>
  537. <a name="WMBUSreadings"></a>
  538. <b>Readings</b><br>
  539. <ul>
  540. Z&auml;hler k&ouml;nnen sehr viele unterschiedliche Informationen senden, abh&auml;ngig von ihrem Typ. Ein Elektrizit&auml;tsz&auml;hler wird andere Daten senden als ein
  541. Wasserz&auml;hler. Die Information h&auml;ngt auch vom Hersteller des Z&auml;hlers ab. F&uuml;r weitere Informationen siehe die WMBus Spezifikation unter
  542. <a href="http://www.oms-group.org">oms-group.org</a>.
  543. <br><br>
  544. Die Readings werden als Block dargestellt, beginnend mit Block 1. Ein Z&auml;hler kann mehrere Bl&ouml;cke senden.
  545. Jeder Block enth&auml;lt zumindest einen Typ, einen Wert und eine Einheit. F&uuml;r einen Elektrizit&auml;tsz&auml;hler k&ouml;nnte das z. B. so aussehen<br>
  546. <ul>
  547. <code>1_type VIF_ENERGY_WATT</code><br>
  548. <code>1_unit Wh</code><br>
  549. <code>1_value 2948787</code><br>
  550. </ul>
  551. <br>
  552. Es gibt auch eine Anzahl von festen Readings.
  553. <ul>
  554. <li><code>is_encrypted</code> ist 1 wenn die empfangene Nachricht verschl&uuml;sselt ist.</li>
  555. <li><code>decryption_ok</code> ist 1 wenn die Nachricht entweder erfolgreich entschl&uuml;sselt wurde oder gar nicht verschl&uuml;sselt war.</li>
  556. <li><code>state</code> enth&auml;lt den Status des Z&auml;hlers und kann Fehlermeldungen wie 'battery low' enthalten. Normalerweise ist der Wert 'no error'.</li>
  557. <li><code>battery</code> enth&auml;lt ok oder low.</li>
  558. </ul>
  559. Für einige bekannte Gerätetypen werden zusätzliche Readings wie der Energieverbrauch in kWh erzeugt.
  560. </ul>
  561. </ul>
  562. =end html_DE
  563. =cut