-
Notifications
You must be signed in to change notification settings - Fork 1
/
10_CUL_HM.pm
14752 lines (14011 loc) · 677 KB
/
10_CUL_HM.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
##############################################
##############################################
# CUL HomeMatic handler
# $Id: 10_CUL_HM.pm 25977 2022-12-30 frank + Beta-User "uninitialized" 2022-08-01 $
#
# open issues:
# https://forum.fhem.de/index.php/topic,125378.msg1200761.html#msg1200761
# https://forum.fhem.de/index.php/topic,124090.msg1186368.html#msg1186368
# https://forum.fhem.de/index.php/topic,121139.msg1182503.html#msg1182503
# https://forum.fhem.de/index.php/topic,126118.msg1207202.html#msg1207202
# https://forum.fhem.de/index.php/topic,126197.0.html
package main;
use strict;
use warnings;
use HMConfig;
use Color;
use Digest::MD5 qw(md5);
eval "use Crypt::Rijndael";
my $cryptFunc = ($@)?0:1;
# ========================import constants=====================================
my $culHmModel =\%HMConfig::culHmModel;
my $culHmModel2Id =\%HMConfig::culHmModel2Id;
my $culHmRegDefShLg =\%HMConfig::culHmRegDefShLg;
my $culHmRegDefine =\%HMConfig::culHmRegDefine;
my $culHmRegGeneral =\%HMConfig::culHmRegGeneral;
my $culHmRegType =\%HMConfig::culHmRegType;
my $culHmRegModel =\%HMConfig::culHmRegModel;
my $culHmRegChan =\%HMConfig::culHmRegChan;
my $culHmGlobalGets =\%HMConfig::culHmGlobalGets;
my $culHmVrtGets =\%HMConfig::culHmVrtGets;
my $culHmSubTypeGets =\%HMConfig::culHmSubTypeGets;
my $culHmModelGets =\%HMConfig::culHmModelGets;
my $culHmGlobalGetsDev =\%HMConfig::culHmGlobalGetsDev;
my $culHmSubTypeDevSets =\%HMConfig::culHmSubTypeDevSets;
my $culHmGlobalSetsChn =\%HMConfig::culHmGlobalSetsChn;
my $culHmReglSets =\%HMConfig::culHmReglSets;
my $culHmGlobalSets =\%HMConfig::culHmGlobalSets;
my $culHmGlobalSetsVrtDev =\%HMConfig::culHmGlobalSetsVrtDev;
my $culHmSubTypeSets =\%HMConfig::culHmSubTypeSets;
my $culHmModelSets =\%HMConfig::culHmModelSets;
my $culHmChanSets =\%HMConfig::culHmChanSets;
my $culHmFunctSets =\%HMConfig::culHmFunctSets;
my $culHmBits =\%HMConfig::culHmBits;
my $culHmCmdFlags =\@HMConfig::culHmCmdFlags;
my $K_actDetID ="000000";
my %activeCmds = ( "valvePos" => 1,"up" => 1,"unlock" => 1,"toggleDir" => 1
,"toggle" => 1
,"tempListWed" => 1,"tempListTue" => 1,"tempListThu" => 1,"tempListSun" => 1
,"tempListSat" => 1,"tempListMon" => 1,"tempListFri" => 1
,"stop" => 1,"setRepeat" => 1
,"reset" => 1,"regSet" => 1,"regBulk" => 1
,"press" => 1,"postEvent" => 1,"playTone" => 1
,"peerIODev" => 1,"peerChan" => 1,"peerBulk" => 1
,"pctSlat" => 1,"pctLvlSlat" => 1,"pct" => 1,"pair" => 1
,"open" => 1,"on" => 1,"old" => 1,"off" => 1
,"lock" => 1,"level" => 1,"led" => 1
,"keydef" => 1,"fwUpdate" => 1,"down" => 1
,"controlParty" => 1,"controlManu" => 1
,"color" => 1,"colProgram" => 1,"brightCol" => 1,"brightAuto" => 1
,"on-till" => 1,"on-for-timer" => 1,"desired-temp" => 1
);
############################################################
sub CUL_HM_Initialize($);
sub CUL_HM_reqStatus($);
sub CUL_HM_autoReadConfig();
sub CUL_HM_updateConfig($);
sub CUL_HM_Define($$);
sub CUL_HM_Undef($$);
sub CUL_HM_Rename($$);
sub CUL_HM_Attr(@);
sub CUL_HM_Parse($$);
sub CUL_HM_parseCommon(@);
sub CUL_HM_qAutoRead($$);
sub CUL_HM_Get($@);
sub CUL_HM_Set($@);
sub CUL_HM_valvePosUpdt(@);
sub CUL_HM_infoUpdtDevData($$$$);
sub CUL_HM_infoUpdtChanData(@);
sub CUL_HM_getConfig($);
sub CUL_HM_SndCmd($$);
sub CUL_HM_responseSetup($$);
sub CUL_HM_eventP($$);
sub CUL_HM_protState($$);
sub CUL_HM_respPendRm($);
sub CUL_HM_respPendTout($);
sub CUL_HM_respPendToutProlong($);
sub CUL_HM_PushCmdStack($$);
sub CUL_HM_ProcessCmdStack($);
sub CUL_HM_pushConfig($$$$$$$$@);
sub CUL_HM_ID2PeerList ($$$);
sub CUL_HM_peerChId($$);
sub CUL_HM_peerChName($$);
sub CUL_HM_getMId($);
sub CUL_HM_getRxType($);
sub CUL_HM_getAssChnIds($);
sub CUL_HM_h2IoId($);
sub CUL_HM_IoId($);
sub CUL_HM_hash2Id($);
sub CUL_HM_hash2Name($);
sub CUL_HM_name2Hash($);
sub CUL_HM_name2Id(@);
sub CUL_HM_id2Name($);
sub CUL_HM_id2Hash($);
sub CUL_HM_getDeviceHash($);
sub CUL_HM_getDeviceName($);
sub CUL_HM_DumpProtocol($$@);
sub CUL_HM_getRegFromStore($$$$@);
sub CUL_HM_updtRegDisp($$$);
sub CUL_HM_encodeTime8($);
sub CUL_HM_decodeTime8($);
sub CUL_HM_encodeTime16($);
sub CUL_HM_convTemp($);
sub CUL_HM_decodeTime16($);
sub CUL_HM_secSince2000();
sub CUL_HM_getChnLvl($);
sub CUL_HM_initRegHash();
sub CUL_HM_fltCvT($);
sub CUL_HM_CvTflt($);
sub CUL_HM_getRegN($$@);
sub CUL_HM_4DisText($);
sub CUL_HM_TCtempReadings($);
sub CUL_HM_repReadings($);
sub CUL_HM_dimLog($);
sub CUL_HM_ActGetCreateHash();
sub CUL_HM_time2sec($);
sub CUL_HM_ActAdd($$);
sub CUL_HM_ActDel($);
sub CUL_HM_ActCheck($);
sub CUL_HM_UpdtReadBulk(@);
sub CUL_HM_UpdtReadSingle(@);
sub CUL_HM_setAttrIfCh($$$$);
sub CUL_HM_noDup(@); #return list with no duplicates
sub CUL_HM_noDupInString($);#return string with no duplicates, comma separated
sub CUL_HM_storeRssi(@);
sub CUL_HM_qStateUpdatIfEnab($@);
sub CUL_HM_getAttrInt($@);
sub CUL_HM_appFromQ($$);
sub CUL_HM_autoReadReady($);
sub CUL_HM_calcDisWm($$$);
sub CUL_HM_statCnt(@);
sub CUL_HM_trigLastEvent($$$$$);
sub CUL_HM_rmOldRegs($$);
sub CUL_HM_SetList($$);
sub CUL_HM_operIObyIOHash($);
sub CUL_HM_operIObyIOName($);
sub CUL_HM_hmInitMsgUpdt($;$);
# ----------------modul globals-----------------------
my $respRemoved; # used to control trigger of stack processing
my $IOpoll = 0.2;# poll speed to scan IO device out of order
my $maxPendCmds = 10; #number of parallel requests
my @evtEt = (); #readings for entities. Format hash:trigger:reading:value
my $evtDly = 0; # ugly switch to delay set readings if in parser - actually not our job, but fhem.pl refuses
# need to take care that ACK is first
my $mIdReverse = 0; # CUL_HM model ID reverse search is not supported by default. Check and update at startup
#+++++++++++++++++ startup, init, definition+++++++++++++++++++++++++++++++++++
sub CUL_HM_Initialize($) {
my ($hash) = @_;
# my @modellist = ();
# foreach my $model (keys %{$culHmModel}){
# next if (!$model);
# push @modellist,$culHmModel->{$model}{name};
# }
$hash->{Match} = "^A....................";
$hash->{DefFn} = "CUL_HM_Define";
$hash->{UndefFn} = "CUL_HM_Undef";
$hash->{ParseFn} = "CUL_HM_Parse";
$hash->{SetFn} = "CUL_HM_Set";
$hash->{GetFn} = "CUL_HM_Get";
#$hash->{RenameFn} = "CUL_HM_Rename"; # by own notify
$hash->{AttrFn} = "CUL_HM_Attr";
$hash->{NotifyFn} = "CUL_HM_Notify";
CUL_HM_AttrInit($hash,"initAttrlist");
CUL_HM_initRegHash();
my $time = gettimeofday();
$hash->{prot}{rspPend} = 0;#count Pending responses
my @statQArr = ();
my @statQWuArr = ();
my @confQArr = ();
my @confQWuArr = ();
my %confCheckH ;
my %confUpdt ; # entities with updated config
$hash->{helper}{qReqStat} = \@statQArr;
$hash->{helper}{qReqStatWu} = \@statQWuArr;
$hash->{helper}{qReqConf} = \@confQArr;
$hash->{helper}{qReqConfWu} = \@confQWuArr;
$hash->{helper}{confCheckH} = \%confCheckH;
$hash->{helper}{confUpdt} = \%confUpdt;
$hash->{helper}{cfgCmpl}{init}= 1;# mark entities with complete config
#statistics
$hash->{stat}{s}{dummy}=0;
$hash->{stat}{r}{dummy}=0;
RemoveInternalTimer("StatCntRfresh");
InternalTimer($time + 3600 * 20,"CUL_HM_statCntRfresh","StatCntRfresh", 0);
$hash->{hmIoMaxDly} = 60;# poll timeout - stop poll and discard
$hash->{hmAutoReadScan} = 4; # delay autoConf readings
$hash->{helper}{hmManualOper} = 0;# default automode
$hash->{helper}{verbose}{none} = 1; # init hash
$hash->{helper}{primary} = ""; # primary is one device in CUL_HM.It will be used for module notification.
# fhem does not provide module notifcation - so we streamline here.
$hash->{helper}{initDone} = 0;
$hash->{NotifyOrderPrefix} = "48-"; #Beta-User: make sure, CUL_HM is up and running prior to User code e.g. in notify, and also prior to HMinfo
InternalTimer($time + 1,"CUL_HM_updateConfig","startUp",0);
#InternalTimer($time + 1,"CUL_HM_setupHMLAN", "initHMLAN", 0);#start asap once FHEM is operational
return;
}
sub CUL_HM_updateConfig($){##########################
my $type = shift;
# this routine is called immedately after INITALIZED or REREADCFG
# so all attributes and stateFile content has been read.
# it will also be called after each manual definition
# Purpose is to parse attributes and read config
RemoveInternalTimer("updateConfig");
if (!$init_done){
InternalTimer(gettimeofday() + 1,"CUL_HM_updateConfig", "updateConfig", 0);#start asap once FHEM is operational
return;
}
if (!$modules{CUL_HM}{helper}{initDone}){ #= 0;$type eq "startUp"){
# only once after startup - clean up definitions. During operation define function will take care
Log 5,"CUL_HM start inital cleanup";
$mIdReverse = 1 if (scalar keys %{$culHmModel2Id});
my @hmdev = devspec2array("TYPE=CUL_HM:FILTER=DEF=......:FILTER=DEF!=000000"); # devices only
foreach my $name (@hmdev){
if ($attr{$name}{subType} && $attr{$name}{subType} eq "virtual"){
$attr{$name}{model} = "VIRTUAL" if (!$attr{$name}{model} || $attr{$name}{model} =~ m/virtual_/);
}
if ($attr{$name}{".mId"} && $culHmModel->{$attr{$name}{".mId"}}){ #if mId is available set model to its original value -at least temporarliy
$attr{$name}{model} = $culHmModel->{$attr{$name}{".mId"}}{name};
}
else{#if mId is not available use attr model and assign it.
if ($modules{CUL_HM}{AttrList} =~ m /\.mId/){# do not handle .mId if not restarted
$attr{$name}{".mId"} = CUL_HM_getmIdFromModel($attr{$name}{model});
}
}
CUL_HM_updtDeviceModel($name,AttrVal($name,"modelForce",AttrVal($name,"model","")),1) if($attr{$name}{".mId"});
# update IOdev
my $IOgrp = AttrVal($name,"IOgrp","");
if($IOgrp ne ""){
delete $attr{$name}{IODev};
CUL_HM_Attr('set',$name,'IOList',AttrVal($name,'IOList','')) if (AttrVal($name,'IOList',undef));
CUL_HM_Attr("set",$name,"IOgrp",$IOgrp);
}
my $h = $defs{$name};
delete $h->{helper}{io}{restoredIO} if ( defined($h->{helper}{io})
&& defined($h->{helper}{io}{restoredIO})
&& !defined($defs{$h->{helper}{io}{restoredIO}})); # cleanup undefined restored IO
if (!CUL_HM_operIObyIOHash($h->{IODev})) { # noansi: assign IO, if no currently operational IO assigned
CUL_HM_assignIO($h) if !IsDummy($name) && !IsIgnored($name);
delete($h->{IODev}{'.clientArray'}) if ($h->{IODev}); # Force a recompute
}
}
}
foreach my $name (@{$modules{CUL_HM}{helper}{updtCfgLst}}){
my $hash = $defs{$name};
next if (!$hash->{DEF}); # likely renamed
foreach my $read (grep/(RegL_0.:|_chn:\d\d)/,keys%{$hash->{READINGS}}){
my $readN = $read;
$readN =~ s/(RegL_0.):/$1\./;
$readN =~ s/_chn:(\d\d)/_chn-$1/;
$hash->{READINGS}{$readN} = $hash->{READINGS}{$read};
delete $hash->{READINGS}{$read};
}
my $id = $hash->{DEF};
my $nAttr = $modules{CUL_HM}{helper}{hmManualOper};# no update for attr
{#### find notification entity
if(!$modules{CUL_HM}{helper}{primary}){
CUL_HM_primaryDev(); # fake call to init primary device
}
if ($modules{CUL_HM}{helper}{primary} && $modules{CUL_HM}{helper}{primary} ne $name){
notifyRegexpChanged($defs{$name},0,1);#disable the notification
}
}
if ($id eq $K_actDetID){# if action detector
$attr{$name}{"event-on-change-reading"} =
AttrVal($name, "event-on-change-reading", ".*")
if(!$nAttr);
$attr{$name}{".mId"} = CUL_HM_getmIdFromModel("ACTIONDETECTOR");
$attr{$name}{model} = $culHmModel->{"0000"}{name};
$attr{$name}{subType} = $culHmModel->{"0000"}{st};
delete $hash->{IODev};
delete $hash->{READINGS}{IODev};
delete $hash->{helper}{mRssi};
delete $hash->{helper}{role};
delete $attr{$name}{$_}
foreach ( "autoReadReg","actStatus","burstAccess","serialNr"
,"IODev","IOList","IOgrp","hmProtocolEvents","rssiLog");
$hash->{helper}{role}{vrt} = 1;
$hash->{helper}{role}{dev} = 1;
delete $hash->{helper}{mId};
delete $hash->{helper}{rxType};#will update rxType and mId
CUL_HM_getMId($hash); # need to set regLst in helper
next;
}
CUL_HM_getMId($hash); # need to set regLst in helper
my $chn = substr($id."00",6,2);
my $st = CUL_HM_getAttr($name,"subType","");
my $md = CUL_HM_getAttr($name,"model","");
my $dHash = CUL_HM_getDeviceHash($hash);
$dHash->{helper}{role}{prs} = 1 if($hash->{helper}{regLst} && $hash->{helper}{regLst} =~ m/3p/);
foreach my $rName ("D-firmware","D-serialNr",".D-devInfo",".D-stc"){
# move certain attributes to readings for future handling
my $aName = $rName;
$aName =~ s/D-//;
my $aVal = AttrVal($name,$aName,undef);
CUL_HM_UpdtReadSingle($hash,$rName,$aVal,0)
if (!defined ReadingsVal($name,$rName,undef) && defined($aVal));
}
if ($md =~ /(HM-CC-TC|ROTO_ZEL-STG-RM-FWT)/){
# $hash->{helper}{role}{chn} = 1 if (length($id) == 6); #tc special
}
elsif ($md =~ m/^(HM-CC-RT-DN)/){
$hash->{helper}{shRegR}{"07"} = "00" if ($chn eq "04");# shadowReg List 7 read from CH 0
$hash->{helper}{shRegW}{"07"} = "04" if ($chn eq "00");# shadowReg List 7 write to CH 4
}
elsif ($md =~ m/^(HM-TC-IT-WM-W-EU)/){
$hash->{helper}{shRegR}{"07"} = "00" if ($chn eq "02");# shadowReg List 7 read from CH 0
$hash->{helper}{shRegW}{"07"} = "02" if ($chn eq "00");# shadowReg List 7 write to CH 4
}
elsif ($md =~ m/^(HM-CC-VD|ROTO_ZEL-STG-RM-FSA)/){
$attr{$name}{msgRepeat} = 0 if ($hash->{helper}{role}{dev}); #noansi: force no repeat
$hash->{helper}{oldDes} = "0";
}
elsif ($md =~ m/^(HM-DIS-WM55)/){
foreach my $t ("s","l"){
if(!defined $hash->{helper}{dispi}{$t}{"l1"}{d}){# setup if one is missing
$hash->{helper}{dispi}{$t}{"l$_"}{d}=1 foreach (1,2,3,4,5,6);
}
}
}
elsif ($md =~ m/^(HM-DIS-EP-WM55)/){
CUL_HM_UpdtReadSingle($hash,"state","-",0) if(InternalVal($name,"chanNo",0)>3);
}
elsif ($md =~ m/^(CCU-FHEM)/){
$hash->{helper}{role}{vrt} = 1;
delete $hash->{helper}{mId};
if($hash->{helper}{role}{dev}){
CUL_HM_UpdtCentral($name); # first update, then keys
foreach my $io (split ",",AttrVal($name,"IOList","")) {
next if(!$defs{$io});
if($defs{$io}->{TYPE} eq "HMLAN" && eval "defined(&HMLAN_writeAesKey)"){
HMLAN_writeAesKey($io);
}
elsif ($defs{$io}->{TYPE} eq "HMUARTLGW") {
CallFn($io,"WriteFn",$defs{$io},undef,"writeAesKey:${io}");
}
elsif ( $defs{$io}->{helper}{VTS_AES} # noansi: for TSCUL
&& eval "defined(&TSCUL_WriteAesKeyHM)"){
TSCUL_WriteAesKeyHM($io); # noansi: for TSCUL
}
}
$hash->{helper}{io}{vccu} = $name if (!$hash->{helper}{io}{vccu}
&& AttrVal($name,"IOList","")); # noansi: help, if IOgrp is missing for VCCU
}
}
elsif ($md =~ m/^HM-SEN-RD-O/ && $chn eq "02"){
for my $params (split q{,},AttrVal($name,'param','')){
if ($params eq "offAtPon"){$hash->{helper}{param}{offAtPon} = 1}
elsif ($params eq "onAtRain"){$hash->{helper}{param}{onAtRain} = 1}
}
}
elsif ($st =~ m/^(motionDetector|motionAndBtn)$/ ){
CUL_HM_UpdtReadSingle($hash,"state","-",0);
CUL_HM_UpdtReadSingle($hash,"motion","-",0);
RemoveInternalTimer($name.":motionCheck");
InternalTimer(gettimeofday()+30+2,"CUL_HM_motionCheck", $name.":motionCheck", 0);
}
elsif ($st eq "dimmer" ) {#setup virtual dimmer channels
my $mId = CUL_HM_getMId($hash);
#configure Dimmer virtual channel assotiation
if ($hash->{helper}{role}{chn}){
my $chn = (length($id) == 8)?substr($id,6,2):"01";
my $devId = substr($id,0,6);
if ($culHmModel->{$mId} && $culHmModel->{$mId}{chn} =~ m/Dim_V/){#virtual?
my @chnPh = (grep{$_ =~ m/Sw:/ } split ',',$culHmModel->{$mId}{chn});
@chnPh = split ':',$chnPh[0] if (@chnPh);
my $chnPhyMax = $chnPh[2]?$chnPh[2]:1; # max Phys channels
my $chnPhy = ($chnPhyMax == 2 && $chn > 4)?2:1; # assotiated phy chan( either 1 or 2)
my $idPhy = $devId.sprintf("%02X",$chnPhy);# ID assot phy chan
my $pHash = CUL_HM_id2Hash($idPhy); # hash assot phy chan
$idPhy = $pHash->{DEF}; # could be device!!!
if ($pHash){
$pHash->{helper}{vDim}{idPhy} = $idPhy;
my $vHash = CUL_HM_id2Hash($devId.sprintf("%02X",$chnPhyMax+2*$chnPhy-1));
if ($vHash){
$pHash->{helper}{vDim}{idV2} = $vHash->{DEF};
$vHash->{helper}{vDim}{idPhy} = $idPhy;
}
else{
delete $pHash->{helper}{vDim}{idV2};
}
$vHash = CUL_HM_id2Hash($devId.sprintf("%02X",$chnPhyMax+2*$chnPhy));
if ($vHash){
$pHash->{helper}{vDim}{idV3} = $vHash->{DEF};
$vHash->{helper}{vDim}{idPhy} = $idPhy;
}
else{
delete $pHash->{helper}{vDim}{idV3};
}
}
}
}
}
elsif ($st eq "virtual" ) {#setup virtuals
$hash->{helper}{role}{vrt} = 1;
if ( $hash->{helper}{fkt}
&& $hash->{helper}{fkt} =~ m/^(vdCtrl|virtThSens)$/){
my $vId = substr($id."01",0,8);
if (!defined $hash->{helper}{vd}{msgRed}) {
$hash->{helper}{vd}{msgRed}= 0;
my $attrVal = AttrVal($name,'param','');
if ($attrVal =~ m/msgReduce/) {
my (undef,$rCnt) = split(":",$attrVal,2);
$hash->{helper}{vd}{msgRed} = (defined $rCnt && $rCnt =~ m/^\d$/) ? $rCnt : 1;
}
}
if(!defined $hash->{helper}{vd}{next}){
($hash->{helper}{vd}{msgCnt},$hash->{helper}{vd}{next}) =
split(";",ReadingsVal($name,".next","0;".gettimeofday()));
$hash->{helper}{vd}{idl} = 0;
$hash->{helper}{vd}{idh} = 0;
}
InternalTimer(time+10,'CUL_HM_initializeVirtuals', $hash,0); #Beta-User: make sure, CUL_HM is in toto up and running befor other devices want to use them,
# delete - virtuals dont have regs
delete $attr{$name}{$_} foreach ("autoReadReg","actCycle","actStatus","burstAccess","serialNr");
}
}
elsif ($st eq "sensRain") {
$hash->{helper}{lastRain} = ReadingsTimestamp($name,"state","")
if (ReadingsVal($name,"state","") eq "rain");
}
next if ($nAttr);# stop if default setting if attributes is not desired
# --- set default attributes if missing ---
if ($hash->{helper}{role}{dev}){
if( $st ne "virtual"){
$attr{$name}{expert} = AttrVal($name,"expert" ,"rawReg");
$attr{$name}{autoReadReg}= AttrVal($name,"autoReadReg","4_reqStatus");
CUL_HM_hmInitMsg($hash);
}
my $rxt = CUL_HM_getRxType($hash);# set rxType and mId
if($rxt & 0x02){#burst dev must restrict retries!
$attr{$name}{msgRepeat} = 1 if (!$attr{$name}{msgRepeat});
}
elsif($rxt & 0x80){# frank: init conditional burst dev
if($attr{$name}{burstAccess}){
CUL_HM_Attr('set',$name,'burstAccess',$attr{$name}{burstAccess});
}
else{
CUL_HM_Attr('del',$name,'burstAccess');
}
}
}
if ($attr{$name}{expert}){
CUL_HM_Attr("set",$name,"expert",$attr{$name}{expert});
}
else{
CUL_HM_Attr("del",$name,"expert"); # need to update settings and readings
}
;#need update after readings are available
if ($chn eq "03" &&
$md =~ /(-TC|ROTO_ZEL-STG-RM-FWT|HM-CC-RT-DN)/){
$attr{$name}{stateFormat} = "last:trigLast";
}
# -+-+-+-+-+ add default web-commands
my $webCmd;
$webCmd = AttrVal($name,"webCmd",undef);
if(!defined $webCmd){
if ($st eq "virtual" ){
if ($hash->{helper}{fkt} && $hash->{helper}{fkt} eq "sdLead1") {$webCmd="teamCall:alarmOn:alarmOff";}
elsif($hash->{helper}{fkt} && $hash->{helper}{fkt} eq "vdCtrl") {$webCmd="valvePos";}
elsif($hash->{helper}{fkt} && $hash->{helper}{fkt} eq "virtThSens"){$webCmd="virtTemp:virtHum";}
elsif(!$hash->{helper}{role}{dev}) {$webCmd="press short:press long";}
elsif($md =~ m/^(virtual_|VIRTUAL)/) {$webCmd="virtual";}
elsif($md eq "CCU-FHEM") {$webCmd="virtual:update";}
}
elsif((!$hash->{helper}{role}{chn} &&
$md !~ m/^(HM-CC-TC|ROTO_ZEL-STG-RM-FWT)/)
||$st eq "repeater"
||$md =~ m/^(HM-CC-VD|ROTO_ZEL-STG-RM-FSA)/ ){$webCmd="getConfig:clear msgEvents";
if ($md =~ m/^HM-CC-RT-DN/) {$webCmd.=":burstXmit";}
}
elsif($st eq "blindActuator"){
if ($hash->{helper}{role}{chn}){$webCmd="statusRequest:toggleDir:on:off:up:down:stop";}
else{ $webCmd="statusRequest:getConfig:clear msgEvents";}
}
elsif($st eq "dimmer" ){
if ($hash->{helper}{role}{chn}){$webCmd="statusRequest:toggle:on:off:up:down";}
else{ $webCmd="statusRequest:getConfig:clear msgEvents";}
}
elsif($st eq "switch" ){
if ($hash->{helper}{role}{chn}){$webCmd="statusRequest:toggle:on:off";}
else{ $webCmd="statusRequest:getConfig:clear msgEvents";}
}
elsif($st eq "smokeDetector"){ $webCmd="statusRequest";
if (defined $hash->{helper}{fkt} && $hash->{helper}{fkt} eq "sdLead1"){
$webCmd.=":teamCall:alarmOn:alarmOff";}
}
elsif($st eq "keyMatic" ){ $webCmd="lock:inhibit on:inhibit off";
}
elsif( $md eq "HM-OU-CFM-PL"
||$md eq "HM-OU-CFM-TW" ){ $webCmd="press short:press long"
.($chn eq "02"?":playTone replay":"");
}
if ($webCmd){
my $eventMap = AttrVal($name,"eventMap",undef);
my @wc;
push @wc,ReplaceEventMap($name, $_, 1) foreach (split ":",$webCmd);
$webCmd = join ":",@wc;
}
}
$attr{$name}{webCmd} = $webCmd if ($webCmd);
CUL_HM_SetList($name,"") if (!defined $defs{$name}{helper}{cmds}{cmdLst});
#remove invalid attributes. After set commands fot templist
CUL_HM_Attr("set",$name,"peerIDs",$attr{$name}{peerIDs}) if (defined $attr{$name}{peerIDs});# set attr again to update namings
foreach(sort keys %{$attr{$name}}){
delete $attr{$name}{$_} if (CUL_HM_AttrCheck($name,'set',$_,$attr{$name}{$_}));
}
#CUL_HM_qStateUpdatIfEnab($name) if($hash->{helper}{role}{dev}); #frank, https://forum.fhem.de/index.php/topic,125378.msg1202273.html#msg1202273
next if (0 == (0x07 & CUL_HM_getAttrInt($name,"autoReadReg")));
if(CUL_HM_getPeers($name,"Config") == 2){
CUL_HM_qAutoRead($name,1);
}
else{
foreach(CUL_HM_reglUsed($name)){
next if (!$_);
if(ReadingsVal($name,$_,"x") !~ m/00:00/){
CUL_HM_qAutoRead($name,1);
last;
}
}
}
CUL_HM_complConfig($name);
CUL_HM_setAssotiat($name);
}
#delete $modules{CUL_HM}{helper}{updtCfgLst}; #frank, https://forum.fhem.de/index.php/topic,125378.msg1202273.html#msg1202273
if(!$modules{CUL_HM}{helper}{initDone}){
Log 5,"CUL_HM finished initial cleanup";
InternalTimer(gettimeofday() + 66, 'CUL_HM_startQueues', 'CUL_HM_startQueues', 0); #frank, https://forum.fhem.de/index.php/topic,125378.msg1202273.html#msg1202273 ff
if (defined &HMinfo_init){# force reread
$modules{HMinfo}{helper}{initDone} = 0;
InternalTimer(gettimeofday() + 5,"HMinfo_init", "HMinfo_init", 0);
}
}
$modules{CUL_HM}{helper}{initDone} = 1;# we made init once - now we are operational. Check with HMInfo as well
## configCheck will be issues by HMInfo once
}
sub CUL_HM_startQueues() { #frank, https://forum.fhem.de/index.php/topic,125378.msg1202273.html#msg1202273
Log3('global',3,'CUL_HM start Queues'); #Beta-User: changed verbose level
for my $name (@{$modules{CUL_HM}{helper}{updtCfgLst}}){
CUL_HM_qStateUpdatIfEnab($name) if($defs{$name}->{helper}{role}{dev});
}
delete $modules{CUL_HM}{helper}{updtCfgLst};
return;
}
sub CUL_HM_initializeVirtuals {
my $hash = shift // return;
my $name = $hash->{NAME} // return;
my $vId = substr($hash->{DEF}."01",0,8);
if ($hash->{helper}{fkt} eq "vdCtrl"){
my $d = ReadingsNum($name,'valvePosTC','50');
CUL_HM_Set($hash,$name,"valvePos",$d);
CUL_HM_UpdtReadSingle($hash,"valveCtrl","restart",1) if ($d =~ m/^[-+]?[0-9]+\.?[0-9]*$/);
RemoveInternalTimer("valvePos:$vId");
RemoveInternalTimer("valveTmr:$vId");
InternalTimer($hash->{helper}{vd}{next},"CUL_HM_valvePosUpdt","valvePos:$vId",0);
}
elsif($hash->{helper}{fkt} eq "virtThSens"){
my $d = ReadingsNum($name,'temperature','');
CUL_HM_Set($hash,$name,"virtTemp",$d) if($d =~ m/^[-+]?[0-9]+\.?[0-9]*$/);
$d = ReadingsNum($name,"humidity","");
CUL_HM_Set($hash,$name,"virtHum" ,$d) if($d =~ m/^[-+]?[0-9]+\.?[0-9]*$/);
}
return;
}
sub CUL_HM_primaryDev() {############################
# one - and only one - CUL_HM entity will be primary device
# primary device is a) CUL_HM and b) not ignored
if ( !$modules{CUL_HM}{helper}{primary}
|| AttrVal($modules{CUL_HM}{helper}{primary},"ignore",0) == 1
|| !defined $defs{$modules{CUL_HM}{helper}{primary}} ){# we need to check primary
my ($prim ) = devspec2array("TYPE=CUL_HM"); # a non-ignore CUL_HM entity
if ($prim && defined $defs{$prim}){
notifyRegexpChanged($defs{$prim},"global",0);
$modules{CUL_HM}{helper}{primary} = $prim;
}
else{
$modules{CUL_HM}{helper}{primary} = "";
}
}
}
sub CUL_HM_Define($$) {##############################
my ($hash, $def) = @_;
my @a = split("[ \t][ \t]*", $def);
my $HMid = uc($a[2]);
return "wrong syntax: define <name> CUL_HM 6-digit-hex-code [Raw-Message]"
if(!(int(@a)==3 || int(@a)==4) || $HMid !~ m/^[A-F0-9]{6}([A-F0-9]{2})?$/i );
return "HMid DEF already used by " . CUL_HM_id2Name($HMid)
if ($modules{CUL_HM}{defptr}{$HMid});
my $name = $hash->{NAME};
if(length($HMid) == 8) {# define a channel
my $devHmId = substr($HMid, 0, 6);
my $chn = substr($HMid, 6, 2);
my $devHash = $modules{CUL_HM}{defptr}{$devHmId};
return "please define a device with hmId:".$devHmId." first" if(!$devHash);
my $devName = $devHash->{NAME};
$hash->{device} = $devName; #readable ref to device name
$hash->{chanNo} = $chn; #readable ref to Channel
$devHash->{"channel_$chn"} = $name; #reference in device as well
$attr{$name}{model} = AttrVal($devName, "model", undef);
$hash->{helper}{role}{chn} = 1;
delete $hash->{helper}{mId};
delete $hash->{helper}{rxType};
if($chn eq "01"){
if (defined $devHash->{helper}{peerIDsH}){
$hash->{helper}{peerIDsH} = $devHash->{helper}{peerIDsH} ;
$hash->{helper}{peerIDsState} = $devHash->{helper}{peerIDsState};
}
$attr{$name}{peerIDs} = AttrVal($devName, "peerIDs", "peerUnread");
$hash->{READINGS}{peerList}{VAL} = ReadingsVal($devName,"peerList","peerUnread");
$hash->{peerList} = $devHash->{peerList} if($devHash->{peerList});
delete $devHash->{helper}{role}{chn};#device no longer
delete $devHash->{chanNo}; #readable ref to Channel
delete $devHash->{peerList};
delete $devHash->{READINGS}{peerList};
delete $attr{$devName}{peerIDs};
delete $devHash->{helper}{peerIDsH};
delete $devHash->{helper}{peerIDsState};
$devHash->{helper}{cmds}{cmdKey} = ''; # noansi: rebuild required
$devHash->{helper}{cmds}{TmplKey} = ''; # noansi: rebuild required
}
}
else{# define a device
$hash->{helper}{role}{dev} = 1;
delete $hash->{helper}{mId};
delete $hash->{helper}{rxType};
$hash->{helper}{role}{chn} = 1;# take role of chn 01 until it is defined
$hash->{helper}{q}{qReqConf} = ""; # queue autoConfig requests
$hash->{helper}{q}{qReqStat} = ""; # queue statusRequest for this device
$hash->{helper}{mRssi}{mNo} = "";
$hash->{helper}{HM_CMDNR} = int(rand(250));# should be different from previous
CUL_HM_prtInit ($hash);
$hash->{helper}{io}{vccu} = "";
my @a;
$hash->{helper}{io}{prefIO} = \@a;
$hash->{chanNo} = "01" if (!defined $defs{$HMid."01"}); #readable ref to Channel
if ( !$modules{CUL_HM}{helper}{initDone}
&& $HMid ne "000000") {
if (eval "defined(&TSCUL_RestoreHMDev)") {
my $restoredIOname = TSCUL_RestoreHMDev($hash, $HMid); # noansi: restore IODev from TSCUL before the first CUL_HM_assignIO
# here not all IOs may be defined allready, but we can try to restore as no IO is set
# restore is working best, if IOs are defined first in cfg
if (defined($restoredIOname)) {
$hash->{IODev} = $defs{$restoredIOname};
# $attr{$name}{IODev} = $restoredIOname;
$hash->{helper}{io}{restoredIO} = $restoredIOname; # noansi: until attributes are filled, this should be the first choice
@{$hash->{helper}{mRssi}{io}{$restoredIOname}} = (100,100); # noansi: set IO high rssi for first autoassign
}
}
# fhem.pl will set an IO from reading/attr IODev or AssignIoPort at end of init, we can not avoid and can not assign correctly
# but with reading IOdev fhem.pl will restore the IO unsed before normal restart
CUL_HM_assignIO($hash) if (!$hash->{IODev} && $init_done);
delete($hash->{IODev}{'.clientArray'}) if ($hash->{IODev}); # Force a recompute
}
}
$hash->{helper}{cmds}{cmdKey} = "";
$hash->{helper}{cmds}{TmplKey} = "";
$modules{CUL_HM}{defptr}{$HMid} = $hash;
notifyRegexpChanged($hash,"",1);# no notification required for this device
CUL_HM_primaryDev() if devspec2array('TYPE=CUL_HM') == 2; #Beta-User: we need at least one entity to initialize startup procedure
#- - - - create auto-update - - - - - -
CUL_HM_ActGetCreateHash() if($HMid eq '000000');#startTimer
$hash->{DEF} = $HMid;
CUL_HM_Parse($hash, $a[3]) if(int(@a) == 4);
CUL_HM_queueUpdtCfg($name);
return undef;
}
sub CUL_HM_Undef($$) {###############################
my ($hash, $name) = @_;
my $devName = $hash->{device};
my $HMid = $hash->{DEF};
CUL_HM_unQEntity($name,"qReqConf");
CUL_HM_unQEntity($name,"qReqStat");
CUL_HM_complConfigTestRm($name);
my $chn = substr($HMid,6,2);
if ($chn){# delete a channel
my $devHash = $defs{$devName};
delete $devHash->{"channel_$chn"} if ($devName);
$devHash->{helper}{role}{chn} = 1 if($chn eq "01");# return chan 01 role
delete $hash->{helper}{mId};
}
else{# delete a device
CommandDelete(undef,$hash->{$_}) foreach (grep(/^channel_/,keys %{$hash}));
}
delete($modules{CUL_HM}{defptr}{$HMid});
delete $modules{CUL_HM}{helper}{primary} if (devspec2array('TYPE=CUL_HM') == 1);
return undef;
}
sub CUL_HM_Rename($$) {##############################
my ($name, $oldName) = @_;
my $hash = $defs{$name};
return if($hash->{TYPE} ne "CUL_HM");
my $HMid = CUL_HM_name2Id($name);
if (!$hash->{helper}{role}{dev}){# we are channel, inform the device
$hash->{chanNo} = substr($HMid,6,2);
my $devHash = CUL_HM_id2Hash(substr($HMid,0,6));
$hash->{device} = $devHash->{NAME};
$devHash->{"channel_".$hash->{chanNo}} = $name;
}
else{# we are a device - inform channels if exist
foreach (grep (/^channel_/, keys%{$hash})){
next if(!$_);
my $chnHash = $defs{$hash->{$_}};
$chnHash->{device} = $name;
}
if (!defined $defs{$HMid."01"}){$hash->{chanNo} = "01";}
else {delete $hash->{chanNo};}
CUL_HM_UpdtCentral($name) if (AttrVal($name, "model", "") eq "CCU-FHEM");
}
if ($hash->{helper}{role}{chn}){
my $HMidCh = substr($HMid."01",0,8);
foreach my $pId (keys %{$modules{CUL_HM}{defptr}}){#all devices for peer
my $pH = $modules{CUL_HM}{defptr}{$pId};
my $pN = $pH->{NAME};
if (defined $hash->{helper}{peerIDsH}{$HMidCh}){
CUL_HM_Attr("set",$pN,"peerIDs",$attr{$pN}{peerIDs}) if (defined $attr{$pN}{peerIDs});# set attr again to update namings
foreach my $pR (grep /(-|\.)$oldName(-|$)/,keys%{$pH->{READINGS}}){#update reading of the peer
my $pRn = $pR;
$pRn =~ s/$oldName/$name/;
$pH->{READINGS}{$pRn}{VAL} = $pH->{READINGS}{$pR}{VAL};
$pH->{READINGS}{$pRn}{TIME} = $pH->{READINGS}{$pR}{TIME};
delete $pH->{READINGS}{$pR};
}
if (eval "defined(&HMinfo_templateMark)"){
foreach my $pT (grep /$oldName:/,keys%{$pH->{helper}{tmpl}}){#update reading of the peer
my $param = $pH->{helper}{tmpl}{$pT};
my ($px,$tmpl) = split(">",$pT);
HMinfo_templateDel($pN,$tmpl,$px);
$px =~ s/$oldName/$name/;
HMinfo_templateMark($pH,"$px>$tmpl",split(" ",$param));
}
}
}
}
}
if($modules{CUL_HM}{helper}{primary} eq $oldName){
}
notifyRegexpChanged($hash,"",1);# no notification required for this device
return;
}
sub CUL_HM_Attr(@) {#################################
my ($cmd,$name, $attrName,$attrVal) = @_;
return undef if (!$init_done);
my $chk = CUL_HM_AttrCheck($name,$cmd, $attrName,$attrVal);
return $chk if ($chk);
my $hash = CUL_HM_name2Hash($name);
my $updtReq = 0;
if ($attrName eq "expert"){
my $ret = 0;
if ($cmd eq "set"){
my @expLst = ();
if ($attrVal =~ m/^(\d+)/){# old style
push @expLst, "defReg" if(!($1 & 0x04));#default register on
push @expLst, "allReg" if( ($1 & 0x01));#detail register on
push @expLst, "rawReg" if( ($1 & 0x02));#raw register on
push @expLst, "templ" if( ($1 & 0x08));#template on
push @expLst, "none" if( ($1 & 0x0F) == 0x04);#all off
$ret = 1;
}
else{
$modules{CUL_HM}{AttrList} =~ m/.*expert:multiple,(.*?) .*/;
my $expOpts = $1;
foreach (split(",",$attrVal)){
if($expOpts =~ m/\b$_\b/){
push @expLst,$_ ;
}
else{
$ret = 1;
}
}
}
$attr{$name}{$attrName} = join(",",@expLst);
}
else{#delete
delete $attr{$name}{$attrName};
}
CUL_HM_chgExpLvl($_) foreach ((map{CUL_HM_id2Hash($_)} CUL_HM_getAssChnIds($name)),$defs{$name});
return $attr{$name}{$attrName} if ($ret);
}
elsif($attrName eq "readOnly"){#[0,1]
}
elsif($attrName eq "actCycle"){#"000:00" or 'off'
if ($cmd eq "set"){
if (CUL_HM_name2Id($name) eq $K_actDetID){
return "$attrName must not be lower then 10, $attrVal not allowed"
if ($attrVal < 10);
#update and sync to new timing
RemoveInternalTimer("ActionDetector");
InternalTimer(gettimeofday()+5,"CUL_HM_ActCheck", "ActionDetector", 0);
}
else{
return "attribut not allowed for channels"
if (!$hash->{helper}{role}{dev});
my $attrValNew;
if($attrVal =~ m/^(0+:0+|off)$/){
$attrValNew = '000:00';
}
elsif($attrVal =~ m/^(\d+):(\d+)$/){
my ($h,$m) = (int($1),int($2));
return "format hhh:mm required. $attrVal incorrect" if( $h > 999 || $h < 0
|| $m > 59 || $m < 0
|| $h + $m <= 0);
$attrValNew = sprintf("%03d:%02d",$h,$m);
}
my $addres = CUL_HM_ActAdd(CUL_HM_name2Id($name),$attrValNew);
return $addres if defined($addres); # noansi: return errors from CUL_HM_ActAdd
$attr{$name}{$attrName} = $attrValNew;
return "reformated input:$attrValNew" if($attrValNew ne $attrVal);
}
}
$updtReq = 1;
}
elsif($attrName eq "param"){
my $md = CUL_HM_getAttr($name,"model","");
my $st = CUL_HM_getAttr($name,"subType","");
my $chn = substr(CUL_HM_hash2Id($hash),6,2);
if ($md eq "HM-SEN-RD-O" && $chn eq "02"){
delete $hash->{helper}{param};
foreach (split ",",$attrVal){
if ($_ eq "offAtPon"){$hash->{helper}{param}{offAtPon} = 1}
elsif ($_ eq "onAtRain"){$hash->{helper}{param}{onAtRain} = 1}
else {return "param $_ unknown, use offAtPon or onAtRain";}
}
}
elsif ($md eq "HM-DIS-EP-WM55" && $chn eq "03"){#reWriteDisplay
if ($cmd eq "set"){
if ($attrVal =~ m/^reWriteDisplay([0-9][0-9])$/){# no action, just set
my $delay = $1;
if($delay < 1 || $delay >99){
return "invalid $delay- select between reWriteDisplay01 and reWriteDisplay99";
}
}
else{
return "attribut param $attrVal not valid for $name. Only reWriteDisplayxx allowed";
}
}
else{
delete $hash->{helper}{vd}{msgRed};
}
}
elsif ($st eq "virtual"){
if ($cmd eq "set"){
if ($attrVal eq "noOnOff"){# no action
}
elsif ($attrVal =~ m/msgReduce/){# send only each other message
my (undef,$rCnt) = split(":",$attrVal,2);
$rCnt=(defined $rCnt && $rCnt =~ m/^\d$/)?$rCnt:1;
$hash->{helper}{vd}{msgRed}=$rCnt;
}
else{
return "attribut param $attrVal not valid for $name";
}
}
else{
delete $hash->{helper}{vd}{msgRed};
}
}
else{
if ($cmd eq "set"){
if ($attrVal =~ m/(levelInverse|ponRestore)/){# no action
}
elsif ($attrVal =~ m/(showTimed)/){# no action
#we could check for those subtypes
#sensRain
#siren
#powerMeter
#switch
#dimmer
#rgb
}
else{
return "attribut param $attrVal not valid for $name";
}
}
else{
delete $hash->{helper}{vd}{msgRed};
}
}
}
elsif($attrName eq "peerIDs"){
if ($cmd eq "set"){
return "$attrName not usable for devices" if(!$hash->{helper}{role}{chn});
my $dId = substr(CUL_HM_name2Id($name),0,6); #get own device ID
if ($hash->{DEF} ne $K_actDetID && $attrVal){# if not action detector
return "new $attrName val:$attrVal element $_ not a peerID. User (peerUnread|[0-9a-fA-Fx]{8})" if(grep!/^(peerUnread|[0-9a-fA-Fx]{8})$/,split(",",$attrVal));
CUL_HM_ID2PeerList($name,$_,1) foreach("peerUnread",split(",",$attrVal));#first clear, then setup
}
}
else{# delete
delete $hash->{peerList};
delete $hash->{READINGS}{peerList};
CUL_HM_ID2PeerList($name," ","clear");
}
}
elsif($attrName eq "msgRepeat"){
if ($cmd eq "set"){
return "$attrName not usable for channels" if(!$hash->{helper}{role}{dev});#only for device
return "value $attrVal ignored, must be an integer" if ($attrVal !~ m/^(\d+)$/);
}
return;
}
elsif($attrName eq "model"){
return "change not allowed for channels" if(!$hash->{helper}{role}{dev});
if ( $attrVal eq "CCU-FHEM"
and $cmd eq "set"
and AttrVal($name,"model","VIRTUAL") =~ m/^(VIRTUAL|)$/){
delete $hash->{helper}{rxType}; # needs new calculation
delete $hash->{helper}{mId};
$attr{$name}{subType} = "virtual";
$attr{$name}{".mId"} = CUL_HM_getmIdFromModel($attrVal);
CUL_HM_updtDeviceModel($name,$attrVal);
$updtReq = 1;
CUL_HM_AttrAssign($name);
CUL_HM_UpdtCentral($name);
}
else{
return "$attrName must not be changed by User. \nUse modelForce instead" if (AttrVal($name,$attrName,"empty") !~ m/(empty|$attrVal)/);
delete $hash->{helper}{rxType}; # needs new calculation
delete $hash->{helper}{mId};
CUL_HM_hmInitMsg($hash);# will update mId, rxType and others
CUL_HM_updtDeviceModel($name,$attrVal);
}
$attr{$name}{$attrName} = $attrVal if ($cmd eq "set");
}
elsif($attrName eq "modelForce"){
if ($cmd eq "set"){
return "invalid model name$cmd. Please check options" if (!CUL_HM_getmIdFromModel($attrVal));
if (!defined $attr{$name}{".mId"} && defined $attr{$name}{model}){ # set .mId in case it is missing
$attr{$name}{".mId"} = CUL_HM_getmIdFromModel($attr{$name}{model});
}
CUL_HM_updtDeviceModel($name,$attrVal);
}
else{
$attr{$name}{model} = $culHmModel->{$attr{$name}{".mId"}}{name} if ($attr{$name}{".mId"});# return to old model name
CUL_HM_updtDeviceModel($name,$attr{$name}{model});
}
}