-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path73_AutoShuttersControl.pm
4039 lines (3497 loc) · 149 KB
/
73_AutoShuttersControl.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
###############################################################################
#
# Developed with Kate
#
# (c) 2018-2019 Copyright: Marko Oldenburg (leongaultier at gmail dot com)
# All rights reserved
#
# Special thanks goes to:
# - Bernd (Cluni) this module is based on the logic of his script "Rollladensteuerung für HM/ROLLO inkl. Abschattung und Komfortfunktionen in Perl" (https://forum.fhem.de/index.php/topic,73964.0.html)
# - Beta-User for many tests and ideas
# - pc1246 write english commandref
# - sledge fix many typo in commandref
# - many User that use with modul and report bugs
#
#
# This script is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License,or
# any later version.
#
# The GNU General Public License can be found at
# http://www.gnu.org/copyleft/gpl.html.
# A copy is found in the textfile GPL.txt and important notices to the license
# from the author is found in LICENSE.txt distributed with these scripts.
#
# 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. See the
# GNU General Public License for more details.
#
#
# $Id$
#
###############################################################################
### Notizen
# - Feststellen ob ein Rolladen fährt oder nicht
package main;
use strict;
use warnings;
my $version = '0.4.0.9';
sub AutoShuttersControl_Initialize($) {
my ($hash) = @_;
## Da ich mit package arbeite müssen in die Initialize für die jeweiligen hash Fn Funktionen der Funktionsname
# und davor mit :: getrennt der eigentliche package Name des Modules
$hash->{SetFn} = 'AutoShuttersControl::Set';
$hash->{GetFn} = 'AutoShuttersControl::Get';
$hash->{DefFn} = 'AutoShuttersControl::Define';
$hash->{NotifyFn} = 'AutoShuttersControl::Notify';
$hash->{UndefFn} = 'AutoShuttersControl::Undef';
$hash->{AttrFn} = 'AutoShuttersControl::Attr';
$hash->{AttrList} =
'ASC_guestPresence:on,off '
. 'ASC_temperatureSensor '
. 'ASC_temperatureReading '
. 'ASC_brightnessMinVal '
. 'ASC_brightnessMaxVal '
. 'ASC_autoShuttersControlMorning:on,off '
. 'ASC_autoShuttersControlEvening:on,off '
. 'ASC_autoShuttersControlShading:on,off '
. 'ASC_autoShuttersControlComfort:on,off '
. 'ASC_residentsDevice '
. 'ASC_residentsDeviceReading '
. 'ASC_rainSensorDevice '
. 'ASC_rainSensorReading '
. 'ASC_rainSensorShuttersClosedPos:0,10,20,30,40,50,60,70,80,90,100 '
. 'ASC_autoAstroModeMorning:REAL,CIVIL,NAUTIC,ASTRONOMIC,HORIZON '
. 'ASC_autoAstroModeMorningHorizon:-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9 '
. 'ASC_autoAstroModeEvening:REAL,CIVIL,NAUTIC,ASTRONOMIC,HORIZON '
. 'ASC_autoAstroModeEveningHorizon:-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9 '
. 'ASC_freezeTemp:-5,-4,-3,-2,-1,0,1,2,3,4,5 '
. 'ASC_shuttersDriveOffset '
. 'ASC_twilightDevice '
. 'ASC_expert:1 '
. $readingFnAttributes;
$hash->{NotifyOrderPrefix} = '51-'; # Order Nummer für NotifyFn
## Ist nur damit sich bei einem reload auch die Versionsnummer erneuert.
# foreach my $d ( sort keys %{ $modules{AutoShuttersControl}{defptr} } ) {
# my $hash = $modules{AutoShuttersControl}{defptr}{$d};
# $hash->{VERSION} = $version;
# }
}
## unserer packagename
package AutoShuttersControl;
use strict;
use warnings;
use POSIX;
use GPUtils qw(:all)
; # wird für den Import der FHEM Funktionen aus der fhem.pl benötigt
use Data::Dumper; #only for Debugging
use Date::Parse;
my $missingModul = '';
eval "use JSON qw(decode_json encode_json);1" or $missingModul .= 'JSON ';
## Import der FHEM Funktionen
BEGIN {
GP_Import(
qw(devspec2array
readingsSingleUpdate
readingsBulkUpdate
readingsBulkUpdateIfChanged
readingsBeginUpdate
readingsEndUpdate
defs
modules
Log3
CommandAttr
attr
CommandDeleteAttr
CommandDeleteReading
CommandSet
AttrVal
ReadingsVal
Value
IsDisabled
deviceEvents
init_done
addToDevAttrList
addToAttrList
delFromDevAttrList
delFromAttrList
gettimeofday
sunset_abs
sunrise_abs
InternalTimer
RemoveInternalTimer
computeAlignTime
ReplaceEventMap)
);
}
## Die Attributsliste welche an die Rolläden verteilt wird. Zusammen mit Default Werten
my %userAttrList = (
'ASC_Mode_Up:absent,always,off,home' => 'always',
'ASC_Mode_Down:absent,always,off,home' => 'always',
'ASC_Up:time,astro,brightness' => 'astro',
'ASC_Down:time,astro,brightness' => 'astro',
'ASC_AutoAstroModeMorning:REAL,CIVIL,NAUTIC,ASTRONOMIC,HORIZON' => 'none',
'ASC_AutoAstroModeMorningHorizon:-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9'
=> 'none',
'ASC_AutoAstroModeEvening:REAL,CIVIL,NAUTIC,ASTRONOMIC,HORIZON' => 'none',
'ASC_AutoAstroModeEveningHorizon:-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9'
=> 'none',
'ASC_Open_Pos:0,10,20,30,40,50,60,70,80,90,100' => [ '', 0, 100 ],
'ASC_Closed_Pos:0,10,20,30,40,50,60,70,80,90,100' => [ '', 100, 0 ],
'ASC_Pos_Reading' => [ '', 'position', 'pct' ],
'ASC_Time_Up_Early' => '04:30',
'ASC_Time_Up_Late' => '09:00',
'ASC_Time_Up_WE_Holiday' => '08:30',
'ASC_Time_Down_Early' => '15:30',
'ASC_Time_Down_Late' => '22:30',
'ASC_PrivacyDownTime_beforNightClose' => -1,
'ASC_PrivacyDown_Pos' => 50,
'ASC_WindowRec' => 'none',
'ASC_Ventilate_Window_Open:on,off' => 'on',
'ASC_LockOut:soft,hard,off' => 'off',
'ASC_LockOut_Cmd:inhibit,blocked,protection' => 'none',
'ASC_BlockingTime_afterManual' => 1200,
'ASC_BlockingTime_beforNightClose' => 3600,
'ASC_BlockingTime_beforDayOpen' => 3600,
'ASC_Brightness_Sensor' => 'none',
'ASC_Brightness_Reading' => 'brightness',
'ASC_Shading_Direction' => 180,
'ASC_Shading_Pos:10,20,30,40,50,60,70,80,90,100' => [ '', 80, 20 ],
'ASC_Shading_Mode:absent,always,off,home' => 'off',
'ASC_Shading_Angle_Left' => 75,
'ASC_Shading_Angle_Right' => 75,
'ASC_Shading_StateChange_Sunny' => 35000,
'ASC_Shading_StateChange_Cloudy' => 20000,
'ASC_Shading_Min_Elevation' => 25.0,
'ASC_Shading_Min_OutsideTemperature' => 18,
'ASC_Shading_WaitingPeriod' => 1200,
# 'ASC_Shading_Fast_Open:on,off' => 'none',
# 'ASC_Shading_Fast_Close:on,off' => 'none',
'ASC_Drive_Offset' => -1,
'ASC_Drive_OffsetStart' => -1,
'ASC_WindowRec_subType:twostate,threestate' => 'twostate',
'ASC_ShuttersPlace:window,terrace' => 'window',
'ASC_Ventilate_Pos:10,20,30,40,50,60,70,80,90,100' => [ '', 70, 30 ],
'ASC_ComfortOpen_Pos:0,10,20,30,40,50,60,70,80,90,100' => [ '', 20, 80 ],
'ASC_GuestRoom:on,off' => 'none',
'ASC_Antifreeze:off,soft,hard,am,pm' => 'off',
'ASC_Antifreeze_Pos:5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100'
=> [ '', 85, 15 ],
'ASC_Partymode:on,off' => 'off',
'ASC_Roommate_Device' => 'none',
'ASC_Roommate_Reading' => 'state',
'ASC_Self_Defense_Exclude:on,off' => 'off',
'ASC_BrightnessMinVal' => -1,
'ASC_BrightnessMaxVal' => -1,
'ASC_WiggleValue' => 5,
);
my %posSetCmds = (
ZWave => 'dim',
Siro => 'position',
CUL_HM => 'pct',
ROLLO => 'pct',
SOMFY => 'position',
tahoma => 'dim',
KLF200Node => 'pct',
DUOFERN => 'position',
HM485 => 'level',
);
my $shutters = new ASC_Shutters();
my $ascDev = new ASC_Dev();
sub Define($$) {
my ( $hash, $def ) = @_;
my @a = split( '[ \t][ \t]*', $def );
return 'only one AutoShuttersControl instance allowed'
if ( devspec2array('TYPE=AutoShuttersControl') > 1 )
; # es wird geprüft ob bereits eine Instanz unseres Modules existiert,wenn ja wird abgebrochen
return 'too few parameters: define <name> ShuttersControl' if ( @a != 2 );
return
'Cannot define ShuttersControl device. Perl modul '
. ${missingModul}
. 'is missing.'
if ($missingModul)
; # Abbruch wenn benötigte Hilfsmodule nicht vorhanden sind / vorerst unwichtig
my $name = $a[0];
$hash->{VERSION} = $version;
$hash->{MID} = 'da39a3ee5e6b4b0d3255bfef95601890afd80709'
; # eine Ein Eindeutige ID für interne FHEM Belange / nicht weiter wichtig
$hash->{NOTIFYDEV} = 'global,'
. $name; # Liste aller Devices auf deren Events gehört werden sollen
$ascDev->setName($name);
readingsSingleUpdate(
$hash,
'state',
'please set attribute ASC with value 1 or 2 in all auto controlled shutter devices and then execute \'set DEVICENAME scanForShutters\'',
1
);
CommandAttr( undef, $name . ' room ASC' )
if ( AttrVal( $name, 'room', 'none' ) eq 'none' );
CommandAttr( undef, $name . ' icon fts_shutter_automatic' )
if ( AttrVal( $name, 'icon', 'none' ) eq 'none' );
CommandAttr( undef, $name . ' ASC_autoAstroModeEvening REAL' )
if ( $ascDev->getAutoAstroModeEvening eq 'none' );
CommandAttr( undef, $name . ' ASC_autoAstroModeMorning REAL' )
if ( $ascDev->getAutoAstroModeMorning eq 'none' );
CommandAttr( undef, $name . ' ASC_autoShuttersControlMorning on' )
if ( $ascDev->getAutoShuttersControlMorning eq 'none' );
CommandAttr( undef, $name . ' ASC_autoShuttersControlEvening on' )
if ( $ascDev->getAutoShuttersControlEvening eq 'none' );
CommandAttr( undef, $name . ' ASC_temperatureReading temperature' )
if ( $ascDev->getTempReading eq 'none' );
CommandAttr( undef, $name . ' ASC_freezeTemp 3' )
if ( $ascDev->getFreezeTemp eq 'none' );
CommandAttr( undef,
$name
. ' devStateIcon selfeDefense.terrace:fts_door_tilt created.new.drive.timer:clock .*asleep:scene_sleeping roommate.(awoken|home):user_available residents.(home|awoken):status_available manual:fts_shutter_manual selfeDefense.active:status_locked selfeDefense.inactive:status_open day.open:scene_day night.close:scene_night shading.in:weather_sun shading.out:weather_cloudy'
) if ( AttrVal( $name, 'devStateIcon', 'none' ) eq 'none' );
addToAttrList('ASC:0,1,2');
Log3( $name, 3, "AutoShuttersControl ($name) - defined" );
$modules{AutoShuttersControl}{defptr}{ $hash->{MID} } = $hash;
return undef;
}
sub Undef($$) {
my ( $hash, $arg ) = @_;
my $name = $hash->{NAME};
UserAttributs_Readings_ForShutters( $hash, 'del' )
; # es sollen alle Attribute und Readings in den Rolläden Devices gelöscht werden welche vom Modul angelegt wurden
delFromAttrList('ASC:0,1,2');
delete( $modules{AutoShuttersControl}{defptr}{ $hash->{MID} } );
Log3( $name, 3, "AutoShuttersControl ($name) - delete device $name" );
return undef;
}
sub Attr(@) {
my ( $cmd, $name, $attrName, $attrVal ) = @_;
my $hash = $defs{$name};
return undef;
}
sub Notify($$) {
my ( $hash, $dev ) = @_;
my $name = $hash->{NAME};
my $devname = $dev->{NAME};
my $devtype = $dev->{TYPE};
my $events = deviceEvents( $dev, 1 );
return if ( !$events );
Log3( $name, 4,
"AutoShuttersControl ($name) - Devname: "
. $devname
. " Name: "
. $name
. " Notify: "
. Dumper $events); # mit Dumper
if (
(
grep /^DEFINED.$name$/,
@{$events} and $devname eq 'global' and $init_done
)
or (
grep /^INITIALIZED$/,
@{$events} or grep /^REREADCFG$/,
@{$events} or grep /^MODIFIED.$name$/,
@{$events}
)
and $devname eq 'global'
)
{
readingsSingleUpdate( $hash, 'partyMode', 'off', 0 )
if ( $ascDev->getPartyMode eq 'none' );
readingsSingleUpdate( $hash, 'hardLockOut', 'off', 0 )
if ( $ascDev->getHardLockOut eq 'none' );
readingsSingleUpdate( $hash, 'sunriseTimeWeHoliday', 'off', 0 )
if ( $ascDev->getSunriseTimeWeHoliday eq 'none' );
readingsSingleUpdate( $hash, 'selfDefense', 'off', 0 )
if ( $ascDev->getSelfDefense eq 'none' );
CommandDeleteReading( undef, $name . ' lockOut' )
if ( ReadingsVal( $name, 'lockOut', 'none' ) ne 'none' )
; # temporär ab Version 0.2.2
# Ist der Event ein globaler und passt zum Rest der Abfrage oben wird nach neuen Rolläden Devices gescannt und eine Liste im Rolladenmodul sortiert nach Raum generiert
ShuttersDeviceScan($hash)
unless ( ReadingsVal( $name, 'userAttrList', 'none' ) eq 'none' );
}
return
unless ( ref( $hash->{helper}{shuttersList} ) eq 'ARRAY'
and scalar( @{ $hash->{helper}{shuttersList} } ) > 0 );
my $posReading = $shutters->getPosCmd;
if ( $devname eq $name ) {
if ( grep /^userAttrList:.rolled.out$/, @{$events} ) {
unless ( scalar( @{ $hash->{helper}{shuttersList} } ) == 0 ) {
WriteReadingsShuttersList($hash);
UserAttributs_Readings_ForShutters( $hash, 'add' );
InternalTimer( gettimeofday() + 3,
'AutoShuttersControl::RenewSunRiseSetShuttersTimer',
$hash );
InternalTimer( gettimeofday() + 5,
'AutoShuttersControl::AutoSearchTwilightDev', $hash );
}
}
elsif ( grep /^partyMode:.off$/, @{$events} ) {
EventProcessingPartyMode($hash);
}
elsif ( grep /^sunriseTimeWeHoliday:.(on|off)$/, @{$events} ) {
RenewSunRiseSetShuttersTimer($hash);
}
}
elsif ( $devname eq "global" )
{ # Kommt ein globales Event und beinhaltet folgende Syntax wird die Funktion zur Verarbeitung aufgerufen
if (
grep
/^(ATTR|DELETEATTR)\s(.*ASC_Roommate_Device|.*ASC_WindowRec|.*ASC_residentsDevice|.*ASC_rainSensorDevice|.*ASC_Brightness_Sensor|.*ASC_twilightDevice)(\s.*|$)/,
@{$events}
)
{
EventProcessingGeneral( $hash, undef, join( ' ', @{$events} ) );
}
elsif (
grep
/^(ATTR|DELETEATTR)\s(.*ASC_Time_Up_WE_Holiday|.*ASC_Up|.*ASC_Down|.*ASC_AutoAstroModeMorning|.*ASC_AutoAstroModeMorningHorizon|.*ASC_AutoAstroModeEvening|.*ASC_AutoAstroModeEveningHorizon|.*ASC_Time_Up_Early|.*ASC_Time_Up_Late|.*ASC_Time_Down_Early|.*ASC_Time_Down_Late|.*ASC_autoAstroModeMorning|.*ASC_autoAstroModeMorningHorizon|.*ASC_PrivacyDownTime_beforNightClose|.*ASC_autoAstroModeEvening|.*ASC_autoAstroModeEveningHorizon)(\s.*|$)/,
@{$events}
)
{
EventProcessingGeneral( $hash, undef, join( ' ', @{$events} ) );
}
}
elsif ( grep /^($posReading):\s\d+$/, @{$events} ) {
EventProcessingShutters( $hash, $devname, join( ' ', @{$events} ) );
}
else {
EventProcessingGeneral( $hash, $devname, join( ' ', @{$events} ) )
; # bei allen anderen Events wird die entsprechende Funktion zur Verarbeitung aufgerufen
}
return;
}
sub EventProcessingGeneral($$$) {
my ( $hash, $devname, $events ) = @_;
my $name = $hash->{NAME};
if ( defined($devname) and ($devname) )
{ # es wird lediglich der Devicename der Funktion mitgegeben wenn es sich nicht um global handelt daher hier die Unterschiedung
while ( my ( $device, $deviceAttr ) =
each %{ $hash->{monitoredDevs}{$devname} } )
{
EventProcessingWindowRec( $hash, $device, $events )
if ( $deviceAttr eq 'ASC_WindowRec' )
; # ist es ein Fensterdevice wird die Funktion gestartet
EventProcessingRoommate( $hash, $device, $events )
if ( $deviceAttr eq 'ASC_Roommate_Device' )
; # ist es ein Bewohner Device wird diese Funktion gestartet
EventProcessingResidents( $hash, $device, $events )
if ( $deviceAttr eq 'ASC_residentsDevice' );
EventProcessingRain( $hash, $device, $events )
if ( $deviceAttr eq 'ASC_rainSensorDevice' );
EventProcessingTwilightDevice( $hash, $device, $events )
if ( $deviceAttr eq 'ASC_twilightDevice' );
$shutters->setShuttersDev($device)
if ( $deviceAttr eq 'ASC_Brightness_Sensor' );
if (
$deviceAttr eq 'ASC_Brightness_Sensor'
and ( $shutters->getDown eq 'brightness'
or $shutters->getUp eq 'brightness' )
)
{
EventProcessingBrightness( $hash, $device, $events );
}
elsif ( $deviceAttr eq 'ASC_Brightness_Sensor' ) {
EventProcessingShadingBrightness( $hash, $device, $events );
}
}
}
else { # alles was kein Devicenamen mit übergeben hat landet hier
if ( $events =~
m#^ATTR\s(.*)\s(ASC_Roommate_Device|ASC_WindowRec|ASC_residentsDevice|ASC_rainSensorDevice|ASC_Brightness_Sensor|ASC_twilightDevice)\s(.*)$#
)
{ # wurde den Attributen unserer Rolläden ein Wert zugewiesen ?
AddNotifyDev( $hash, $3, $1, $2 ) if ( $3 ne 'none' );
Log3( $name, 4,
"AutoShuttersControl ($name) - EventProcessing: ATTR" );
}
elsif ( $events =~
m#^DELETEATTR\s(.*)\s(ASC_Roommate_Device|ASC_WindowRec|ASC_residentsDevice|ASC_rainSensorDevice|ASC_Brightness_Sensor|ASC_twilightDevice)$#
)
{ # wurde das Attribut unserer Rolläden gelöscht ?
Log3( $name, 4,
"AutoShuttersControl ($name) - EventProcessing: DELETEATTR" );
DeleteNotifyDev( $hash, $1, $2 );
}
elsif ( $events =~
m#^ATTR\s(.*)\s(ASC_Time_Up_WE_Holiday|ASC_Up|ASC_Down|ASC_AutoAstroModeMorning|ASC_AutoAstroModeMorningHorizon|ASC_PrivacyDownTime_beforNightClose|ASC_AutoAstroModeEvening|ASC_AutoAstroModeEveningHorizon|ASC_Time_Up_Early|ASC_Time_Up_Late|ASC_Time_Down_Early|ASC_Time_Down_Late)\s(.*)$#
)
{
CreateSunRiseSetShuttersTimer( $hash, $1 )
if (
$2 ne 'ASC_Time_Up_WE_Holiday'
or ( $2 eq 'ASC_Time_Up_WE_Holiday'
and $ascDev->getSunriseTimeWeHoliday eq 'on' )
);
}
elsif ( $events =~
m#^ATTR\s(.*)\s(ASC_autoAstroModeMorning|ASC_autoAstroModeMorningHorizon|ASC_autoAstroModeEvening|ASC_autoAstroModeEveningHorizon)\s(.*)$#
)
{
RenewSunRiseSetShuttersTimer($hash);
}
}
}
sub Set($$@) {
my ( $hash, $name, @aa ) = @_;
my ( $cmd, @args ) = @aa;
if ( lc $cmd eq 'renewsetsunrisesunsettimer' ) {
return "usage: $cmd" if ( @args != 0 );
RenewSunRiseSetShuttersTimer($hash);
}
elsif ( lc $cmd eq 'scanforshutters' ) {
return "usage: $cmd" if ( @args != 0 );
ShuttersDeviceScan($hash);
}
elsif ( lc $cmd eq 'createnewnotifydev' ) {
return "usage: $cmd" if ( @args != 0 );
CreateNewNotifyDev($hash);
}
elsif ( lc $cmd eq 'partymode' ) {
return "usage: $cmd" if ( @args > 1 );
readingsSingleUpdate( $hash, $cmd, join( ' ', @args ), 1 )
if ( join( ' ', @args ) ne ReadingsVal($name,'partyMode',0) );
}
elsif ( lc $cmd eq 'hardlockout' ) {
return "usage: $cmd" if ( @args > 1 );
readingsSingleUpdate( $hash, $cmd, join( ' ', @args ), 1 );
HardewareBlockForShutters( $hash, join( ' ', @args ) );
}
elsif ( lc $cmd eq 'sunrisetimeweholiday' ) {
return "usage: $cmd" if ( @args > 1 );
readingsSingleUpdate( $hash, $cmd, join( ' ', @args ), 1 );
}
elsif ( lc $cmd eq 'selfdefense' ) {
return "usage: $cmd" if ( @args > 1 );
readingsSingleUpdate( $hash, $cmd, join( ' ', @args ), 1 );
}
elsif ( lc $cmd eq 'wiggle' ) {
return "usage: $cmd" if ( @args > 1 );
( $args[0] eq 'all' ? wiggleAll($hash) : wiggle( $hash, $args[0] ) );
}
else {
my $list = "scanForShutters:noArg";
$list .=
" renewSetSunriseSunsetTimer:noArg partyMode:on,off hardLockOut:on,off sunriseTimeWeHoliday:on,off selfDefense:on,off wiggle:all,"
. join( ',', @{ $hash->{helper}{shuttersList} } )
if ( ReadingsVal( $name, 'userAttrList', 'none' ) eq 'rolled out' );
$list .= " createNewNotifyDev:noArg"
if ( ReadingsVal( $name, 'userAttrList', 'none' ) eq 'rolled out'
and AttrVal( $name, 'ASC_expert', 0 ) == 1 );
return "Unknown argument $cmd,choose one of $list";
}
return undef;
}
sub Get($$@) {
my ( $hash, $name, @aa ) = @_;
my ( $cmd, @args ) = @aa;
if ( lc $cmd eq 'showshuttersinformations' ) {
return "usage: $cmd" if ( @args != 0 );
my $ret = GetShuttersInformation($hash);
return $ret;
}
elsif ( lc $cmd eq 'shownotifydevsinformations' ) {
return "usage: $cmd" if ( @args != 0 );
my $ret = GetMonitoredDevs($hash);
return $ret;
}
else {
my $list = "";
$list .= " showShuttersInformations:noArg"
if ( ReadingsVal( $name, 'userAttrList', 'none' ) eq 'rolled out' );
$list .= " showNotifyDevsInformations:noArg"
if ( ReadingsVal( $name, 'userAttrList', 'none' ) eq 'rolled out'
and AttrVal( $name, 'ASC_expert', 0 ) == 1 );
return "Unknown argument $cmd,choose one of $list";
}
}
sub ShuttersDeviceScan($) {
my $hash = shift;
my $name = $hash->{NAME};
delete $hash->{helper}{shuttersList};
my @list;
@list = devspec2array('ASC=[1-2]');
CommandDeleteReading( undef, $name . ' .*_nextAstroTimeEvent' );
unless ( scalar(@list) > 0 ) {
readingsBeginUpdate($hash);
readingsBulkUpdate( $hash, 'userAttrList', 'none' );
readingsBulkUpdate( $hash, 'state', 'no shutters found' );
readingsEndUpdate( $hash, 1 );
return;
}
my $shuttersList = '';
foreach (@list) {
push( @{ $hash->{helper}{shuttersList} }, $_ )
; ## einem Hash wird ein Array zugewiesen welches die Liste der erkannten Rollos beinhaltet
delFromDevAttrList( $_, 'ASC_lock-out:soft,hard' )
; # temporär muss später gelöscht werden ab Version 0.2.0.6
delFromDevAttrList( $_, 'ASC_lock-outCmd:inhibit,blocked' )
; # temporär muss später gelöscht werden ab Version 0.2.0.6
delFromDevAttrList( $_,
'ASC_Pos_after_ComfortOpen:0,10,20,30,40,50,60,70,80,90,100' )
; # temporär muss später gelöscht werden ab Version 0.2.0.6
delFromDevAttrList( $_, 'ASC_Antifreeze:off,on' )
if ( AttrVal( $_, 'ASC_Antifreeze', 'on' ) eq 'on'
or AttrVal( $_, 'ASC_Antifreeze', 'on' ) eq 'off' )
; # temporär muss später gelöscht werden ab Version 0.2.0.6
delFromDevAttrList( $_,
'ASC_AntifreezePos:5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100'
); # temporär muss später gelöscht werden ab Version 0.2.0.7
delFromDevAttrList( $_, 'ASC_LockOut_Cmd:inhibit,blocked' )
if ( AttrVal( $_, 'ASC_LockOut_Cmd', 'none' ) eq 'none' )
; # temporär muss später gelöscht werden ab Version 0.2.0.10
delFromDevAttrList( $_, 'ASC_Shading_Brightness_Sensor' )
; # temporär muss später gelöscht werden ab Version 0.2.0.12
delFromDevAttrList( $_, 'ASC_Shading_Brightness_Reading' )
; # temporär muss später gelöscht werden ab Version 0.2.0.12
$shuttersList = $shuttersList . ',' . $_;
$shutters->setShuttersDev($_);
$shutters->setLastManPos( $shutters->getStatus );
$shutters->setLastPos( $shutters->getStatus );
$shutters->setDelayCmd('none');
$shutters->setNoOffset(0);
$shutters->setPosSetCmd( $posSetCmds{ $defs{$_}->{TYPE} } );
$shutters->setShading('out');
}
# $hash->{NOTIFYDEV} = $hash->{NOTIFYDEV} . $shuttersList;
$hash->{NOTIFYDEV} = "global," . $name . $shuttersList;
if ( $ascDev->getMonitoredDevs ne 'none' ) {
$hash->{monitoredDevs} =
eval { decode_json( $ascDev->getMonitoredDevs ) };
my $notifyDevString = $hash->{NOTIFYDEV};
while ( each %{ $hash->{monitoredDevs} } ) {
$notifyDevString .= ',' . $_;
}
$hash->{NOTIFYDEV} = $notifyDevString;
}
readingsSingleUpdate( $hash, 'userAttrList', 'rolled out', 1 );
}
## Die Funktion schreibt in das Moduldevice Readings welche Rolläden in welchen Räumen erfasst wurden.
sub WriteReadingsShuttersList($) {
my $hash = shift;
my $name = $hash->{NAME};
CommandDeleteReading( undef, $name . ' room_.*' );
readingsBeginUpdate($hash);
foreach ( @{ $hash->{helper}{shuttersList} } ) {
readingsBulkUpdate(
$hash,
'room_' . makeReadingName( AttrVal( $_, 'room', 'unsorted' ) ),
ReadingsVal(
$name,
'room_' . makeReadingName( AttrVal( $_, 'room', 'unsorted' ) ),
''
)
. ','
. $_
)
if (
ReadingsVal(
$name,
'room_' . makeReadingName( AttrVal( $_, 'room', 'unsorted' ) ),
'none'
) ne 'none'
);
readingsBulkUpdate( $hash,
'room_' . makeReadingName( AttrVal( $_, 'room', 'unsorted' ) ), $_ )
if (
ReadingsVal(
$name,
'room_' . makeReadingName( AttrVal( $_, 'room', 'unsorted' ) ),
'none'
) eq 'none'
);
}
readingsBulkUpdate( $hash, 'state', 'active' );
readingsEndUpdate( $hash, 0 );
}
sub UserAttributs_Readings_ForShutters($$) {
my ( $hash, $cmd ) = @_;
my $name = $hash->{NAME};
while ( my ( $attrib, $attribValue ) = each %{userAttrList} ) {
foreach ( @{ $hash->{helper}{shuttersList} } ) {
addToDevAttrList( $_, $attrib )
; ## fhem.pl bietet eine Funktion um ein userAttr Attribut zu befüllen. Wir schreiben also in den Attribut userAttr alle unsere Attribute rein. Pro Rolladen immer ein Attribut pro Durchlauf
## Danach werden die Attribute die im userAttr stehen gesetzt und mit default Werten befüllt
if ( $cmd eq 'add' ) {
if ( ref($attribValue) ne 'ARRAY' ) {
$attr{$_}{ ( split( ':', $attrib ) )[0] } = $attribValue
if (
not
defined( $attr{$_}{ ( split( ':', $attrib ) )[0] } ) );
}
else {
$attr{$_}{ ( split( ':', $attrib ) )[0] } =
$attribValue->[ AttrVal( $_, 'ASC', 2 ) ]
if (
not
defined( $attr{$_}{ ( split( ':', $attrib ) )[0] } ) );
}
## Oder das Attribut wird wieder gelöscht.
}
elsif ( $cmd eq 'del' ) {
$shutters->setShuttersDev($_);
RemoveInternalTimer( $shutters->getInTimerFuncHash );
CommandDeleteReading( undef,
$_ . ' .?(AutoShuttersControl|ASC)_.*' );
CommandDeleteAttr( undef, $_ . ' ASC' );
delFromDevAttrList( $_, $attrib );
}
}
}
}
## Fügt dem NOTIFYDEV Hash weitere Devices hinzu
sub AddNotifyDev($@) {
my ( $hash, $dev, $shuttersDev, $shuttersAttr ) = @_;
my $name = $hash->{NAME};
my $notifyDev = $hash->{NOTIFYDEV};
$notifyDev = "" if ( !$notifyDev );
my %hash;
%hash = map { ( $_ => 1 ) }
split( ",", "$notifyDev,$dev" );
$hash->{NOTIFYDEV} = join( ",", sort keys %hash );
my @devs = split( ',', $dev );
foreach (@devs) {
$hash->{monitoredDevs}{$_}{$shuttersDev} = $shuttersAttr;
}
readingsSingleUpdate( $hash, '.monitoredDevs',
eval { encode_json( $hash->{monitoredDevs} ) }, 0 );
}
## entfernt aus dem NOTIFYDEV Hash Devices welche als Wert in Attributen steckten
sub DeleteNotifyDev($@) {
my ( $hash, $shuttersDev, $shuttersAttr ) = @_;
my $name = $hash->{NAME};
my $notifyDevs =
ExtractNotifyDevFromEvent( $hash, $shuttersDev, $shuttersAttr );
foreach my $notifyDev ( keys( %{$notifyDevs} ) ) {
Log3( $name, 4,
"AutoShuttersControl ($name) - DeleteNotifyDev - NotifyDev: "
. $_ );
delete $hash->{monitoredDevs}{$notifyDev}{$shuttersDev};
if ( !keys %{ $hash->{monitoredDevs}{$notifyDev} } ) {
delete $hash->{monitoredDevs}{$notifyDev};
my $notifyDevString = $hash->{NOTIFYDEV};
$notifyDevString = "" if ( !$notifyDevString );
my %hash;
%hash = map { ( $_ => 1 ) }
grep { " $notifyDev " !~ m/ $_ / }
split( ",", "$notifyDevString,$notifyDev" );
$hash->{NOTIFYDEV} = join( ",", sort keys %hash );
}
}
readingsSingleUpdate( $hash, '.monitoredDevs',
eval { encode_json( $hash->{monitoredDevs} ) }, 0 );
}
## Sub zum steuern der Rolläden bei einem Fenster Event
sub EventProcessingWindowRec($@) {
my ( $hash, $shuttersDev, $events ) = @_;
my $name = $hash->{NAME};
if ( $events =~ m#state:\s(open(ed)?|closed|tilted)# # weitere mögliche Events (opened / closed)
and IsAfterShuttersManualBlocking($shuttersDev) )
{
$shutters->setShuttersDev($shuttersDev);
my $homemode = $shutters->getRoommatesStatus;
$homemode = $ascDev->getResidentsStatus if ( $homemode eq 'none' );
#### Hardware Lock der Rollläden
$shutters->setHardLockOut('off')
if ( $1 eq 'closed' and $shutters->getShuttersPlace eq 'terrace' );
$shutters->setHardLockOut('on')
if ( ($1 eq 'open' or $1 eq 'opened') and $shutters->getShuttersPlace eq 'terrace' );
$shutters->setNoOffset(1);
my $queryShuttersPosWinRecTilted = (
$shutters->getShuttersPosCmdValueNegate
? $shutters->getStatus > $shutters->getVentilatePos
: $shutters->getStatus < $shutters->getVentilatePos
);
my $queryShuttersPosWinRecComfort = (
$shutters->getShuttersPosCmdValueNegate
? $shutters->getStatus > $shutters->getComfortOpenPos
: $shutters->getStatus < $shutters->getComfortOpenPos
);
# ## Wird erstmal deaktiviert da es Sinnlos ist in meinen Augen
# if ( $shutters->getDelayCmd ne 'none' and $1 eq 'closed' )
# { # Es wird geschaut ob wärend der Fenster offen Phase ein Fahrbefehl über das Modul kam,wenn ja wird dieser aus geführt
# $shutters->setLastDrive('delayed drive - window closed');
# ShuttersCommandSet( $hash, $shuttersDev, $shutters->getDelayCmd );
# }
if ( $1 eq 'closed'
and IsAfterShuttersTimeBlocking( $hash, $shuttersDev )
and ($shutters->getModeDown eq $homemode
or ( $shutters->getModeDown eq 'absent'
and $homemode eq 'gone' )
or $shutters->getModeDown eq 'always') )
{
if ( $shutters->getStatus == $shutters->getVentilatePos
or $shutters->getStatus == $shutters->getComfortOpenPos
or $shutters->getStatus == $shutters->getOpenPos )
{
my $homemode = $shutters->getRoommatesStatus;
$homemode = $ascDev->getResidentsStatus
if ( $homemode eq 'none' );
if (
IsDay( $hash, $shuttersDev )
and $shutters->getStatus != $shutters->getOpenPos
and ( $homemode ne 'asleep'
or $homemode ne 'gotosleep'
or $homemode eq 'none' )
)
{
$shutters->setLastDrive('window day closed');
ShuttersCommandSet( $hash, $shuttersDev,
$shutters->getLastPos );
}
elsif (not IsDay( $hash, $shuttersDev )
or $homemode eq 'asleep'
or $homemode eq 'gotosleep' )
{
$shutters->setLastDrive('window night closed');
ShuttersCommandSet( $hash, $shuttersDev,
$shutters->getClosedPos );
}
}
}
elsif (
(
$1 eq 'tilted'
or ( ($1 eq 'open' or $1 eq 'opened') and $shutters->getSubTyp eq 'twostate' )
)
and $shutters->getVentilateOpen eq 'on'
and $queryShuttersPosWinRecTilted
)
{
$shutters->setLastDrive('ventilate - window open');
ShuttersCommandSet( $hash, $shuttersDev,
$shutters->getVentilatePos );
}
elsif ( ($1 eq 'open' or $1 eq 'opened')
and $shutters->getSubTyp eq 'threestate'
and $ascDev->getAutoShuttersControlComfort eq 'on'
and $queryShuttersPosWinRecComfort )
{
$shutters->setLastDrive('comfort - window open');
ShuttersCommandSet( $hash, $shuttersDev,
$shutters->getComfortOpenPos );
}
}
}
## Sub zum steuern der Rolladen bei einem Bewohner/Roommate Event
sub EventProcessingRoommate($@) {
my ( $hash, $shuttersDev, $events ) = @_;
my $name = $hash->{NAME};
$shutters->setShuttersDev($shuttersDev);
my $reading = $shutters->getRoommatesReading;
if ( $events =~ m#$reading:\s(absent|gotosleep|asleep|awoken|home)# ) {
Log3( $name, 4,
"AutoShuttersControl ($name) - EventProcessingRoommate: "
. $shutters->getRoommatesReading );
Log3( $name, 4,
"AutoShuttersControl ($name) - EventProcessingRoommate: $shuttersDev und Events $events"
);
if (
( $1 eq 'home' or $1 eq 'awoken' )
and ( $shutters->getRoommatesStatus eq 'home'
or $shutters->getRoommatesStatus eq 'awoken' )
and $ascDev->getAutoShuttersControlMorning eq 'on'
and ( $shutters->getModeUp eq 'always'
or $shutters->getModeUp eq 'home' )
)
{
Log3( $name, 4,
"AutoShuttersControl ($name) - EventProcessingRoommate_1: $shuttersDev und Events $events"
);
if (
(
$shutters->getRoommatesLastStatus eq 'asleep'
or $shutters->getRoommatesLastStatus eq 'awoken'
)
and IsDay( $hash, $shuttersDev )
and IsAfterShuttersTimeBlocking( $hash, $shuttersDev )
)
{
Log3( $name, 4,
"AutoShuttersControl ($name) - EventProcessingRoommate_2: $shuttersDev und Events $events"
);
$shutters->setLastDrive('roommate awoken');
ShuttersCommandSet( $hash, $shuttersDev,
$shutters->getOpenPos );
}
if (
(
$shutters->getRoommatesLastStatus eq 'absent'
or $shutters->getRoommatesLastStatus eq 'gone'
or $shutters->getRoommatesLastStatus eq 'home'
)
and ( $shutters->getModeUp eq 'home'
or $shutters->getModeUp eq 'always'
or $shutters->getModeDown eq 'home'
or $shutters->getModeDown eq 'always' )
and $shutters->getRoommatesStatus eq 'home'
)
{
if ( not IsDay( $hash, $shuttersDev )
and IsAfterShuttersTimeBlocking( $hash, $shuttersDev ) )
{
my $position;
$shutters->setLastDrive('roommate home');
if ( CheckIfShuttersWindowRecOpen($shuttersDev) == 0
or $shutters->getVentilateOpen eq 'off' )
{
$position = $shutters->getClosedPos;
}
else {
$position = $shutters->getVentilatePos;
$shutters->setLastDrive(
$shutters->getLastDrive . ' - ventilate mode' );
}
ShuttersCommandSet( $hash, $shuttersDev, $position );
}
elsif ( IsDay( $hash, $shuttersDev )
and $shutters->getStatus == $shutters->getClosedPos
and IsAfterShuttersTimeBlocking( $hash, $shuttersDev ) )
{
$shutters->setLastDrive('roommate home');
ShuttersCommandSet( $hash, $shuttersDev,
$shutters->getOpenPos );
}
}
}
elsif (
(
$shutters->getModeDown eq 'always'
or $shutters->getModeDown eq 'home'
)
and ( $1 eq 'gotosleep' or $1 eq 'asleep' )
and $ascDev->getAutoShuttersControlEvening eq 'on'
)
{
my $position;
$shutters->setLastDrive('roommate asleep');
if ( CheckIfShuttersWindowRecOpen($shuttersDev) == 0
or $shutters->getVentilateOpen eq 'off' )
{
$position = $shutters->getClosedPos;
}
else {
$position = $shutters->getVentilatePos;
$shutters->setLastDrive(
$shutters->getLastDrive . ' - ventilate mode' );
}
ShuttersCommandSet( $hash, $shuttersDev, $position );
}
elsif ( $shutters->getModeDown eq 'absent'
and $1 eq 'absent'
and not IsDay( $hash, $shuttersDev ) )
{
$shutters->setLastDrive('roommate absent');
ShuttersCommandSet( $hash, $shuttersDev, $shutters->getClosedPos );
}
}
}
sub EventProcessingResidents($@) {
my ( $hash, $device, $events ) = @_;
my $name = $device;
my $reading = $ascDev->getResidentsReading;
if ( $events =~ m#$reading:\s(absent)# ) {
foreach my $shuttersDev ( @{ $hash->{helper}{shuttersList} } ) {
$shutters->setShuttersDev($shuttersDev);
$shutters->setHardLockOut('off');