46_TRX_WEATHER.pm 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896
  1. # $Id: 46_TRX_WEATHER.pm 11450 2016-05-15 19:03:23Z wherzig $
  2. ##############################################################################
  3. #
  4. # 46_TRX_WEATHER.pm
  5. # FHEM module to decode weather sensor messages for RFXtrx
  6. #
  7. # The following devices are implemented to be received:
  8. #
  9. # temperature sensors (TEMP):
  10. # * "THR128" is THR128/138, THC138
  11. # * "THGR132N" is THC238/268,THN132,THWR288,THRN122,THN122,AW129/131
  12. # * "THWR800" is THWR800
  13. # * "RTHN318" is RTHN318
  14. # * "TX3_T" is LaCrosse TX3, TX4, TX17
  15. # * "TS15C" is TS15C
  16. # * "VIKING_02811" is Viking 02811
  17. # * "WS2300" is La Crosse WS2300
  18. # * "RUBICSON" is RUBiCSON
  19. # * "TFA_303133" is TFA 30.3133
  20. # * "WT0122" is WT0122 pool sensor
  21. #
  22. # humidity sensors (HYDRO):
  23. # * "TX3" is LaCrosse TX3
  24. # * "WS2300" is LaCrosse WS2300
  25. # * "S80" is Inovalley S80 plant humidity sensor
  26. #
  27. # temperature/humidity sensors (TEMPHYDRO):
  28. # * "THGR228N" is THGN122/123, THGN132, THGR122/228/238/268
  29. # * "THGR810" is THGR810
  30. # * "RTGR328" is RTGR328
  31. # * "THGR328" is THGR328
  32. # * "WTGR800_T" is WTGR800
  33. # * "THGR918" is THGR918, THGRN228, THGN500
  34. # * "TFATS34C" is TFA TS34C, Cresta
  35. # * "WT450H" is WT260,WT260H,WT440H,WT450,WT450H
  36. # * "VIKING_02038" is Viking 02035,02038 (02035 has no humidity)
  37. # * "RUBICSON" is Rubicson
  38. # * "EW109" is EW109
  39. # * "XT300" is Imagintronix/Opus XT300 Soil sensor
  40. # * "WS1700" is Alecto WS1700 and compatibles
  41. # * "WS3500" is Alecto WS3500, WS4500, Auriol H13726, Hama EWS1500, Meteoscan W155/W160, Ventus WS155
  42. #
  43. # temperature/humidity/pressure sensors (TEMPHYDROBARO):
  44. # * "BTHR918" is BTHR918
  45. # * "BTHR918N" is BTHR918N, BTHR968
  46. #
  47. # rain gauge sensors (RAIN):
  48. # * "RGR918" is RGR126/682/918
  49. # * "PCR800" is PCR800
  50. # * "TFA_RAIN" is TFA
  51. # * "RG700" is UPM RG700
  52. # * "WS2300_RAIN" is WS2300
  53. # * "TX5_RAIN" is La Crosse TX5
  54. # * "WS4500_RAIN" is Alecto WS4500, Auriol H13726, Hama EWS1500, Meteoscan W155/W160,
  55. #
  56. # wind sensors (WIND):
  57. # * "WTGR800_A" is WTGR800
  58. # * "WGR800_A" is WGR800
  59. # * "WGR918" is STR918, WGR918
  60. # * "TFA_WIND" is TFA
  61. # * "WDS500" is UPM WDS500u
  62. # * "WS2300_WIND" is WS2300
  63. # * "WS4500_WIND" is Alecto WS4500, Auriol H13726, Hama EWS1500, Meteoscan W155/W160, Ventus WS155
  64. #
  65. # UV Sensors:
  66. # * "UVN128" is Oregon UVN128, UV138
  67. # * "UVN800" is Oregon UVN800
  68. # * "TFA_UV" is TFA_UV-Sensor
  69. #
  70. # Date/Time Sensors:
  71. # * "RTGR328_DATE" is RTGR328N
  72. #
  73. # Energy Sensors:
  74. # * "CM160" is OWL CM119, CM160
  75. # * "CM180" is OWL CM180
  76. # * "REVOLT" is Revolt
  77. #
  78. # Weighing scales (WEIGHT):
  79. # * "BWR101" is Oregon Scientific BWR101
  80. # * "GR101" is Oregon Scientific GR101
  81. #
  82. # BBQ-Sensors (two temperature values):
  83. # * "ET732" is Maverick ET-732
  84. #
  85. # thermostats (THERMOSTAT):
  86. # * "TH10" is XDOM TH10
  87. # * "TLX7506" is Digimax TLX7506
  88. #
  89. # Copyright (C) 2012-2016 Willi Herzig
  90. #
  91. # This script is distributed in the hope that it will be useful,
  92. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  93. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  94. #
  95. # Due to RFXCOM SDK requirements this code may only be used with a RFXCOM device.
  96. #
  97. # Some code was derived and modified from xpl-perl
  98. # from the following two files:
  99. # xpl-perl/lib/xPL/Utils.pm:
  100. # xpl-perl/lib/xPL/RF/Oregon.pm:
  101. #
  102. #SEE ALSO
  103. # Project website: http://www.xpl-perl.org.uk/
  104. # AUTHOR: Mark Hindess, soft-xpl-perl@temporalanomaly.com
  105. #
  106. # Copyright (C) 2007, 2009 by Mark Hindess
  107. #
  108. # This library is free software; you can redistribute it and/or modify
  109. # it under the same terms as Perl itself, either Perl version 5.8.7 or,
  110. # at your option, any later version of Perl 5 you may have available.
  111. ##################################
  112. #
  113. # values for "set global verbose"
  114. # 4: log unknown prologtocols
  115. # 5: log decoding hexlines for debugging
  116. #
  117. package main;
  118. use strict;
  119. use warnings;
  120. # Hex-Debugging into READING hexline? YES = 1, NO = 0
  121. my $TRX_HEX_debug = 0;
  122. # Max temperatute für Maverick BBQ
  123. my $TRX_MAX_TEMP_BBQ = 1000;
  124. my $time_old = 0;
  125. my $trx_rssi;
  126. sub
  127. TRX_WEATHER_Initialize($)
  128. {
  129. my ($hash) = @_;
  130. $hash->{Match} = "^..(40|4e|50|51|52|54|55|56|57|58|5a|5c|5d).*";
  131. $hash->{DefFn} = "TRX_WEATHER_Define";
  132. $hash->{UndefFn} = "TRX_WEATHER_Undef";
  133. $hash->{ParseFn} = "TRX_WEATHER_Parse";
  134. $hash->{AttrList} = "IODev ignore:1,0 do_not_notify:1,0 ".
  135. $readingFnAttributes;
  136. }
  137. #####################################
  138. sub
  139. TRX_WEATHER_Define($$)
  140. {
  141. my ($hash, $def) = @_;
  142. my @a = split("[ \t][ \t]*", $def);
  143. #my $a = int(@a);
  144. #print "a0 = $a[0]";
  145. return "wrong syntax: define <name> TRX_WEATHER code" if (int(@a) < 3);
  146. my $name = $a[0];
  147. my $code = $a[2];
  148. if (($code =~ /^CM160/) || ($code =~ /^CM180/) || ($code =~ /^REVOLT/)) {
  149. return "wrong syntax: define <name> TRX_WEATHER code [scale_current scale_total add_total]" if (int(@a) != 3 && int(@a) != 6);
  150. $hash->{scale_current} = ((int(@a) == 6) ? $a[3] : 1);
  151. $hash->{scale_total} = ((int(@a) == 6) ? $a[4] : 1.0);
  152. $hash->{add_total} = ((int(@a) == 6) ? $a[5] : 0.0);
  153. } else {
  154. return "wrong syntax: define <name> TRX_WEATHER code" if(int(@a) > 3);
  155. }
  156. $hash->{CODE} = $code;
  157. $modules{TRX_WEATHER}{defptr}{$code} = $hash;
  158. AssignIoPort($hash);
  159. return undef;
  160. }
  161. #####################################
  162. sub
  163. TRX_WEATHER_Undef($$)
  164. {
  165. my ($hash, $name) = @_;
  166. delete($modules{TRX_WEATHER}{defptr}{$name});
  167. return undef;
  168. }
  169. # --------------------------------------------
  170. # sensor types
  171. my %types =
  172. (
  173. # THERMOSTAT
  174. 0x4009 => { part => 'THERMOSTAT', method => \&TRX_WEATHER_common_therm, },
  175. # BBQ
  176. 0x4e0a => { part => 'BBQ', method => \&TRX_WEATHER_common_bbq, },
  177. # TEMP
  178. 0x5008 => { part => 'TEMP', method => \&TRX_WEATHER_common_temp, },
  179. # HYDRO
  180. 0x5108 => { part => 'HYDRO', method => \&TRX_WEATHER_common_hydro, },
  181. # TEMP HYDRO
  182. 0x520a => { part => 'TEMPHYDRO', method => \&TRX_WEATHER_common_temphydro, },
  183. # TEMP HYDRO BARO
  184. 0x540d => { part => 'TEMPHYDROBARO', method => \&TRX_WEATHER_common_temphydrobaro, },
  185. # RAIN
  186. 0x550b => { part => 'RAIN', method => \&TRX_WEATHER_common_rain, },
  187. # WIND
  188. 0x5610 => { part => 'WIND', method => \&TRX_WEATHER_common_anemometer, },
  189. # UV
  190. 0x5709 => { part => 'UV', method => \&TRX_WEATHER_common_uv, },
  191. # Date/Time sensors
  192. 0x580D => { part => 'DATE', method => \&TRX_WEATHER_common_datetime, },
  193. # Energy usage sensors
  194. 0x5A11 => { part => 'ENERGY', method => \&TRX_WEATHER_common_energy, },
  195. 0x5B13 => { part => 'ENERGY2', method => \&TRX_WEATHER_common_energy2, },
  196. 0x5c0f => { part => 'ENERGY3', method => \&TRX_WEATHER_common_energy3, },
  197. # WEIGHT
  198. 0x5D08 => { part => 'WEIGHT', method => \&TRX_WEATHER_common_weight, },
  199. );
  200. # --------------------------------------------
  201. #my $DOT = q{.};
  202. # Important: change it to _, because FHEM uses regexp
  203. my $DOT = q{_};
  204. my @TRX_WEATHER_winddir_name=("N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW");
  205. # --------------------------------------------
  206. # The following functions are changed:
  207. # - some parameter like "parent" and others are removed
  208. # - @res array return the values directly (no usage of xPL::Message)
  209. sub TRX_WEATHER_temperature {
  210. my ($bytes, $dev, $res, $off) = @_;
  211. my $temp =
  212. (
  213. (($bytes->[$off] & 0x80) ? -1 : 1) *
  214. (($bytes->[$off] & 0x7f)*256 + $bytes->[$off+1])
  215. )/10;
  216. push @$res, {
  217. device => $dev,
  218. type => 'temp',
  219. current => $temp,
  220. units => 'Grad Celsius'
  221. }
  222. }
  223. sub TRX_WEATHER_temperature_food {
  224. my ($bytes, $dev, $res, $off) = @_;
  225. my $temp = $bytes->[$off]*256 + $bytes->[$off+1];
  226. return if ($temp > $TRX_MAX_TEMP_BBQ);
  227. push @$res, {
  228. device => $dev,
  229. type => 'temp-food',
  230. current => $temp,
  231. units => 'Grad Celsius'
  232. }
  233. }
  234. # -----------------------------
  235. sub TRX_WEATHER_common_therm {
  236. my $type = shift;
  237. my $longids = shift;
  238. my $bytes = shift;
  239. my $subtype = sprintf "%02x", $bytes->[1];
  240. my $dev_type;
  241. my %devname =
  242. ( # HEXSTRING => "NAME"
  243. 0x00 => "TLX7506",
  244. 0x01 => "TH10",
  245. );
  246. if (exists $devname{$bytes->[1]}) {
  247. $dev_type = $devname{$bytes->[1]};
  248. } else {
  249. Log3 undef, 3, "TRX_WEATHER: common_therm error undefined subtype=$subtype";
  250. my @res = ();
  251. return @res;
  252. }
  253. #my $seqnbr = sprintf "%02x", $bytes->[2];
  254. my $dev_str = $dev_type;
  255. if (TRX_WEATHER_use_longid($longids,$dev_type)) {
  256. $dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
  257. }
  258. if ($bytes->[4] > 0) {
  259. $dev_str .= $DOT.sprintf("%d", $bytes->[4]);
  260. }
  261. my @res = ();
  262. # hexline debugging
  263. if ($TRX_HEX_debug) {
  264. my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
  265. push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
  266. }
  267. my $temp = ($bytes->[5]);
  268. if ($temp) {
  269. push @res, {
  270. device => $dev_str,
  271. type => 'temp',
  272. current => $temp,
  273. units => 'Grad Celsius'
  274. }
  275. }
  276. my $setpoint =($bytes->[6]);
  277. if ($setpoint) {
  278. push @res, {
  279. device => $dev_str,
  280. type => 'setpoint',
  281. current => $setpoint,
  282. units => 'Grad Celsius'
  283. }
  284. }
  285. my $demand;
  286. my $t_status = ($bytes->[7] & 0x03);
  287. if ($t_status == 0) { $demand = 'n/a'}
  288. elsif ($t_status == 1) { $demand = 'on'}
  289. elsif ($t_status == 2) { $demand = 'off'}
  290. elsif ($t_status == 3) { $demand = 'initializing'}
  291. else {
  292. $demand = sprintf("unknown-%02x",$t_status);
  293. }
  294. Log3 undef, 5, "TRX_WEATHER: demand = $bytes->[7] $t_status $demand";
  295. push @res, {
  296. device => $dev_str,
  297. type => 'demand',
  298. current => sprintf("%s",$demand),
  299. };
  300. my $rssi = ($bytes->[8] & 0xf0) >> 4;
  301. if ($trx_rssi == 1) {
  302. push @res, {
  303. device => $dev_str,
  304. type => 'rssi',
  305. current => sprintf("%d",$rssi),
  306. };
  307. }
  308. return @res;
  309. }
  310. sub TRX_WEATHER_temperature_bbq {
  311. my ($bytes, $dev, $res, $off) = @_;
  312. my $temp = $bytes->[$off]*256 + $bytes->[$off+1];
  313. return if ($temp > $TRX_MAX_TEMP_BBQ);
  314. push @$res, {
  315. device => $dev,
  316. type => 'temp-bbq',
  317. current => $temp,
  318. units => 'Grad Celsius'
  319. }
  320. }
  321. sub TRX_WEATHER_chill_temperature {
  322. my ($bytes, $dev, $res, $off) = @_;
  323. my $temp =
  324. (
  325. (($bytes->[$off] & 0x80) ? -1 : 1) *
  326. (($bytes->[$off] & 0x7f)*256 + $bytes->[$off+1])
  327. )/10;
  328. push @$res, {
  329. device => $dev,
  330. type => 'chilltemp',
  331. current => $temp,
  332. units => 'Grad Celsius'
  333. }
  334. }
  335. sub TRX_WEATHER_humidity {
  336. my ($bytes, $dev, $res, $off) = @_;
  337. my $hum = $bytes->[$off];
  338. my $hum_str = ['dry', 'comfortable', 'normal', 'wet']->[$bytes->[$off+1]];
  339. push @$res, {
  340. device => $dev,
  341. type => 'humidity',
  342. current => $hum,
  343. string => $hum_str,
  344. units => '%'
  345. }
  346. }
  347. sub TRX_WEATHER_pressure {
  348. my ($bytes, $dev, $res, $off) = @_;
  349. #my $offset = 795 unless ($offset);
  350. my $hpa = ($bytes->[$off])*256 + $bytes->[$off+1];
  351. my $forecast = { 0x00 => 'noforecast',
  352. 0x01 => 'sunny',
  353. 0x02 => 'partly',
  354. 0x03 => 'cloudy',
  355. 0x04 => 'rain',
  356. }->{$bytes->[$off+2]} || 'unknown';
  357. push @$res, {
  358. device => $dev,
  359. type => 'pressure',
  360. current => $hpa,
  361. units => 'hPa',
  362. forecast => $forecast,
  363. };
  364. }
  365. sub TRX_WEATHER_simple_battery {
  366. my ($bytes, $dev, $res, $off) = @_;
  367. my $battery;
  368. my $battery_level = $bytes->[$off] & 0x0f;
  369. if ($battery_level == 0x9) { $battery = 'ok'}
  370. elsif ($battery_level == 0x0) { $battery = 'low'}
  371. else {
  372. $battery = sprintf("unknown-%02x",$battery_level);
  373. }
  374. push @$res, {
  375. device => $dev,
  376. type => 'battery',
  377. current => $battery,
  378. };
  379. my $rssi = ($bytes->[$off] & 0xf0) >> 4;
  380. if ($trx_rssi == 1) {
  381. push @$res, {
  382. device => $dev,
  383. type => 'rssi',
  384. current => sprintf("%d",$rssi),
  385. };
  386. }
  387. }
  388. sub TRX_WEATHER_battery {
  389. my ($bytes, $dev, $res, $off) = @_;
  390. my $battery;
  391. my $battery_level = ($bytes->[$off] & 0x0f) + 1;
  392. if ($battery_level > 5) {
  393. $battery = sprintf("ok %d0%%",$battery_level);
  394. } else {
  395. $battery = sprintf("low %d0%%",$battery_level);
  396. }
  397. push @$res, {
  398. device => $dev,
  399. type => 'battery',
  400. current => $battery,
  401. };
  402. my $rssi = ($bytes->[$off] & 0xf0) >> 4;
  403. if ($trx_rssi == 1) {
  404. push @$res, {
  405. device => $dev,
  406. type => 'rssi',
  407. current => sprintf("%d",$rssi),
  408. };
  409. }
  410. }
  411. # Test if to use longid for device type
  412. sub TRX_WEATHER_use_longid {
  413. my ($longids,$dev_type) = @_;
  414. return 0 if ($longids eq "");
  415. return 0 if ($longids eq "0");
  416. return 1 if ($longids eq "1");
  417. return 1 if ($longids eq "ALL");
  418. return 1 if(",$longids," =~ m/,$dev_type,/);
  419. return 0;
  420. }
  421. # ------------------------------------------------------------
  422. # T R X _ W E A T H E R _ c o m m o n _ a n e m o m e t e r
  423. # 0x5610 => { part => 'WIND'
  424. sub TRX_WEATHER_common_anemometer {
  425. my $type = shift;
  426. my $longids = shift;
  427. my $bytes = shift;
  428. my $subtype = sprintf "%02x", $bytes->[1];
  429. my $dev_type;
  430. my %devname =
  431. ( # HEXSTRING => "NAME"
  432. 0x01 => "WTGR800_A",
  433. 0x02 => "WGR800",
  434. 0x03 => "WGR918",
  435. 0x04 => "TFA_WIND",
  436. 0x05 => "WDS500", # UPM WDS500
  437. 0x06 => "WS2300_WIND", # WS2300
  438. 0x07 => "WS4500_WIND", # Alecto WS4500, Auriol H13726, Hama EWS1500, Meteoscan W155/W160, Ventus WS155
  439. );
  440. if (exists $devname{$bytes->[1]}) {
  441. $dev_type = $devname{$bytes->[1]};
  442. } else {
  443. Log3 undef, 3, "TRX_WEATHER: common_anemometer error undefined subtype=$subtype";
  444. my @res = ();
  445. return @res;
  446. }
  447. my $dev_str = $dev_type;
  448. if (TRX_WEATHER_use_longid($longids,$dev_type)) {
  449. $dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
  450. }
  451. if ($bytes->[4] > 0) {
  452. $dev_str .= $DOT.sprintf("%d", $bytes->[4]);
  453. }
  454. my @res = ();
  455. # hexline debugging
  456. if ($TRX_HEX_debug) {
  457. my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
  458. push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
  459. }
  460. my $dir = $bytes->[5]*256 + $bytes->[6];
  461. my $dirname = $TRX_WEATHER_winddir_name[int((($dir + 11.25) % 360) / 22.5)];
  462. my $avspeed = ($bytes->[7]*256 + $bytes->[8]) / 10;
  463. my $speed = ($bytes->[9]*256 + $bytes->[10]) / 10;
  464. if ($dev_type eq "TFA_WIND") {
  465. TRX_WEATHER_temperature($bytes, $dev_str, \@res, 11);
  466. TRX_WEATHER_chill_temperature($bytes, $dev_str, \@res, 13);
  467. }
  468. push @res, {
  469. device => $dev_str,
  470. type => 'speed',
  471. current => $speed,
  472. average => $avspeed,
  473. units => 'mps',
  474. } , {
  475. device => $dev_str,
  476. type => 'direction',
  477. current => $dir,
  478. string => $dirname,
  479. units => 'degrees',
  480. };
  481. TRX_WEATHER_battery($bytes, $dev_str, \@res, 15);
  482. return @res;
  483. }
  484. # --------------------------------------------------------------------
  485. # T R X _ W E A T H E R _ c o m m o n _ b b q
  486. # 0x4e0a => { part => 'BBQ'
  487. #
  488. sub TRX_WEATHER_common_bbq {
  489. my $type = shift;
  490. my $longids = shift;
  491. my $bytes = shift;
  492. my $subtype = sprintf "%02x", $bytes->[1];
  493. my $dev_type;
  494. my %devname =
  495. ( # HEXSTRING => "NAME"
  496. 0x01 => "ET732",
  497. );
  498. if (exists $devname{$bytes->[1]}) {
  499. $dev_type = $devname{$bytes->[1]};
  500. } else {
  501. Log3 undef, 3, "TRX_WEATHER: common_bbq error undefined subtype=$subtype";
  502. my @res = ();
  503. return @res;
  504. }
  505. #my $seqnbr = sprintf "%02x", $bytes->[2];
  506. my $dev_str = $dev_type;
  507. if (TRX_WEATHER_use_longid($longids,$dev_type)) {
  508. $dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
  509. $dev_str .= $DOT.sprintf("%02x", $bytes->[4]);
  510. }
  511. my @res = ();
  512. # hexline debugging
  513. if ($TRX_HEX_debug) {
  514. my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
  515. push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
  516. }
  517. TRX_WEATHER_temperature_food($bytes, $dev_str, \@res, 5);
  518. TRX_WEATHER_temperature_bbq($bytes, $dev_str, \@res, 7);
  519. TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 9);
  520. return @res;
  521. }
  522. # --------------------------------------------------------------------
  523. # T R X _ W E A T H E R _ c o m m o n _ t e m p
  524. # 0x5008 => { part => 'TEMP'
  525. sub TRX_WEATHER_common_temp {
  526. my $type = shift;
  527. my $longids = shift;
  528. my $bytes = shift;
  529. my $subtype = sprintf "%02x", $bytes->[1];
  530. my $dev_type;
  531. my %devname =
  532. ( # HEXSTRING => "NAME"
  533. 0x01 => "THR128",
  534. 0x02 => "THGR132N", # was THGR228N,
  535. 0x03 => "THWR800",
  536. 0x04 => "RTHN318",
  537. 0x05 => "TX3", # LaCrosse TX3
  538. 0x06 => "TS15C",
  539. 0x07 => "VIKING_02811", # Viking 02811
  540. 0x08 => "WS2300", # La Crosse WS2300
  541. 0x09 => "RUBICSON", # RUBiCSON
  542. 0x0a => "TFA_303133", # TFA 30.3133
  543. 0x0b => "WT0122", # WT0122
  544. );
  545. if (exists $devname{$bytes->[1]}) {
  546. $dev_type = $devname{$bytes->[1]};
  547. } else {
  548. Log3 undef, 3, "TRX_WEATHER: common_temp error undefined subtype=$subtype";
  549. my @res = ();
  550. return @res;
  551. }
  552. #my $seqnbr = sprintf "%02x", $bytes->[2];
  553. my $dev_str = $dev_type;
  554. if (TRX_WEATHER_use_longid($longids,$dev_type)) {
  555. $dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
  556. }
  557. if ($bytes->[4] > 0) {
  558. $dev_str .= $DOT.sprintf("%d", $bytes->[4]);
  559. }
  560. my @res = ();
  561. # hexline debugging
  562. if ($TRX_HEX_debug) {
  563. my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
  564. push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
  565. }
  566. TRX_WEATHER_temperature($bytes, $dev_str, \@res, 5);
  567. TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 7);
  568. return @res;
  569. }
  570. # --------------------------------------------------------------------
  571. # T R X _ W E A T H E R _ c o m m o n _ h y d r o
  572. # 0x5108 => { part => 'HYDRO'
  573. sub TRX_WEATHER_common_hydro {
  574. my $type = shift;
  575. my $longids = shift;
  576. my $bytes = shift;
  577. my $subtype = sprintf "%02x", $bytes->[1];
  578. my $dev_type;
  579. my %devname =
  580. ( # HEXSTRING => "NAME"
  581. 0x01 => "TX3", # LaCrosse TX3
  582. 0x02 => "WS2300", # LaCrosse WS2300 Humidity
  583. 0x03 => "S80", # Inovalley S80 plant humidity sensor
  584. );
  585. if (exists $devname{$bytes->[1]}) {
  586. $dev_type = $devname{$bytes->[1]};
  587. } else {
  588. Log3 undef, 3, "TRX_WEATHER: common_hydro error undefined subtype=$subtype";
  589. my @res = ();
  590. return @res;
  591. }
  592. my $dev_str = $dev_type;
  593. if (TRX_WEATHER_use_longid($longids,$dev_type)) {
  594. $dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
  595. }
  596. if ($bytes->[4] > 0) {
  597. $dev_str .= $DOT.sprintf("%d", $bytes->[4]);
  598. }
  599. my @res = ();
  600. # hexline debugging
  601. if ($TRX_HEX_debug) {
  602. my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
  603. push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
  604. }
  605. TRX_WEATHER_humidity($bytes, $dev_str, \@res, 5);
  606. TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 7);
  607. return @res;
  608. }
  609. # --------------------------------------------------------------------
  610. # T R X _ W E A T H E R _ c o m m o n _ t e m p h y d r o
  611. # 0x520a => { part => 'TEMPHYDRO'
  612. sub TRX_WEATHER_common_temphydro {
  613. my $type = shift;
  614. my $longids = shift;
  615. my $bytes = shift;
  616. my $subtype = sprintf "%02x", $bytes->[1];
  617. my $dev_type;
  618. my %devname =
  619. ( # HEXSTRING => "NAME"
  620. 0x01 => "THGR228N", # THGN122/123, THGN132, THGR122/228/238/268
  621. 0x02 => "THGR810",
  622. 0x03 => "RTGR328",
  623. 0x04 => "THGR328",
  624. 0x05 => "WTGR800_T",
  625. 0x06 => "THGR918",
  626. 0x07 => "TFATS34C",
  627. 0x08 => "WT450H", # WT260,WT260H,WT440H,WT450,WT450H
  628. 0x09 => "VIKING_02038", # Viking 02035,02038 (02035 has no humidity)
  629. 0x0a => "RUBICSON", # Rubicson
  630. 0x0b => "EW109", # EW109
  631. 0x0c => "XT300", # Imagintronix/Opus XT300 Soil sensor
  632. 0x0d => "WS1700", # Alecto WS1700 and compatibles
  633. 0x0e => "WS3500", # Alecto WS3500, WS4500, Auriol H13726, Hama EWS1500, Meteoscan W155/W160, Ventus WS155
  634. );
  635. if (exists $devname{$bytes->[1]}) {
  636. $dev_type = $devname{$bytes->[1]};
  637. } else {
  638. Log3 undef, 3, "TRX_WEATHER: common_temphydro error undefined subtype=$subtype";
  639. my @res = ();
  640. return @res;
  641. }
  642. my $dev_str = $dev_type;
  643. if (TRX_WEATHER_use_longid($longids,$dev_type)) {
  644. $dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
  645. } elsif ($dev_type eq "TFATS34C") {
  646. #Log3 undef, 1,"TRX_WEATHER: TFA";
  647. if ($bytes->[3] > 0x20 && $bytes->[3] <= 0x3F) {
  648. #Log3 undef, 1,"TRX_WEATHER: TFA 1";
  649. $dev_str .= $DOT."1";
  650. } elsif ($bytes->[3] >= 0x40 && $bytes->[3] <= 0x5F) {
  651. #Log3 undef, 1,"TRX_WEATHER: TFA 2";
  652. $dev_str .= $DOT."2";
  653. } elsif ($bytes->[3] >= 0x60 && $bytes->[3] <= 0x7F) {
  654. #Log3 undef, 1,"TRX_WEATHER: TFA 3";
  655. $dev_str .= $DOT."3";
  656. } elsif ($bytes->[3] >= 0xA0 && $bytes->[3] <= 0xBF) {
  657. #Log3 undef, 1,"TRX_WEATHER: TFA 4";
  658. $dev_str .= $DOT."4";
  659. } elsif ($bytes->[3] >= 0xC0 && $bytes->[3] <= 0xDF) {
  660. #Log3 undef, 1,"TRX_WEATHER: TFA 5";
  661. $dev_str .= $DOT."5";
  662. } else {
  663. #Log3 undef, 1,"TRX_WEATHER: TFA 9";
  664. $dev_str .= $DOT."9";
  665. }
  666. }
  667. if ($dev_type ne "TFATS34C" && $bytes->[4] > 0) {
  668. $dev_str .= $DOT.sprintf("%d", $bytes->[4]);
  669. }
  670. my @res = ();
  671. # hexline debugging
  672. if ($TRX_HEX_debug) {
  673. my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
  674. push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
  675. }
  676. TRX_WEATHER_temperature($bytes, $dev_str, \@res, 5);
  677. TRX_WEATHER_humidity($bytes, $dev_str, \@res, 7);
  678. if ($dev_type eq "THGR918") {
  679. TRX_WEATHER_battery($bytes, $dev_str, \@res, 9);
  680. } else {
  681. TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 9);
  682. }
  683. return @res;
  684. }
  685. # --------------------------------------------------------------------
  686. # T R X _ W E A T H E R _ c o m m o n _ t e m p h y d r o b a r o
  687. # 0x540d => { part => 'TEMPHYDROBARO'
  688. sub TRX_WEATHER_common_temphydrobaro {
  689. my $type = shift;
  690. my $longids = shift;
  691. my $bytes = shift;
  692. my $subtype = sprintf "%02x", $bytes->[1];
  693. my $dev_type;
  694. my %devname =
  695. ( # HEXSTRING => "NAME"
  696. 0x01 => "BTHR918",
  697. 0x02 => "BTHR918N",
  698. );
  699. if (exists $devname{$bytes->[1]}) {
  700. $dev_type = $devname{$bytes->[1]};
  701. } else {
  702. Log3 undef, 3, "TRX_WEATHER: common_temphydrobaro error undefined subtype=$subtype";
  703. my @res = ();
  704. return @res;
  705. }
  706. my $dev_str = $dev_type;
  707. if (TRX_WEATHER_use_longid($longids,$dev_type)) {
  708. $dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
  709. }
  710. if ($bytes->[4] > 0) {
  711. $dev_str .= $DOT.sprintf("%d", $bytes->[4]);
  712. }
  713. my @res = ();
  714. # hexline debugging
  715. if ($TRX_HEX_debug) {
  716. my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
  717. push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
  718. }
  719. TRX_WEATHER_temperature($bytes, $dev_str, \@res, 5);
  720. TRX_WEATHER_humidity($bytes, $dev_str, \@res, 7);
  721. TRX_WEATHER_pressure($bytes, $dev_str, \@res, 9);
  722. TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 12);
  723. return @res;
  724. }
  725. # --------------------------------------------------------------------
  726. # T R X _ W E A T H E R _ c o m m o n _ r a i n
  727. # 0x550b => { part => 'RAIN'
  728. sub TRX_WEATHER_common_rain {
  729. my $type = shift;
  730. my $longids = shift;
  731. my $bytes = shift;
  732. my $subtype = sprintf "%02x", $bytes->[1];
  733. my $dev_type;
  734. my %devname =
  735. ( # HEXSTRING => "NAME"
  736. 0x01 => "RGR918",
  737. 0x02 => "PCR800",
  738. 0x03 => "TFA_RAIN",
  739. 0x04 => "RG700",
  740. 0x05 => "WS2300_RAIN", # WS2300
  741. 0x06 => "TX5_RAIN", # La Crosse TX5
  742. 0x07 => "WS4500_RAIN", # Alecto WS4500, Auriol H13726, Hama EWS1500, Meteoscan W155/W160,
  743. );
  744. if (exists $devname{$bytes->[1]}) {
  745. $dev_type = $devname{$bytes->[1]};
  746. } else {
  747. Log3 undef, 3, "TRX_WEATHER: common_rain error undefined subtype=$subtype";
  748. my @res = ();
  749. return @res;
  750. }
  751. my $dev_str = $dev_type;
  752. if (TRX_WEATHER_use_longid($longids,$dev_type)) {
  753. $dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
  754. }
  755. if ($bytes->[4] > 0) {
  756. $dev_str .= $DOT.sprintf("%d", $bytes->[4]);
  757. }
  758. my @res = ();
  759. # hexline debugging
  760. if ($TRX_HEX_debug) {
  761. my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
  762. push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
  763. }
  764. my $rain = $bytes->[5]*256 + $bytes->[6];
  765. if ($dev_type eq "RGR918") {
  766. push @res, {
  767. device => $dev_str,
  768. type => 'rain',
  769. current => $rain,
  770. units => 'mm/h',
  771. };
  772. } elsif ($dev_type eq "PCR800") {
  773. $rain = $rain / 100;
  774. push @res, {
  775. device => $dev_str,
  776. type => 'rain',
  777. current => $rain,
  778. units => 'mm/h',
  779. };
  780. }
  781. if ($dev_type ne "TX5_RAIN") {
  782. my $train = ($bytes->[7]*256*256 + $bytes->[8]*256 + $bytes->[9])/10; # total rain
  783. push @res, {
  784. device => $dev_str,
  785. type => 'train',
  786. current => $train,
  787. units => 'mm',
  788. };
  789. }
  790. TRX_WEATHER_battery($bytes, $dev_str, \@res, 10);
  791. return @res;
  792. }
  793. my @uv_str =
  794. (
  795. qw/low low low/, # 0 - 2
  796. qw/medium medium medium/, # 3 - 5
  797. qw/high high/, # 6 - 7
  798. 'very high', 'very high', 'very high', # 8 - 10
  799. );
  800. sub TRX_WEATHER_uv_string {
  801. $uv_str[$_[0]] || 'dangerous';
  802. }
  803. # ------------------------------------------------------------
  804. # T R X _ W E A T H E R _ c o m m o n _ u v
  805. # * 0x5709 => { part => 'UV'
  806. sub TRX_WEATHER_common_uv {
  807. my $type = shift;
  808. my $longids = shift;
  809. my $bytes = shift;
  810. my $subtype = sprintf "%02x", $bytes->[1];
  811. my $dev_type;
  812. my %devname =
  813. ( # HEXSTRING => "NAME"
  814. 0x01 => "UVN128", # Oregon UVN128, UV138
  815. 0x02 => "UVN800", # Oregon UVN800
  816. 0x03 => "TFA_UV", # TFA_UV-Sensor
  817. );
  818. if (exists $devname{$bytes->[1]}) {
  819. $dev_type = $devname{$bytes->[1]};
  820. } else {
  821. Log3 undef, 3, "TRX_WEATHER: common_uv error undefined subtype=$subtype";
  822. my @res = ();
  823. return @res;
  824. }
  825. #my $seqnbr = sprintf "%02x", $bytes->[2];
  826. my $dev_str = $dev_type;
  827. if (TRX_WEATHER_use_longid($longids,$dev_type)) {
  828. $dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
  829. }
  830. if ($bytes->[4] > 0) {
  831. $dev_str .= $DOT.sprintf("%d", $bytes->[4]);
  832. }
  833. my @res = ();
  834. # hexline debugging
  835. if ($TRX_HEX_debug) {
  836. my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
  837. push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
  838. }
  839. my $uv = $bytes->[5]/10; # UV
  840. my $risk = TRX_WEATHER_uv_string(int($uv));
  841. push @res, {
  842. device => $dev_str,
  843. type => 'uv',
  844. current => $uv,
  845. risk => $risk,
  846. units => '',
  847. };
  848. if ($dev_type eq "TFA_UV") {
  849. TRX_WEATHER_temperature($bytes, $dev_str, \@res, 6);
  850. }
  851. TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 8);
  852. return @res;
  853. }
  854. # ------------------------------------------------------------
  855. # T R X _ W E A T H E R _ c o m m o n _ d a t e t i m e
  856. # 0x580D => { part => 'DATE', method => \&TRX_WEATHER_common_datetime, },
  857. sub TRX_WEATHER_common_datetime {
  858. my $type = shift;
  859. my $longids = shift;
  860. my $bytes = shift;
  861. my $subtype = sprintf "%02x", $bytes->[1];
  862. my $dev_type;
  863. my %devname =
  864. ( # HEXSTRING => "NAME"
  865. 0x01 => "RTGR328_DATE", # RTGR328N datetime datagram
  866. );
  867. if (exists $devname{$bytes->[1]}) {
  868. $dev_type = $devname{$bytes->[1]};
  869. } else {
  870. Log3 undef, 3, "TRX_WEATHER: common_datetime error undefined subtype=$subtype";
  871. my @res = ();
  872. return @res;
  873. }
  874. my $dev_str = $dev_type;
  875. if (TRX_WEATHER_use_longid($longids,$dev_type)) {
  876. $dev_str .= $DOT.sprintf("%02x%02x", $bytes->[3],$bytes->[4]);
  877. }
  878. my @res = ();
  879. # hexline debugging
  880. if ($TRX_HEX_debug) {
  881. my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
  882. push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
  883. }
  884. push @res, {
  885. device => $dev_str,
  886. type => 'date',
  887. current => sprintf("%02d-%02d-%02d", $bytes->[5],$bytes->[6],$bytes->[7]),
  888. units => 'yymmdd',
  889. };
  890. push @res, {
  891. device => $dev_str,
  892. type => 'time',
  893. current => sprintf("%02d:%02d:%02d", $bytes->[9],$bytes->[10],$bytes->[11]),
  894. units => 'hhmmss',
  895. };
  896. TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 12);
  897. return @res;
  898. }
  899. # ------------------------------------------------------------
  900. # T R X _ W E A T H E R _ c o m m o n _ e n e r g y ( )
  901. #
  902. # devices: CM119, CM160, CM180
  903. sub TRX_WEATHER_common_energy {
  904. my $type = shift;
  905. my $longids = shift;
  906. my $bytes = shift;
  907. my $subtype = sprintf "%02x", $bytes->[1];
  908. my $dev_type;
  909. my %devname =
  910. ( # HEXSTRING => "NAME"
  911. 0x01 => "CM160", # CM119, CM160
  912. 0x02 => "CM180", # CM180
  913. );
  914. if (exists $devname{$bytes->[1]}) {
  915. $dev_type = $devname{$bytes->[1]};
  916. } else {
  917. Log3 undef, 3, "TRX_WEATHER: common_energy error undefined subtype=$subtype";
  918. my @res = ();
  919. return @res;
  920. }
  921. #my $seqnbr = sprintf "%02x", $bytes->[2];
  922. my $dev_str = $dev_type;
  923. $dev_str .= $DOT.sprintf("%02x%02x", $bytes->[3],$bytes->[4]);
  924. my @res = ();
  925. # hexline debugging
  926. if ($TRX_HEX_debug) {
  927. my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
  928. push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
  929. }
  930. my $energy_current = (
  931. $bytes->[6] * 256*256*256 +
  932. $bytes->[7] * 256*256 +
  933. $bytes->[8] * 256 +
  934. $bytes->[9]
  935. );
  936. push @res, {
  937. device => $dev_str,
  938. type => 'energy_current',
  939. current => $energy_current,
  940. units => 'W',
  941. };
  942. my $energy_total = (
  943. $bytes->[10] * 256*256*256*256*256 +
  944. $bytes->[11] * 256*256*256*256 +
  945. $bytes->[12] * 256*256*256 +
  946. $bytes->[13] * 256*256 +
  947. $bytes->[14] * 256 +
  948. $bytes->[15]
  949. ) / 223.666;
  950. $energy_total = $energy_total / 1000;
  951. push @res, {
  952. device => $dev_str,
  953. type => 'energy_total',
  954. current => $energy_total,
  955. units => 'kWh',
  956. };
  957. my $count = $bytes->[5];
  958. # TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 16) if ($count==0 || $count==1 || $count==2 || $count==3 || $count==8 || $count==9);
  959. TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 16);
  960. return @res;
  961. }
  962. # ------------------------------------------------------------
  963. # T R X _ W E A T H E R _ c o m m o n _ e n e r g y 2
  964. #
  965. # devices: CM180i
  966. sub TRX_WEATHER_common_energy2 {
  967. my $type = shift;
  968. my $longids = shift;
  969. my $bytes = shift;
  970. my $subtype = sprintf "%02x", $bytes->[1];
  971. my $dev_type;
  972. my %devname =
  973. ( # HEXSTRING => "NAME"
  974. 0x01 => "CM180I", # CM180i
  975. );
  976. if (exists $devname{$bytes->[1]}) {
  977. $dev_type = $devname{$bytes->[1]};
  978. } else {
  979. Log3 undef, 3, "TRX_WEATHER: common_energy2 error undefined subtype=$subtype";
  980. my @res = ();
  981. return @res;
  982. }
  983. #my $seqnbr = sprintf "%02x", $bytes->[2];
  984. my $dev_str = $dev_type;
  985. $dev_str .= $DOT.sprintf("%02x%02x", $bytes->[3],$bytes->[4]);
  986. my @res = ();
  987. # hexline debugging
  988. if ($TRX_HEX_debug) {
  989. my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
  990. push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
  991. }
  992. my $energy_count = $bytes->[5];
  993. if (1) {
  994. my $energy_current_ch1 = ($bytes->[6] * 256 + $bytes->[7])/10;
  995. my $energy_current_ch2 = ($bytes->[8] * 256 + $bytes->[9])/10;
  996. my $energy_current_ch3 = ($bytes->[10] * 256 + $bytes->[11]/10);
  997. push @res, {
  998. device => $dev_str,
  999. type => 'energy_ch1',
  1000. current => $energy_current_ch1,
  1001. units => 'A',
  1002. };
  1003. push @res, {
  1004. device => $dev_str,
  1005. type => 'energy_ch2',
  1006. current => $energy_current_ch2,
  1007. units => 'A',
  1008. };
  1009. push @res, {
  1010. device => $dev_str,
  1011. type => 'energy_ch3',
  1012. current => $energy_current_ch3,
  1013. units => 'A',
  1014. };
  1015. }
  1016. if ($energy_count == 0) {
  1017. my $energy_total = (
  1018. $bytes->[12] * 256*256*256*256*256 +
  1019. $bytes->[13] * 256*256*256*256 +
  1020. $bytes->[14] * 256*256*256 +
  1021. $bytes->[15] * 256*256 +
  1022. $bytes->[16] * 256 +
  1023. $bytes->[17]
  1024. ) / 223.666;
  1025. $energy_total = $energy_total / 1000;
  1026. push @res, {
  1027. device => $dev_str,
  1028. type => 'energy_total',
  1029. current => $energy_total,
  1030. units => 'kWh',
  1031. };
  1032. }
  1033. # TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 16) if ($count==0 || $count==1 || $count==2 || $count==3 || $count==8 || $count==9);
  1034. TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 18);
  1035. return @res;
  1036. }
  1037. # ------------------------------------------------------------
  1038. # T R X _ W E A T H E R _ c o m m o n _ e n e r g y 3
  1039. #
  1040. # devices: REVOLT
  1041. sub TRX_WEATHER_common_energy3 {
  1042. my $type = shift;
  1043. my $longids = shift;
  1044. my $bytes = shift;
  1045. my $subtype = sprintf "%02x", $bytes->[1];
  1046. my $dev_type;
  1047. my %devname =
  1048. ( # HEXSTRING => "NAME"
  1049. 0x01 => "REVOLT", # Revolt
  1050. );
  1051. if (exists $devname{$bytes->[1]}) {
  1052. $dev_type = $devname{$bytes->[1]};
  1053. } else {
  1054. Log3 undef, 3, "TRX_WEATHER: common_energy3 error undefined subtype=$subtype";
  1055. my @res = ();
  1056. return @res;
  1057. }
  1058. #my $seqnbr = sprintf "%02x", $bytes->[2];
  1059. my $dev_str = $dev_type;
  1060. $dev_str .= $DOT.sprintf("%02x%02x", $bytes->[3],$bytes->[4]);
  1061. my @res = ();
  1062. # hexline debugging
  1063. if ($TRX_HEX_debug) {
  1064. my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
  1065. push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
  1066. }
  1067. my $energy_voltage = $bytes->[5];
  1068. push @res, {
  1069. device => $dev_str,
  1070. type => 'energy_voltage',
  1071. current => $energy_voltage,
  1072. units => 'V',
  1073. };
  1074. my $energy_current = ($bytes->[6] * 256 + $bytes->[7]) / 100;
  1075. push @res, {
  1076. device => $dev_str,
  1077. type => 'energy_current_revolt',
  1078. current => $energy_current,
  1079. units => 'A',
  1080. };
  1081. my $energy_power = ($bytes->[8] * 256 + $bytes->[9]) / 10;
  1082. push @res, {
  1083. device => $dev_str,
  1084. type => 'energy_power',
  1085. current => $energy_power,
  1086. units => 'W',
  1087. };
  1088. my $energy_total = ($bytes->[10] * 256 + $bytes->[11]) / 100;
  1089. push @res, {
  1090. device => $dev_str,
  1091. type => 'energy_total',
  1092. current => $energy_total,
  1093. units => 'kWh',
  1094. };
  1095. my $energy_pf = $bytes->[12] / 100;
  1096. push @res, {
  1097. device => $dev_str,
  1098. type => 'energy_pf',
  1099. current => $energy_pf,
  1100. units => '',
  1101. };
  1102. my $energy_freq = $bytes->[13];
  1103. push @res, {
  1104. device => $dev_str,
  1105. type => 'energy_freq',
  1106. current => $energy_freq,
  1107. units => 'Hz',
  1108. };
  1109. my $rssi = ($bytes->[14] & 0xf0) >> 4;
  1110. if ($trx_rssi == 1) {
  1111. push @res, {
  1112. device => $dev_str,
  1113. type => 'rssi',
  1114. current => sprintf("%d",$rssi),
  1115. };
  1116. }
  1117. return @res;
  1118. }
  1119. # ------------------------------------------------------------
  1120. #
  1121. sub TRX_WEATHER_common_weight {
  1122. my $type = shift;
  1123. my $longids = shift;
  1124. my $bytes = shift;
  1125. my $subtype = sprintf "%02x", $bytes->[1];
  1126. my $dev_type;
  1127. my %devname =
  1128. ( # HEXSTRING => "NAME"
  1129. 0x01 => "BWR101",
  1130. 0x02 => "GR101",
  1131. );
  1132. if (exists $devname{$bytes->[1]}) {
  1133. $dev_type = $devname{$bytes->[1]};
  1134. } else {
  1135. Log3 undef, 3, "TRX_WEATHER: common_weight error undefined subtype=$subtype";
  1136. my @res = ();
  1137. return @res;
  1138. }
  1139. #my $seqnbr = sprintf "%02x", $bytes->[2];
  1140. my $dev_str = $dev_type;
  1141. if (TRX_WEATHER_use_longid($longids,$dev_type)) {
  1142. $dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
  1143. }
  1144. if ($bytes->[4] > 0) {
  1145. $dev_str .= $DOT.sprintf("%d", $bytes->[4]);
  1146. }
  1147. my @res = ();
  1148. # hexline debugging
  1149. if ($TRX_HEX_debug) {
  1150. my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
  1151. push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
  1152. }
  1153. my $weight = ($bytes->[5]*256 + $bytes->[6])/10;
  1154. push @res, {
  1155. device => $dev_str,
  1156. type => 'weight',
  1157. current => $weight,
  1158. units => 'kg',
  1159. };
  1160. #TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 7);
  1161. return @res;
  1162. }
  1163. # -----------------------------
  1164. sub
  1165. TRX_WEATHER_Parse($$)
  1166. {
  1167. my ($iohash, $hexline) = @_;
  1168. #my $hashname = $iohash->{NAME};
  1169. #my $longid = AttrVal($hashname,"longids","");
  1170. #Log3 $iohash, $iohash, 5 ,"2: name=$hashname, attr longids = $longid";
  1171. my $longids = 0;
  1172. if (defined($attr{$iohash->{NAME}}{longids})) {
  1173. $longids = $attr{$iohash->{NAME}}{longids};
  1174. #Log3 $iohash, 5,"0: attr longids = $longids";
  1175. }
  1176. $trx_rssi = 0;
  1177. if (defined($attr{$iohash->{NAME}}{rssi})) {
  1178. $trx_rssi = $attr{$iohash->{NAME}}{rssi};
  1179. #Log3 $iohash, 5, "0: attr rssi = $trx_rssi";
  1180. }
  1181. my $time = time();
  1182. # convert to binary
  1183. my $msg = pack('H*', $hexline);
  1184. if ($time_old ==0) {
  1185. Log3 $iohash, 5, "TRX_WEATHER: decoding delay=0 hex=$hexline";
  1186. } else {
  1187. my $time_diff = $time - $time_old ;
  1188. Log3 $iohash, 5, "TRX_WEATHER: decoding delay=$time_diff hex=$hexline";
  1189. }
  1190. $time_old = $time;
  1191. # convert string to array of bytes. Skip length byte
  1192. my @rfxcom_data_array = ();
  1193. foreach (split(//, substr($msg,1))) {
  1194. push (@rfxcom_data_array, ord($_) );
  1195. }
  1196. my $num_bytes = ord($msg);
  1197. if ($num_bytes < 3) {
  1198. return;
  1199. }
  1200. my $type = $rfxcom_data_array[0];
  1201. my $sensor_id = unpack('H*', chr $type);
  1202. my $key = ($type << 8) + $num_bytes;
  1203. my $rec = $types{$key};
  1204. unless ($rec) {
  1205. Log3 $iohash, 1, "TRX_WEATHER: ERROR: Unknown sensor_id=$sensor_id message='$hexline'";
  1206. return "";
  1207. }
  1208. my $method = $rec->{method};
  1209. unless ($method) {
  1210. Log3 $iohash, 4, "TRX_WEATHER: Possible message from Oregon part '$rec->{part}'";
  1211. Log3 $iohash, 4, "TRX_WEATHER: sensor_id=$sensor_id";
  1212. return;
  1213. }
  1214. my @res;
  1215. if (! defined(&$method)) {
  1216. Log3 $iohash, 4, "TRX_WEATHER: Error: Unknown function=$method. Please define it in file $0";
  1217. Log3 $iohash, 4, "TRX_WEATHER: sensor_id=$sensor_id\n";
  1218. return "";
  1219. } else {
  1220. Log3 $iohash, 5, "TRX_WEATHER: parsing sensor_id=$sensor_id message='$hexline'";
  1221. @res = $method->($rec->{part}, $longids, \@rfxcom_data_array);
  1222. }
  1223. # get device name from first entry
  1224. my $device_name = $res[0]->{device};
  1225. #Log3 $iohash, 5, "device_name=$device_name";
  1226. if (! defined($device_name)) {
  1227. Log3 $iohash, 4, "TRX_WEATHER: error device_name undefined\n";
  1228. return "";
  1229. }
  1230. my $def = $modules{TRX_WEATHER}{defptr}{"$device_name"};
  1231. if(!$def) {
  1232. Log3 $iohash, 3, "TRX_WEATHER: Unknown device $device_name, please define it";
  1233. return "UNDEFINED $device_name TRX_WEATHER $device_name";
  1234. }
  1235. # Use $def->{NAME}, because the device may be renamed:
  1236. my $name = $def->{NAME};
  1237. return "" if(IsIgnored($name));
  1238. my $n = 0;
  1239. my $tm = TimeNow();
  1240. my $i;
  1241. my $val = "";
  1242. my $sensor = "";
  1243. readingsBeginUpdate($def);
  1244. foreach $i (@res){
  1245. #print "!> i=".$i."\n";
  1246. #printf "%s\t",$i->{device};
  1247. if ($i->{type} eq "temp") {
  1248. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name Temperatur ".$i->{current}." ".$i->{units};
  1249. $val .= "T: ".$i->{current}." ";
  1250. $sensor = "temperature";
  1251. readingsBulkUpdate($def, $sensor, $i->{current});
  1252. }
  1253. elsif ($i->{type} eq "temp-bbq") {
  1254. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name Temperature-bbq ".$i->{current}." ".$i->{units};
  1255. $val .= "TB: ".$i->{current}." ";
  1256. $sensor = "temp-bbq";
  1257. readingsBulkUpdate($def, $sensor, $i->{current});
  1258. }
  1259. elsif ($i->{type} eq "temp-food") {
  1260. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name Temperatur-food ".$i->{current}." ".$i->{units};
  1261. $val .= "TF: ".$i->{current}." ";
  1262. $sensor = "temp-food";
  1263. readingsBulkUpdate($def, $sensor, $i->{current});
  1264. }
  1265. elsif ($i->{type} eq "chilltemp") {
  1266. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name windchill ".$i->{current}." ".$i->{units};
  1267. $val .= "CT: ".$i->{current}." ";
  1268. $sensor = "windchill";
  1269. readingsBulkUpdate($def, $sensor, $i->{current});
  1270. }
  1271. elsif ($i->{type} eq "humidity") {
  1272. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name Luftfeuchtigkeit ".$i->{current}.$i->{units};
  1273. $val .= "H: ".$i->{current}." ";
  1274. $sensor = "humidity";
  1275. readingsBulkUpdate($def, $sensor, $i->{current});
  1276. }
  1277. elsif ($i->{type} eq "battery") {
  1278. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name Batterie ".$i->{current};
  1279. my $tmp_battery = $i->{current};
  1280. my @words = split(/\s+/,$i->{current});
  1281. $val .= "BAT: ".$words[0]." "; #use only first word
  1282. $sensor = "battery";
  1283. readingsBulkUpdate($def, $sensor, $i->{current});
  1284. }
  1285. elsif ($i->{type} eq "pressure") {
  1286. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name Luftdruck ".$i->{current}." ".$i->{units}." Vorhersage=".$i->{forecast};
  1287. # do not add it due to problems with hms.gplot
  1288. $val .= "P: ".$i->{current}." ";
  1289. $sensor = "pressure";
  1290. readingsBulkUpdate($def, $sensor, $i->{current});
  1291. $sensor = "forecast";
  1292. readingsBulkUpdate($def, $sensor, $i->{forecast});
  1293. }
  1294. elsif ($i->{type} eq "speed") {
  1295. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name wind_speed ".$i->{current}." wind_avspeed ".$i->{average};
  1296. $val .= "W: ".$i->{current}." ";
  1297. $val .= "WA: ".$i->{average}." ";
  1298. $sensor = "wind_speed";
  1299. readingsBulkUpdate($def, $sensor, $i->{current});
  1300. $sensor = "wind_avspeed";
  1301. readingsBulkUpdate($def, $sensor, $i->{average});
  1302. }
  1303. elsif ($i->{type} eq "direction") {
  1304. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name wind_dir ".$i->{current}." ".$i->{string};
  1305. $val .= "WD: ".$i->{current}." ";
  1306. $val .= "WDN: ".$i->{string}." ";
  1307. $sensor = "wind_dir";
  1308. readingsBulkUpdate($def, $sensor, $i->{current} . " " . $i->{string});
  1309. }
  1310. elsif ($i->{type} eq "rain") {
  1311. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name rain ".$i->{current};
  1312. $val .= "RR: ".$i->{current}." ";
  1313. $sensor = "rain_rate";
  1314. readingsBulkUpdate($def, $sensor, $i->{current});
  1315. }
  1316. elsif ($i->{type} eq "train") {
  1317. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name train ".$i->{current};
  1318. $val .= "TR: ".$i->{current}." ";
  1319. $sensor = "rain_total";
  1320. readingsBulkUpdate($def, $sensor, $i->{current});
  1321. }
  1322. elsif ($i->{type} eq "flip") {
  1323. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name flip ".$i->{current};
  1324. $val .= "F: ".$i->{current}." ";
  1325. $sensor = "rain_flip";
  1326. readingsBulkUpdate($def, $sensor, $i->{current});
  1327. }
  1328. elsif ($i->{type} eq "uv") {
  1329. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name uv_val ".$i->{current}." uv_risk ".$i->{risk};
  1330. $val .= "UV: ".$i->{current}." ";
  1331. $val .= "UVR: ".$i->{risk}." ";
  1332. $sensor = "uv_val";
  1333. readingsBulkUpdate($def, $sensor, $i->{current});
  1334. $sensor = "uv_risk";
  1335. readingsBulkUpdate($def, $sensor, $i->{risk});
  1336. }
  1337. elsif ($i->{type} eq "energy_current") {
  1338. my $energy_current = $i->{current};
  1339. if (defined($def->{scale_current})) {
  1340. $energy_current = $energy_current * $def->{scale_current};
  1341. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name scale_current=".$def->{scale_current};
  1342. }
  1343. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name energy_current=".$energy_current;
  1344. $val .= "ECUR: ".$energy_current." ";
  1345. $sensor = "energy_current";
  1346. #readingsBulkUpdate($def, $sensor, $energy_current." ".$i->{units});
  1347. readingsBulkUpdate($def, $sensor, $energy_current);
  1348. }
  1349. elsif ($i->{type} eq "energy_ch1") {
  1350. my $energy_current = $i->{current};
  1351. if (defined($def->{scale_current})) {
  1352. $energy_current = $energy_current * $def->{scale_current};
  1353. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name energy_ch1 scale_current=".$def->{scale_current};
  1354. }
  1355. Log3 $name, 5, "TRX_WEATHER: device=$device_name CH1 energy_current=$energy_current";
  1356. $val .= "CH1: ".$energy_current." ";
  1357. $sensor = "energy_ch1";
  1358. readingsBulkUpdate($def, $sensor, $energy_current);
  1359. }
  1360. elsif ($i->{type} eq "energy_ch2") {
  1361. my $energy_current = $i->{current};
  1362. if (defined($def->{scale_current})) {
  1363. $energy_current = $energy_current * $def->{scale_current};
  1364. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name energy_ch2 scale_current=".$def->{scale_current};
  1365. }
  1366. Log3 $device_name, 5, "TRX_WEATHER: name=$name device=$device_name CH2 energy_current=$energy_current";
  1367. $val .= "CH2: ".$energy_current." ";
  1368. $sensor = "energy_ch2";
  1369. readingsBulkUpdate($def, $sensor, $energy_current);
  1370. }
  1371. elsif ($i->{type} eq "energy_ch3") {
  1372. my $energy_current = $i->{current};
  1373. if (defined($def->{scale_current})) {
  1374. $energy_current = $energy_current * $def->{scale_current};
  1375. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name energy_ch3 scale_current=".$def->{scale_current};
  1376. }
  1377. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name CH3 energy_current=".$energy_current;
  1378. $val .= "CH3: ".$energy_current." ";
  1379. $sensor = "energy_ch3";
  1380. readingsBulkUpdate($def, $sensor, $energy_current);
  1381. }
  1382. elsif ($i->{type} eq "energy_current_revolt") {
  1383. my $energy_current = $i->{current};
  1384. if (defined($def->{scale_current})) {
  1385. $energy_current = $energy_current * $def->{scale_current};
  1386. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name scale_current=".$def->{scale_current};
  1387. }
  1388. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name energy_current=".$energy_current;
  1389. #$val .= "ECUR: ".$energy_current." ";
  1390. $sensor = "energy_current";
  1391. readingsBulkUpdate($def, $sensor, $energy_current." ".$i->{units});
  1392. }
  1393. elsif ($i->{type} eq "energy_total") {
  1394. my $energy_total = $i->{current};
  1395. if (defined($def->{scale_total}) && defined($def->{add_total})) {
  1396. $energy_total = sprintf("%.4f",$energy_total * $def->{scale_total} + $def->{add_total});
  1397. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name energy_total scale_total=".$def->{scale_total};
  1398. }
  1399. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name energy_total=$energy_total";
  1400. $val .= "ESUM: ".$energy_total." ";
  1401. $sensor = "energy_total";
  1402. #readingsBulkUpdate($def, $sensor, $energy_total." ".$i->{units});
  1403. readingsBulkUpdate($def, $sensor, $energy_total);
  1404. }
  1405. elsif ($i->{type} eq "energy_power") {
  1406. my $energy_power = $i->{current};
  1407. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name energy_power=$energy_power";
  1408. $val .= "EPOW: ".$energy_power." ";
  1409. $sensor = "energy_power";
  1410. readingsBulkUpdate($def, $sensor, $energy_power." ".$i->{units});
  1411. }
  1412. elsif ($i->{type} eq "energy_voltage") {
  1413. my $energy_voltage = $i->{current};
  1414. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name energy_voltage=$energy_voltage";
  1415. #$val .= "V: ".$energy_voltage." ";
  1416. $sensor = "voltage";
  1417. readingsBulkUpdate($def, $sensor, $energy_voltage." ".$i->{units});
  1418. }
  1419. elsif ($i->{type} eq "energy_pf") {
  1420. my $energy_pf = $i->{current};
  1421. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name energy_pf=$energy_pf";
  1422. #$val .= "PF: ".$energy_pf." ";
  1423. $sensor = "energy_pf";
  1424. readingsBulkUpdate($def, $sensor, $energy_pf." ".$i->{units});
  1425. }
  1426. elsif ($i->{type} eq "energy_freq") {
  1427. my $energy_freq = $i->{current};
  1428. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name energy_freq=$energy_freq";
  1429. #$val .= "FREQ: ".$energy_freq." ";
  1430. $sensor = "frequency";
  1431. readingsBulkUpdate($def, $sensor, $energy_freq." ".$i->{units});
  1432. }
  1433. elsif ($i->{type} eq "weight") {
  1434. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name weight ".$i->{current};
  1435. $val .= "W: ".$i->{current}." ";
  1436. $sensor = "weight";
  1437. readingsBulkUpdate($def, $sensor, $i->{current});
  1438. }
  1439. elsif ($i->{type} eq "hexline") {
  1440. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name hexline ".$i->{current};
  1441. $sensor = "hexline";
  1442. readingsBulkUpdate($def, $sensor, $i->{current});
  1443. }
  1444. elsif ($i->{type} eq "rssi") {
  1445. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name rssi ".$i->{current};
  1446. $sensor = "rssi";
  1447. readingsBulkUpdate($def, $sensor, $i->{current});
  1448. }
  1449. elsif ($i->{type} eq "date") {
  1450. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name date ".$i->{current};
  1451. $val .= $i->{current}." ";
  1452. $sensor = "date";
  1453. readingsBulkUpdate($def, $sensor, $i->{current});
  1454. }
  1455. elsif ($i->{type} eq "time") {
  1456. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name time ".$i->{current};
  1457. $val .= $i->{current}." ";
  1458. $sensor = "time";
  1459. readingsBulkUpdate($def, $sensor, $i->{current});
  1460. }
  1461. elsif ($i->{type} eq "setpoint") {
  1462. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name setpoint ".$i->{current}." ".$i->{units};
  1463. $val .= "SP: ".$i->{current}." ";
  1464. $sensor = "setpoint";
  1465. readingsBulkUpdate($def, $sensor, $i->{current});
  1466. }
  1467. elsif ($i->{type} eq "demand") {
  1468. Log3 $name, 5, "TRX_WEATHER: name=$name device=$device_name state ".$i->{current};
  1469. if ($val eq "") {
  1470. $val = "$i->{current}";
  1471. }
  1472. else {
  1473. $val .= "D: ".$i->{current}." ";
  1474. }
  1475. $sensor = "demand";
  1476. readingsBulkUpdate($def, $sensor, $i->{current});
  1477. }
  1478. else {
  1479. Log3 $name, 1, "TRX_WEATHER: name=$name device=$device_name UNKNOWN Type: ".$i->{type}." Value: ".$i->{current}
  1480. }
  1481. }
  1482. if ("$val" ne "") {
  1483. # remove heading and trailing space chars from $val
  1484. $val =~ s/^\s+|\s+$//g;
  1485. #$def->{STATE} = $val;
  1486. readingsBulkUpdate($def, "state", $val);
  1487. }
  1488. readingsEndUpdate($def, 1);
  1489. return $name;
  1490. }
  1491. 1;
  1492. =pod
  1493. =begin html
  1494. <a name="TRX_WEATHER"></a>
  1495. <h3>TRX_WEATHER</h3>
  1496. <ul>
  1497. The TRX_WEATHER module interprets weather sensor messages received by a RTXtrx receiver. See <a href="http://www.rfxcom.com/oregon.htm">http://www.rfxcom.com/oregon.htm</a> for a list of
  1498. Oregon Scientific weather sensors that could be received by the RFXtrx433 tranmitter. You need to define a RFXtrx433 receiver first. See
  1499. See <a href="#TRX">TRX</a>.
  1500. <br><br>
  1501. <a name="TRX_WEATHERdefine"></a>
  1502. <b>Define</b>
  1503. <ul>
  1504. <code>define &lt;name&gt; TRX_WEATHER &lt;deviceid&gt;</code> <br>
  1505. <br>
  1506. <code>&lt;deviceid&gt;</code>
  1507. <ul>
  1508. is the device identifier of the sensor. It consists of the sensors name and (only if the attribute longids is set of the RFXtrx433) an a one byte hex string (00-ff) that identifies the sensor. If an sensor uses an switch to set an additional is then this is also added. The define statement with the deviceid is generated automatically by autocreate. The following sensor names are used: <br>
  1509. "THR128" (for THR128/138, THC138),<br>
  1510. "THGR132N" (for THC238/268,THN132,THWR288,THRN122,THN122,AW129/131),<br>
  1511. "THWR800", <br>
  1512. "RTHN318", <br>
  1513. "TX3_T" (for LaCrosse TX3, TX4, TX17),<br>
  1514. "THGR228N" (for THGN122/123, THGN132, THGR122/228/238/268),<br>
  1515. "THGR810",<br>
  1516. "RTGR328",<br>
  1517. "THGR328",<br>
  1518. "WTGR800_T" (for temperature of WTGR800),<br>
  1519. "THGR918" (for THGR918, THGRN228, THGN500),<br>
  1520. "TFATS34C" (for TFA TS34C),<br>
  1521. "BTHR918",<br>
  1522. "BTHR918N (for BTHR918N, BTHR968),<br>
  1523. "RGR918" (for RGR126/682/918),<br>
  1524. "PCR800",<br>
  1525. "TFA_RAIN" (for TFA rain sensor),<br>
  1526. "WTGR800_A" (for wind sensor of WTGR800),<br>
  1527. "WGR800" (for wind sensor of WGR800),<br>
  1528. "WGR918" (for wind sensor of STR918 and WGR918),<br>
  1529. "TFA_WIND" (for TFA wind sensor),<br>
  1530. "BWR101" (for Oregon Scientific BWR101),<br>
  1531. "GR101" (for Oregon Scientific GR101)
  1532. "TLX7506" (for Digimax TLX7506),<br>
  1533. "TH10" (for Digimax with short format),<br>
  1534. </ul>
  1535. <br>
  1536. Example: <br>
  1537. <ul>
  1538. <code>define Tempsensor TRX_WEATHER TX3_T</code><br>
  1539. <code>define Tempsensor3 TRX_WEATHER THR128_3</code><br>
  1540. <code>define Windsensor TRX_WEATHER WGR918_A</code><br>
  1541. <code>define Regensensor TRX_WEATHER RGR918</code><br>
  1542. </ul>
  1543. </ul>
  1544. <br><br>
  1545. <ul>
  1546. <code>define &lt;name&gt; TRX_WEATHER &lt;deviceid&gt; [&lt;scale_current&gt; &lt;scale_total&gt; &lt;add_total&gt;]</code> <br>
  1547. <br>
  1548. <code>&lt;deviceid&gt;</code>
  1549. <ul>
  1550. is the device identifier of the energy sensor. It consists of the sensors name and (only if the attribute longids is set of the RFXtrx433) an a two byte hex string (0000-ffff) that identifies the sensor. The define statement with the deviceid is generated automatically by autocreate. The following sensor names are used: <br>
  1551. "CM160" (for OWL CM119 or CM160),<br>
  1552. "CM180" (for OWL CM180),<br><br>
  1553. "CM180i"(for OWL CM180i),<br><br>
  1554. </ul>
  1555. The following Readings are generated:<br>
  1556. <ul>
  1557. <code>"energy_current:"</code>:
  1558. <ul>
  1559. Only for CM160 and CM180: current usage in Watt. If &lt;scale_current&gt is defined the result is: <code>energy_current * &lt;scale_current&gt;</code>.
  1560. </ul>
  1561. <code>"energy_chx:"</code>:
  1562. <ul>
  1563. Only for CM180i (where chx is ch1, ch2 or ch3): current usage in Ampere. If &lt;scale_current&gt is defined the result is: <code>energy_chx * &lt;scale_current&gt;</code>.
  1564. </ul>
  1565. <code>"energy_total:"</code>:
  1566. <ul>
  1567. current usage in kWh. If scale_total and add_total is defined the result is: <code>energy_total * &lt;scale_total&gt; + &lt;add_total&gt;</code>.
  1568. </ul>
  1569. <br>
  1570. </ul>
  1571. Example: <br>
  1572. <ul>
  1573. <code>define Tempsensor TRX_WEATHER CM160_1401</code><br>
  1574. <code>define Tempsensor TRX_WEATHER CM180_1401 1 1 0</code><br>
  1575. <code>define Tempsensor TRX_WEATHER CM180_1401 0.9 0.9 -1000</code><br>
  1576. </ul>
  1577. </ul>
  1578. <br>
  1579. <a name="TRX_WEATHERset"></a>
  1580. <b>Set</b> <ul>N/A</ul><br>
  1581. <a name="TRX_WEATHERget"></a>
  1582. <b>Get</b> <ul>N/A</ul><br>
  1583. <a name="TRX_WEATHERattr"></a>
  1584. <b>Attributes</b>
  1585. <ul>
  1586. <li><a href="#ignore">ignore</a></li>
  1587. <li><a href="#do_not_notify">do_not_notify</a></li>
  1588. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  1589. </ul>
  1590. <br>
  1591. </ul>
  1592. =end html
  1593. =cut