forked from playwithfree/FHEMmodules
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path46_TRX_WEATHER.pm
1898 lines (1595 loc) · 52.5 KB
/
46_TRX_WEATHER.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# $Id: 46_TRX_WEATHER.pm 10798 2016-02-11 22:29:43Z wherzig - modified oliv06$
##############################################################################
#
# 46_TRX_WEATHER.pm
# FHEM module to decode weather sensor messages for RFXtrx
#
# The following devices are implemented to be received:
#
# thermostats (THERMOSTAT):
# * "TH10" is XDOM TH10
# * "TLX7506" is Digimax TLX7506
# temperature sensors (TEMP):
# * "THR128" is THR128/138, THC138
# * "THGR132N" is THC238/268,THN132,THWR288,THRN122,THN122,AW129/131
# * "THWR800" is THWR800
# * "RTHN318" is RTHN318
# * "TX3_T" is LaCrosse TX3, TX4, TX17
# * "TS15C" is TS15C
# * "VIKING_02811" is Viking 02811
# * "WS2300" is La Crosse WS2300
# * "RUBICSON" is RUBiCSON
# * "TFA_303133" is TFA 30.3133
# * "WT0122" is WT0122 pool sensor
#
# humidity sensors (HYDRO):
# * "TX3" is LaCrosse TX3
# * "WS2300" is LaCrosse WS2300
# * "S80" is Inovalley S80 plant humidity sensor
#
# temperature/humidity sensors (TEMPHYDRO):
# * "THGR228N" is THGN122/123, THGN132, THGR122/228/238/268
# * "THGR810" is THGR810
# * "RTGR328" is RTGR328
# * "THGR328" is THGR328
# * "WTGR800_T" is WTGR800
# * "THGR918" is THGR918, THGRN228, THGN500
# * "TFATS34C" is TFA TS34C, Cresta
# * "WT450H" is WT260,WT260H,WT440H,WT450,WT450H
# * "VIKING_02038" is Viking 02035,02038 (02035 has no humidity)
# * "RUBICSON" is Rubicson
# * "EW109" is EW109
# * "XT300" is Imagintronix/Opus XT300 Soil sensor
# * "WS1700" is Alecto WS1700 and compatibles
# * "WS3500" is Alecto WS3500, WS4500, Auriol H13726, Hama EWS1500, Meteoscan W155/W160, Ventus WS155
#
# temperature/humidity/pressure sensors (TEMPHYDROBARO):
# * "BTHR918" is BTHR918
# * "BTHR918N" is BTHR918N, BTHR968
#
# rain gauge sensors (RAIN):
# * "RGR918" is RGR126/682/918
# * "PCR800" is PCR800
# * "TFA_RAIN" is TFA
# * "RG700" is UPM RG700
# * "WS2300_RAIN" is WS2300
# * "TX5_RAIN" is La Crosse TX5
# * "WS4500_RAIN" is Alecto WS4500, Auriol H13726, Hama EWS1500, Meteoscan W155/W160,
#
# wind sensors (WIND):
# * "WTGR800_A" is WTGR800
# * "WGR800_A" is WGR800
# * "WGR918" is STR918, WGR918
# * "TFA_WIND" is TFA
# * "WDS500" is UPM WDS500u
# * "WS2300_WIND" is WS2300
# * "WS4500_WIND" is Alecto WS4500, Auriol H13726, Hama EWS1500, Meteoscan W155/W160, Ventus WS155
#
# UV Sensors:
# * "UVN128" is Oregon UVN128, UV138
# * "UVN800" is Oregon UVN800
# * "TFA_UV" is TFA_UV-Sensor
#
# Date/Time Sensors:
# * "RTGR328_DATE" is RTGR328N
#
# Energy Sensors:
# * "CM160" is OWL CM119, CM160
# * "CM180" is OWL CM180
# * "REVOLT" is Revolt
#
# Weighing scales (WEIGHT):
# * "BWR101" is Oregon Scientific BWR101
# * "GR101" is Oregon Scientific GR101
#
# BBQ-Sensors (two temperature values):
# * "ET732" is Maverick ET-732
#
# Copyright (C) 2012/2013 Willi Herzig
#
# This script is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# Due to RFXCOM SDK requirements this code may only be used with a RFXCOM device.
#
# Some code was derived and modified from xpl-perl
# from the following two files:
# xpl-perl/lib/xPL/Utils.pm:
# xpl-perl/lib/xPL/RF/Oregon.pm:
#
#SEE ALSO
# Project website: http://www.xpl-perl.org.uk/
# AUTHOR: Mark Hindess, [email protected]
#
# Copyright (C) 2007, 2009 by Mark Hindess
#
# This library is free software; you can redistribute it and/or modify
# it under the same terms as Perl itself, either Perl version 5.8.7 or,
# at your option, any later version of Perl 5 you may have available.
##################################
#
# values for "set global verbose"
# 4: log unknown prologtocols
# 5: log decoding hexlines for debugging
#
package main;
use strict;
use warnings;
# Hex-Debugging into READING hexline? YES = 1, NO = 0
my $TRX_HEX_debug = 0;
# Max temperatute für Maverick BBQ
my $TRX_MAX_TEMP_BBQ = 1000;
my $time_old = 0;
my $trx_rssi;
sub
TRX_WEATHER_Initialize($)
{
my ($hash) = @_;
$hash->{Match} = "^..(40|4e|50|51|52|54|55|56|57|58|5a|5c|5d).*";
$hash->{DefFn} = "TRX_WEATHER_Define";
$hash->{UndefFn} = "TRX_WEATHER_Undef";
$hash->{ParseFn} = "TRX_WEATHER_Parse";
$hash->{AttrList} = "IODev ignore:1,0 do_not_notify:1,0 ".
$readingFnAttributes;
}
#####################################
sub
TRX_WEATHER_Define($$)
{
my ($hash, $def) = @_;
my @a = split("[ \t][ \t]*", $def);
#my $a = int(@a);
#print "a0 = $a[0]";
return "wrong syntax: define <name> TRX_WEATHER code" if (int(@a) < 3);
my $name = $a[0];
my $code = $a[2];
if (($code =~ /^CM160/) || ($code =~ /^CM180/) || ($code =~ /^REVOLT/)) {
return "wrong syntax: define <name> TRX_WEATHER code [scale_current scale_total add_total]" if (int(@a) != 3 && int(@a) != 6);
$hash->{scale_current} = ((int(@a) == 6) ? $a[3] : 1);
$hash->{scale_total} = ((int(@a) == 6) ? $a[4] : 1.0);
$hash->{add_total} = ((int(@a) == 6) ? $a[5] : 0.0);
} else {
return "wrong syntax: define <name> TRX_WEATHER code" if(int(@a) > 3);
}
$hash->{CODE} = $code;
$modules{TRX_WEATHER}{defptr}{$code} = $hash;
AssignIoPort($hash);
return undef;
}
#####################################
sub
TRX_WEATHER_Undef($$)
{
my ($hash, $name) = @_;
delete($modules{TRX_WEATHER}{defptr}{$name});
return undef;
}
# --------------------------------------------
# sensor types
my %types =
(
# THERMOSTAT
0x4009 => { part => 'THERMOSTAT', method => \&TRX_WEATHER_common_therm, },
# BBQ
0x4e0a => { part => 'BBQ', method => \&TRX_WEATHER_common_bbq, },
# TEMP
0x5008 => { part => 'TEMP', method => \&TRX_WEATHER_common_temp, },
# HYDRO
0x5108 => { part => 'HYDRO', method => \&TRX_WEATHER_common_hydro, },
# TEMP HYDRO
0x520a => { part => 'TEMPHYDRO', method => \&TRX_WEATHER_common_temphydro, },
# TEMP HYDRO BARO
0x540d => { part => 'TEMPHYDROBARO', method => \&TRX_WEATHER_common_temphydrobaro, },
# RAIN
0x550b => { part => 'RAIN', method => \&TRX_WEATHER_common_rain, },
# WIND
0x5610 => { part => 'WIND', method => \&TRX_WEATHER_common_anemometer, },
# UV
0x5709 => { part => 'UV', method => \&TRX_WEATHER_common_uv, },
# Date/Time sensors
0x580D => { part => 'DATE', method => \&TRX_WEATHER_common_datetime, },
# Energy usage sensors
0x5A11 => { part => 'ENERGY', method => \&TRX_WEATHER_common_energy, },
0x5B13 => { part => 'ENERGY2', method => \&TRX_WEATHER_common_energy2, },
0x5c0f => { part => 'ENERGY3', method => \&TRX_WEATHER_common_energy3, },
# WEIGHT
0x5D08 => { part => 'WEIGHT', method => \&TRX_WEATHER_common_weight, },
);
# --------------------------------------------
#my $DOT = q{.};
# Important: change it to _, because FHEM uses regexp
my $DOT = q{_};
my @TRX_WEATHER_winddir_name=("N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW");
# --------------------------------------------
# The following functions are changed:
# - some parameter like "parent" and others are removed
# - @res array return the values directly (no usage of xPL::Message)
sub TRX_WEATHER_temperature {
my ($bytes, $dev, $res, $off) = @_;
my $temp =
(
(($bytes->[$off] & 0x80) ? -1 : 1) *
(($bytes->[$off] & 0x7f)*256 + $bytes->[$off+1])
)/10;
push @$res, {
device => $dev,
type => 'temp',
current => $temp,
units => 'Grad Celsius'
}
}
sub TRX_WEATHER_temperature_food {
my ($bytes, $dev, $res, $off) = @_;
my $temp = $bytes->[$off]*256 + $bytes->[$off+1];
return if ($temp > $TRX_MAX_TEMP_BBQ);
push @$res, {
device => $dev,
type => 'temp-food',
current => $temp,
units => 'Grad Celsius'
}
}
sub TRX_WEATHER_temperature_bbq {
my ($bytes, $dev, $res, $off) = @_;
my $temp = $bytes->[$off]*256 + $bytes->[$off+1];
return if ($temp > $TRX_MAX_TEMP_BBQ);
push @$res, {
device => $dev,
type => 'temp-bbq',
current => $temp,
units => 'Grad Celsius'
}
}
sub TRX_WEATHER_chill_temperature {
my ($bytes, $dev, $res, $off) = @_;
my $temp =
(
(($bytes->[$off] & 0x80) ? -1 : 1) *
(($bytes->[$off] & 0x7f)*256 + $bytes->[$off+1])
)/10;
push @$res, {
device => $dev,
type => 'chilltemp',
current => $temp,
units => 'Grad Celsius'
}
}
sub TRX_WEATHER_humidity {
my ($bytes, $dev, $res, $off) = @_;
my $hum = $bytes->[$off];
my $hum_str = ['dry', 'comfortable', 'normal', 'wet']->[$bytes->[$off+1]];
push @$res, {
device => $dev,
type => 'humidity',
current => $hum,
string => $hum_str,
units => '%'
}
}
sub TRX_WEATHER_pressure {
my ($bytes, $dev, $res, $off) = @_;
#my $offset = 795 unless ($offset);
my $hpa = ($bytes->[$off])*256 + $bytes->[$off+1];
my $forecast = { 0x00 => 'noforecast',
0x01 => 'sunny',
0x02 => 'partly',
0x03 => 'cloudy',
0x04 => 'rain',
}->{$bytes->[$off+2]} || 'unknown';
push @$res, {
device => $dev,
type => 'pressure',
current => $hpa,
units => 'hPa',
forecast => $forecast,
};
}
sub TRX_WEATHER_simple_battery {
my ($bytes, $dev, $res, $off) = @_;
my $battery;
my $battery_level = $bytes->[$off] & 0x0f;
if ($battery_level == 0x9) { $battery = 'ok'}
elsif ($battery_level == 0x0) { $battery = 'low'}
else {
$battery = sprintf("unknown-%02x",$battery_level);
}
push @$res, {
device => $dev,
type => 'battery',
current => $battery,
};
my $rssi = ($bytes->[$off] & 0xf0) >> 4;
if ($trx_rssi == 1) {
push @$res, {
device => $dev,
type => 'rssi',
current => sprintf("%d",$rssi),
};
}
}
sub TRX_WEATHER_battery {
my ($bytes, $dev, $res, $off) = @_;
my $battery;
my $battery_level = ($bytes->[$off] & 0x0f) + 1;
if ($battery_level > 5) {
$battery = sprintf("ok %d0%%",$battery_level);
} else {
$battery = sprintf("low %d0%%",$battery_level);
}
push @$res, {
device => $dev,
type => 'battery',
current => $battery,
};
my $rssi = ($bytes->[$off] & 0xf0) >> 4;
if ($trx_rssi == 1) {
push @$res, {
device => $dev,
type => 'rssi',
current => sprintf("%d",$rssi),
};
}
}
# Test if to use longid for device type
sub TRX_WEATHER_use_longid {
my ($longids,$dev_type) = @_;
return 0 if ($longids eq "");
return 0 if ($longids eq "0");
return 1 if ($longids eq "1");
return 1 if ($longids eq "ALL");
return 1 if(",$longids," =~ m/,$dev_type,/);
return 0;
}
# ------------------------------------------------------------
# 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
# 0x5610 => { part => 'WIND'
sub TRX_WEATHER_common_anemometer {
my $type = shift;
my $longids = shift;
my $bytes = shift;
my $subtype = sprintf "%02x", $bytes->[1];
my $dev_type;
my %devname =
( # HEXSTRING => "NAME"
0x01 => "WTGR800_A",
0x02 => "WGR800",
0x03 => "WGR918",
0x04 => "TFA_WIND",
0x05 => "WDS500", # UPM WDS500
0x06 => "WS2300_WIND", # WS2300
0x07 => "WS4500_WIND", # Alecto WS4500, Auriol H13726, Hama EWS1500, Meteoscan W155/W160, Ventus WS155
);
if (exists $devname{$bytes->[1]}) {
$dev_type = $devname{$bytes->[1]};
} else {
Log3 undef, 3, "TRX_WEATHER: common_anemometer error undefined subtype=$subtype";
my @res = ();
return @res;
}
my $dev_str = $dev_type;
if (TRX_WEATHER_use_longid($longids,$dev_type)) {
$dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
}
if ($bytes->[4] > 0) {
$dev_str .= $DOT.sprintf("%d", $bytes->[4]);
}
my @res = ();
# hexline debugging
if ($TRX_HEX_debug) {
my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
}
my $dir = $bytes->[5]*256 + $bytes->[6];
my $dirname = $TRX_WEATHER_winddir_name[int((($dir + 11.25) % 360) / 22.5)];
my $avspeed = ($bytes->[7]*256 + $bytes->[8]) / 10;
my $speed = ($bytes->[9]*256 + $bytes->[10]) / 10;
if ($dev_type eq "TFA_WIND") {
TRX_WEATHER_temperature($bytes, $dev_str, \@res, 11);
TRX_WEATHER_chill_temperature($bytes, $dev_str, \@res, 13);
}
push @res, {
device => $dev_str,
type => 'speed',
current => $speed,
average => $avspeed,
units => 'mps',
} , {
device => $dev_str,
type => 'direction',
current => $dir,
string => $dirname,
units => 'degrees',
};
TRX_WEATHER_battery($bytes, $dev_str, \@res, 15);
return @res;
}
# --------------------------------------------------------------------
# T R X _ W E A T H E R _ c o m m o n _ b b q
# 0x4e0a => { part => 'BBQ'
#
sub TRX_WEATHER_common_bbq {
my $type = shift;
my $longids = shift;
my $bytes = shift;
my $subtype = sprintf "%02x", $bytes->[1];
my $dev_type;
my %devname =
( # HEXSTRING => "NAME"
0x01 => "ET732",
);
if (exists $devname{$bytes->[1]}) {
$dev_type = $devname{$bytes->[1]};
} else {
Log3 undef, 3, "TRX_WEATHER: common_bbq error undefined subtype=$subtype";
my @res = ();
return @res;
}
#my $seqnbr = sprintf "%02x", $bytes->[2];
my $dev_str = $dev_type;
if (TRX_WEATHER_use_longid($longids,$dev_type)) {
$dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
$dev_str .= $DOT.sprintf("%02x", $bytes->[4]);
}
my @res = ();
# hexline debugging
if ($TRX_HEX_debug) {
my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
}
TRX_WEATHER_temperature_food($bytes, $dev_str, \@res, 5);
TRX_WEATHER_temperature_bbq($bytes, $dev_str, \@res, 7);
TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 9);
return @res;
}
# -----------------------------
sub TRX_WEATHER_common_therm {
my $type = shift;
my $longids = shift;
my $bytes = shift;
my $subtype = sprintf "%02x", $bytes->[1];
my $dev_type;
my %devname =
( # HEXSTRING => "NAME"
0x00 => "TLX7506",
0x01 => "TH10",
);
if (exists $devname{$bytes->[1]}) {
$dev_type = $devname{$bytes->[1]};
} else {
Log3 undef, 3, "TRX_WEATHER: common_therm error undefined subtype=$subtype";
my @res = ();
return @res;
}
#my $seqnbr = sprintf "%02x", $bytes->[2];
my $dev_str = $dev_type;
if (TRX_WEATHER_use_longid($longids,$dev_type)) {
$dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
}
if ($bytes->[4] > 0) {
$dev_str .= $DOT.sprintf("%d", $bytes->[4]);
}
my @res = ();
# hexline debugging
if ($TRX_HEX_debug) {
my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
}
#TRX_WEATHER_temperature($bytes, $dev_str, \@res, 5);
#TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 7);
my $temp = ($bytes->[5]);
if ($temp) {
push @res, {
device => $dev_str,
type => 'temp',
current => $temp,
units => 'Grad Celsius'
}
}
my $setpoint =($bytes->[6]);
if ($setpoint) {
push @res, {
device => $dev_str,
type => 'setpoint',
current => $setpoint,
units => 'Grad Celsius'
}
}
my $demand;
my $t_status = ($bytes->[7] & 0x03);
if ($t_status == 0) { $demand = 'n/a'}
elsif ($t_status == 1) { $demand = 'on'}
elsif ($t_status == 2) { $demand = 'off'}
elsif ($t_status == 3) { $demand = 'initializing'}
else {
$demand = sprintf("unknown-%02x",$t_status);
}
Log3 undef, 5, "TRX_WEATHER: demand = $bytes->[7] $t_status $demand";
push @res, {
device => $dev_str,
type => 'demand',
current => sprintf("%s",$demand),
};
#my $t_mode = ($bytes->[7] & 0x01);
my $rssi = ($bytes->[8] & 0xf0) >> 4;
if ($trx_rssi == 1) {
push @res, {
device => $dev_str,
type => 'rssi',
current => sprintf("%d",$rssi),
};
}
return @res;
}
# --------------------------------------------------------------------
# T R X _ W E A T H E R _ c o m m o n _ t e m p
# 0x5008 => { part => 'TEMP'
sub TRX_WEATHER_common_temp {
my $type = shift;
my $longids = shift;
my $bytes = shift;
my $subtype = sprintf "%02x", $bytes->[1];
my $dev_type;
my %devname =
( # HEXSTRING => "NAME"
0x01 => "THR128",
0x02 => "THGR132N", # was THGR228N,
0x03 => "THWR800",
0x04 => "RTHN318",
0x05 => "TX3", # LaCrosse TX3
0x06 => "TS15C",
0x07 => "VIKING_02811", # Viking 02811
0x08 => "WS2300", # La Crosse WS2300
0x09 => "RUBICSON", # RUBiCSON
0x0a => "TFA_303133", # TFA 30.3133
0x0b => "WT0122", # WT0122
);
if (exists $devname{$bytes->[1]}) {
$dev_type = $devname{$bytes->[1]};
} else {
Log3 undef, 3, "TRX_WEATHER: common_temp error undefined subtype=$subtype";
my @res = ();
return @res;
}
#my $seqnbr = sprintf "%02x", $bytes->[2];
my $dev_str = $dev_type;
if (TRX_WEATHER_use_longid($longids,$dev_type)) {
$dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
}
if ($bytes->[4] > 0) {
$dev_str .= $DOT.sprintf("%d", $bytes->[4]);
}
my @res = ();
# hexline debugging
if ($TRX_HEX_debug) {
my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
}
TRX_WEATHER_temperature($bytes, $dev_str, \@res, 5);
TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 7);
return @res;
}
# --------------------------------------------------------------------
# T R X _ W E A T H E R _ c o m m o n _ h y d r o
# 0x5108 => { part => 'HYDRO'
sub TRX_WEATHER_common_hydro {
my $type = shift;
my $longids = shift;
my $bytes = shift;
my $subtype = sprintf "%02x", $bytes->[1];
my $dev_type;
my %devname =
( # HEXSTRING => "NAME"
0x01 => "TX3", # LaCrosse TX3
0x02 => "WS2300", # LaCrosse WS2300 Humidity
0x03 => "S80", # Inovalley S80 plant humidity sensor
);
if (exists $devname{$bytes->[1]}) {
$dev_type = $devname{$bytes->[1]};
} else {
Log3 undef, 3, "TRX_WEATHER: common_hydro error undefined subtype=$subtype";
my @res = ();
return @res;
}
my $dev_str = $dev_type;
if (TRX_WEATHER_use_longid($longids,$dev_type)) {
$dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
}
if ($bytes->[4] > 0) {
$dev_str .= $DOT.sprintf("%d", $bytes->[4]);
}
my @res = ();
# hexline debugging
if ($TRX_HEX_debug) {
my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
}
TRX_WEATHER_humidity($bytes, $dev_str, \@res, 5);
TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 7);
return @res;
}
# --------------------------------------------------------------------
# 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
# 0x520a => { part => 'TEMPHYDRO'
sub TRX_WEATHER_common_temphydro {
my $type = shift;
my $longids = shift;
my $bytes = shift;
my $subtype = sprintf "%02x", $bytes->[1];
my $dev_type;
my %devname =
( # HEXSTRING => "NAME"
0x01 => "THGR228N", # THGN122/123, THGN132, THGR122/228/238/268
0x02 => "THGR810",
0x03 => "RTGR328",
0x04 => "THGR328",
0x05 => "WTGR800_T",
0x06 => "THGR918",
0x07 => "TFATS34C",
0x08 => "WT450H", # WT260,WT260H,WT440H,WT450,WT450H
0x09 => "VIKING_02038", # Viking 02035,02038 (02035 has no humidity)
0x0a => "RUBICSON", # Rubicson
0x0b => "EW109", # EW109
0x0c => "XT300", # Imagintronix/Opus XT300 Soil sensor
0x0d => "WS1700", # Alecto WS1700 and compatibles
0x0e => "WS3500", # Alecto WS3500, WS4500, Auriol H13726, Hama EWS1500, Meteoscan W155/W160, Ventus WS155
);
if (exists $devname{$bytes->[1]}) {
$dev_type = $devname{$bytes->[1]};
} else {
Log3 undef, 3, "TRX_WEATHER: common_temphydro error undefined subtype=$subtype";
my @res = ();
return @res;
}
my $dev_str = $dev_type;
if (TRX_WEATHER_use_longid($longids,$dev_type)) {
$dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
} elsif ($dev_type eq "TFATS34C") {
#Log3 undef, 1,"TRX_WEATHER: TFA";
if ($bytes->[3] > 0x20 && $bytes->[3] <= 0x3F) {
#Log3 undef, 1,"TRX_WEATHER: TFA 1";
$dev_str .= $DOT."1";
} elsif ($bytes->[3] >= 0x40 && $bytes->[3] <= 0x5F) {
#Log3 undef, 1,"TRX_WEATHER: TFA 2";
$dev_str .= $DOT."2";
} elsif ($bytes->[3] >= 0x60 && $bytes->[3] <= 0x7F) {
#Log3 undef, 1,"TRX_WEATHER: TFA 3";
$dev_str .= $DOT."3";
} elsif ($bytes->[3] >= 0xA0 && $bytes->[3] <= 0xBF) {
#Log3 undef, 1,"TRX_WEATHER: TFA 4";
$dev_str .= $DOT."4";
} elsif ($bytes->[3] >= 0xC0 && $bytes->[3] <= 0xDF) {
#Log3 undef, 1,"TRX_WEATHER: TFA 5";
$dev_str .= $DOT."5";
} else {
#Log3 undef, 1,"TRX_WEATHER: TFA 9";
$dev_str .= $DOT."9";
}
}
if ($dev_type ne "TFATS34C" && $bytes->[4] > 0) {
$dev_str .= $DOT.sprintf("%d", $bytes->[4]);
}
my @res = ();
# hexline debugging
if ($TRX_HEX_debug) {
my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
}
TRX_WEATHER_temperature($bytes, $dev_str, \@res, 5);
TRX_WEATHER_humidity($bytes, $dev_str, \@res, 7);
if ($dev_type eq "THGR918") {
TRX_WEATHER_battery($bytes, $dev_str, \@res, 9);
} else {
TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 9);
}
return @res;
}
# --------------------------------------------------------------------
# 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
# 0x540d => { part => 'TEMPHYDROBARO'
sub TRX_WEATHER_common_temphydrobaro {
my $type = shift;
my $longids = shift;
my $bytes = shift;
my $subtype = sprintf "%02x", $bytes->[1];
my $dev_type;
my %devname =
( # HEXSTRING => "NAME"
0x01 => "BTHR918",
0x02 => "BTHR918N",
);
if (exists $devname{$bytes->[1]}) {
$dev_type = $devname{$bytes->[1]};
} else {
Log3 undef, 3, "TRX_WEATHER: common_temphydrobaro error undefined subtype=$subtype";
my @res = ();
return @res;
}
my $dev_str = $dev_type;
if (TRX_WEATHER_use_longid($longids,$dev_type)) {
$dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
}
if ($bytes->[4] > 0) {
$dev_str .= $DOT.sprintf("%d", $bytes->[4]);
}
my @res = ();
# hexline debugging
if ($TRX_HEX_debug) {
my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
}
TRX_WEATHER_temperature($bytes, $dev_str, \@res, 5);
TRX_WEATHER_humidity($bytes, $dev_str, \@res, 7);
TRX_WEATHER_pressure($bytes, $dev_str, \@res, 9);
TRX_WEATHER_simple_battery($bytes, $dev_str, \@res, 12);
return @res;
}
# --------------------------------------------------------------------
# T R X _ W E A T H E R _ c o m m o n _ r a i n
# 0x550b => { part => 'RAIN'
sub TRX_WEATHER_common_rain {
my $type = shift;
my $longids = shift;
my $bytes = shift;
my $subtype = sprintf "%02x", $bytes->[1];
my $dev_type;
my %devname =
( # HEXSTRING => "NAME"
0x01 => "RGR918",
0x02 => "PCR800",
0x03 => "TFA_RAIN",
0x04 => "RG700",
0x05 => "WS2300_RAIN", # WS2300
0x06 => "TX5_RAIN", # La Crosse TX5
0x07 => "WS4500_RAIN", # Alecto WS4500, Auriol H13726, Hama EWS1500, Meteoscan W155/W160,
);
if (exists $devname{$bytes->[1]}) {
$dev_type = $devname{$bytes->[1]};
} else {
Log3 undef, 3, "TRX_WEATHER: common_rain error undefined subtype=$subtype";
my @res = ();
return @res;
}
my $dev_str = $dev_type;
if (TRX_WEATHER_use_longid($longids,$dev_type)) {
$dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
}
if ($bytes->[4] > 0) {
$dev_str .= $DOT.sprintf("%d", $bytes->[4]);
}
my @res = ();
# hexline debugging
if ($TRX_HEX_debug) {
my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
}
my $rain = $bytes->[5]*256 + $bytes->[6];
if ($dev_type eq "RGR918") {
push @res, {
device => $dev_str,
type => 'rain',
current => $rain,
units => 'mm/h',
};
} elsif ($dev_type eq "PCR800") {
$rain = $rain / 100;
push @res, {
device => $dev_str,
type => 'rain',
current => $rain,
units => 'mm/h',
};
}
if ($dev_type ne "TX5_RAIN") {
my $train = ($bytes->[7]*256*256 + $bytes->[8]*256 + $bytes->[9])/10; # total rain
push @res, {
device => $dev_str,
type => 'train',
current => $train,
units => 'mm',
};
}
TRX_WEATHER_battery($bytes, $dev_str, \@res, 10);
return @res;
}
my @uv_str =
(
qw/low low low/, # 0 - 2
qw/medium medium medium/, # 3 - 5
qw/high high/, # 6 - 7
'very high', 'very high', 'very high', # 8 - 10
);
sub TRX_WEATHER_uv_string {
$uv_str[$_[0]] || 'dangerous';
}
# ------------------------------------------------------------
# T R X _ W E A T H E R _ c o m m o n _ u v
# * 0x5709 => { part => 'UV'
sub TRX_WEATHER_common_uv {
my $type = shift;
my $longids = shift;
my $bytes = shift;
my $subtype = sprintf "%02x", $bytes->[1];
my $dev_type;
my %devname =
( # HEXSTRING => "NAME"
0x01 => "UVN128", # Oregon UVN128, UV138
0x02 => "UVN800", # Oregon UVN800
0x03 => "TFA_UV", # TFA_UV-Sensor
);
if (exists $devname{$bytes->[1]}) {
$dev_type = $devname{$bytes->[1]};
} else {
Log3 undef, 3, "TRX_WEATHER: common_uv error undefined subtype=$subtype";
my @res = ();
return @res;
}
#my $seqnbr = sprintf "%02x", $bytes->[2];
my $dev_str = $dev_type;
if (TRX_WEATHER_use_longid($longids,$dev_type)) {
$dev_str .= $DOT.sprintf("%02x", $bytes->[3]);
}
if ($bytes->[4] > 0) {
$dev_str .= $DOT.sprintf("%d", $bytes->[4]);
}
my @res = ();
# hexline debugging
if ($TRX_HEX_debug) {
my $hexline = ""; for (my $i=0;$i<@$bytes;$i++) { $hexline .= sprintf("%02x",$bytes->[$i]);}
push @res, { device => $dev_str, type => 'hexline', current => $hexline, units => 'hex', };
}
my $uv = $bytes->[5]/10; # UV