forked from simatec/ioBroker.shuttercontrol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
1754 lines (1527 loc) · 91.1 KB
/
main.js
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
/* jshint -W097 */
/* jshint strict: false */
/*jslint node: true */
'use strict';
// @ts-ignore
const utils = require('@iobroker/adapter-core');
// @ts-ignore
const schedule = require('node-schedule');
// @ts-ignore
const SunCalc = require('suncalc2');
const sunProtect = require('./lib/sunProtect.js'); // SunProtect
const triggerChange = require('./lib/triggerChange.js'); // triggerChange
const elevationDown = require('./lib/elevationDown.js'); // elevationDown
const shutterGoldenHour = require('./lib/shutterGoldenHour.js'); // shutterGoldenHour
const shutterUpLiving = require('./lib/shutterUpLiving.js'); // shutterUpLiving
const shutterSunriseSunset = require('./lib/shutterSunriseSunset.js'); // shutterSunriseSunset
const shutterDownLiving = require('./lib/shutterDownLiving.js'); // shutterDownLiving
const shutterUpSleep = require('./lib/shutterUpSleep.js'); // shutterUpSleep
const shutterDownLate = require('./lib/shutterDownLate.js'); // shutterDownLate
const shutterDownChildren = require('./lib/shutterDownChildren.js'); // shutterDownChildren
const shutterUpChildren = require('./lib/shutterUpChildren.js'); // shutterUpChildren
const shutterDownSleep = require('./lib/shutterDownSleep.js'); // shutterDownSleep
const buttonAction = require('./lib/buttonAction.js'); // buttonAction
const shutterState = require('./lib/shutterState.js'); // shutterState
const shutterDownComplete = require('./lib/shutterDownComplete.js'); // shutterDownComplete
const shutterBrightnessSensor = require('./lib/shutterBrightnessSensor.js').shutterBrightnessSensor; // shutterBrightnessSensor
const brightnessState = require('./lib/shutterBrightnessSensor.js').brightnessState; // brightnessState
const shutterAlarm = require('./lib/shutterAlarm.js').shutterAlarm; // ShutterAlarm
let adapter;
const adapterName = require('./package.json').name.split('.').pop();
let autoLivingStr, autoSleepStr, autoChildrenStr, delayUp, delayUpChildren, delayDown, delayDownChildren, resTriggerChange, shutterSettings;
let astroTimeLivingUp, astroTimeLivingDown, astroTimeSleepUp, astroTimeSleepDown, astroTimeChildrenUp, astroTimeChildrenDown;
let timer, timerSleep;
let resTrigger = [];
let resSunInsideTemp = [];
let resSunOutsideTemp = [];
let resSunLight = [];
let ObjautoUp = [];
let ObjautoDown = [];
let ObjautoSun = [];
let ObjautoState = [];
let ObjautoLevel = [];
let resShutterState = [];
let waitTime4StateCheck = 100;
let brightnessDown = false;
// +++++++++++++++++++++++++++ Starts the adapter instance ++++++++++++++++++++++++++++++++
function startAdapter(options) {
options = options || {};
Object.assign(options, { name: adapterName });
adapter = new utils.Adapter(options);
// start here!
adapter.on('ready', () => main(adapter));
// +++++++++++++++++++++++++ is called when adapter shuts down +++++++++++++++++++++++++
adapter.on('unload', (callback) => {
try {
adapter.log.info('cleaned everything up...');
clearTimeout(timer);
clearTimeout(timerSleep);
schedule.cancelJob('shutterUpGoldenHourEnd');
schedule.cancelJob('calcTimer');
schedule.cancelJob('shutterDownGoldenHour');
schedule.cancelJob('shutterUpSunrise');
schedule.cancelJob('shutterDownSunset');
schedule.cancelJob('shutterUpLiving');
schedule.cancelJob('shutterDownLiving');
schedule.cancelJob('shutterUpSleep');
schedule.cancelJob('shutterDownLate');
schedule.cancelJob('shutterDownComplete');
schedule.cancelJob('shutterDownSleep');
schedule.cancelJob('calcPosTimer');
schedule.cancelJob('shutterUpChildren');
schedule.cancelJob('shutterDownChildren');
callback();
} catch (e) {
callback(e);
}
});
// ++++++++++++++++++ is called if a subscribed state changes ++++++++++++++++++
adapter.on('stateChange', async (id, state) => {
if (state) {
if (adapter.config.HolidayDP !== '') {
if (id.includes(adapter.config.HolidayDP)) {
adapter.log.debug('HolidayDP changed to ' + state.val);
await adapter.setStateAsync('control.Holiday', { val: state.val, ack: true })
.catch((e) => adapter.log.warn(e));
}
}
if (adapter.config.schoolfreeDP !== '') {
if (id.includes(adapter.config.schoolfreeDP)) {
adapter.log.debug('schoolfreeDP changed to ' + state.val);
await adapter.setStateAsync('control.schoolfree', { val: state.val, ack: true })
.catch((e) => adapter.log.warn(e));
}
}
if (id === adapter.namespace + '.control.Holiday') {
HolidayStr = state.val;
shutterDriveCalc();
}
if (id === adapter.namespace + '.control.schoolfree') {
SchoolfreeStr = state.val;
shutterDriveCalc();
}
if (id === adapter.namespace + '.control.autoLiving') {
autoLivingStr = state.val;
shutterDriveCalc();
}
if (id === adapter.namespace + '.control.autoSleep') {
autoSleepStr = state.val;
shutterDriveCalc();
}
if (id === adapter.namespace + '.control.autoChildren') {
autoChildrenStr = state.val;
shutterDriveCalc();
}
if (adapter.config.publicHolidays === true) {
if (id === adapter.config.publicHolInstance + '.heute.boolean') {
publicHolidayStr = state.val;
shutterDriveCalc();
}
if (id === adapter.config.publicHolInstance + '.morgen.boolean') {
publicHolidayTomorowStr = state.val;
shutterDriveCalc();
}
}
if (adapter.config.schoolfree === true) {
if (id === adapter.config.schoolfreeInstance + '.info.today') {
schoolfreeStr = state.val;
shutterDriveCalc();
}
if (id === adapter.config.schoolfreeInstance + '.info.tomorrow') {
schoolfreeTomorowStr = state.val;
shutterDriveCalc();
}
}
if (id === adapter.config.triggerAutoLiving) {
await adapter.setStateAsync('control.autoLiving', { val: state.val, ack: true })
.catch((e) => adapter.log.warn(e));
adapter.log.debug('Auto Living is: ' + state.val);
}
if (id === adapter.config.triggerAutoSleep) {
await adapter.setStateAsync('control.autoSleep', { val: state.val, ack: true })
.catch((e) => adapter.log.warn(e));
adapter.log.debug('Auto Sleep is: ' + state.val);
}
if (id === adapter.config.triggerAutoChildren) {
await adapter.setStateAsync('control.autoChildren', { val: state.val, ack: true })
.catch((e) => adapter.log.warn(e));
adapter.log.debug('Auto Children is: ' + state.val);
}
if (id === adapter.config.lightsensorUpDown) {
shutterBrightnessSensor(adapter, state.val, shutterSettings, brightnessDown);
adapter.log.debug('Brightness sensor value: ' + state.val);
await sleep(10000);
brightnessDown = brightnessState(adapter, state.val, brightnessDown);
adapter.log.debug('Brightness State Down is: ' + brightnessDown);
}
if (id === adapter.config.alarmWind1) {
adapter.log.debug('Alarm Wind 1 changed: ' + state.val);
shutterAlarm(adapter, 'alarmWind1', shutterSettings);
}
if (id === adapter.config.alarmWind2) {
adapter.log.debug('Alarm Wind 2 changed: ' + state.val);
shutterAlarm(adapter, 'alarmWind2', shutterSettings);
}
if (id === adapter.config.alarmRain) {
adapter.log.debug('Alarm Rain changed: ' + state.val);
shutterAlarm(adapter, 'alarmRain', shutterSettings);
}
if (id === adapter.config.alarmFrost) {
adapter.log.debug('Alarm Frost changed: ' + state.val);
shutterAlarm(adapter, 'alarmFrost', shutterSettings);
}
if (id === adapter.config.alarmFire) {
adapter.log.debug('Alarm Fire changed: ' + state.val);
shutterAlarm(adapter, 'alarmFire', shutterSettings);
}
resTrigger.forEach(async function (resultTriggerID) {
if (id === resultTriggerID && state.ts === state.lc) {
resTriggerChange = resultTriggerID;
adapter.log.debug('TriggerID changed: ' + resultTriggerID + ' Value: ' + state.val);
triggerChange(resTriggerChange, adapter, shutterSettings);
}
});
resSunInsideTemp.forEach(async function (resSunInsideTempID) {
if (id === resSunInsideTempID && state.ts === state.lc) {
adapter.log.debug('insidetemperature changed: ' + resSunInsideTempID + ' Value: ' + state.val);
sunProtect(adapter, elevation, azimuth, shutterSettings);
}
});
resSunOutsideTemp.forEach(async function (resSunOutsideTempID) {
if (id === resSunOutsideTempID && state.ts === state.lc) {
adapter.log.debug('outsidetemperature changed: ' + resSunOutsideTempID + ' Value: ' + state.val);
sunProtect(adapter, elevation, azimuth, shutterSettings);
}
});
resSunLight.forEach(async function (resSunLightID) {
if (id === resSunLightID && state.ts === state.lc) {
adapter.log.debug('Lightsensor changed: ' + resSunLightID + ' Value: ' + state.val);
sunProtect(adapter, elevation, azimuth, shutterSettings);
}
});
resShutterState.forEach(async function (resShutterID) {
if (id === resShutterID && state.ts === state.lc) {
const result = shutterSettings.filter((/** @type {{ name: any; }} */ d) => d.name == resShutterID);
if (adapter.config.currentShutterState == true && adapter.config.currentShutterStateTime) {
waitTime4StateCheck = (adapter.config.currentShutterStateTime ? adapter.config.currentShutterStateTime * 1000 : 60000);
}
await sleep(waitTime4StateCheck);
for (const i in result) {
for (const s in shutterSettings) {
if (shutterSettings[s].shutterName == result[i].shutterName) {
const nameDevice = shutterSettings[s].shutterName.replace(/[.;, ]/g, '_');
const _shutterState = await adapter.getForeignStateAsync(shutterSettings[s].name).catch((e) => adapter.log.warn(e));
if (typeof _shutterState != undefined && _shutterState != null && shutterSettings[s].oldHeight != _shutterState.val) {
adapter.log.debug('Shutter state changed: ' + shutterSettings[s].shutterName + ' old value = ' + shutterSettings[s].oldHeight + ' new value = ' + _shutterState.val);
}
if (typeof _shutterState != undefined && _shutterState != null && _shutterState.val != shutterSettings[s].currentHeight && _shutterState.val != shutterSettings[s].oldHeight && adapter.config.currentShutterState == true) {
//await sleep(waitTime4StateCheck);
shutterSettings[s].currentAction = 'Manu_Mode';
shutterSettings[s].triggerAction = 'Manu_Mode';
await adapter.setStateAsync('shutters.autoState.' + nameDevice, { val: shutterSettings[s].currentAction, ack: true })
.catch((e) => adapter.log.warn(e));
adapter.log.debug(shutterSettings[s].shutterName + ' drived manually to ' + _shutterState.val + '. Old value = ' + shutterSettings[s].oldHeight + '. New value = ' + _shutterState.val);
adapter.log.debug(shutterSettings[s].shutterName + ' Updated trigger action to ' + shutterSettings[s].triggerAction + ' to prevent moving after window close ');
shutterState(shutterSettings[s].name, adapter, shutterSettings);
} else if (typeof _shutterState != undefined && _shutterState != null && _shutterState.val != shutterSettings[s].currentHeight && _shutterState.val != shutterSettings[s].oldHeight && adapter.config.currentShutterState == false) {
shutterSettings[s].currentAction = 'Manu_Mode';
shutterSettings[s].triggerAction = 'Manu_Mode';
await adapter.setStateAsync('shutters.autoState.' + nameDevice, { val: shutterSettings[s].currentAction, ack: true })
.catch((e) => adapter.log.warn(e));
adapter.log.debug(shutterSettings[s].shutterName + ' Updated trigger action to ' + shutterSettings[s].triggerAction + ' to prevent moving after window close ');
adapter.log.debug(shutterSettings[s].shutterName + ' drived manually to ' + _shutterState.val + '. Old value = ' + shutterSettings[s].oldHeight + '. New value = ' + _shutterState.val);
shutterState(shutterSettings[s].name, adapter, shutterSettings);
} else if (typeof _shutterState != undefined && _shutterState != null && _shutterState.val == shutterSettings[s].currentHeight) {
adapter.log.debug(shutterSettings[s].shutterName + ' Old value = ' + shutterSettings[s].oldHeight + '. New value = ' + _shutterState.val + '. automatic is active');
shutterState(shutterSettings[s].name, adapter, shutterSettings);
}
await sleep(5000);
saveCurrentStates(false);
//Shutter is closed -> opened manually to heightUp (should be 100% or 0%) before it has been opened automatically -> enable possibility to activate sunprotect height if required --> if sunprotect is required: shutter is set to sunProtect height
if (shutterSettings[s].firstCompleteUp == true && state.val == shutterSettings[s].heightUp && shutterSettings[s].currentAction != 'up' && shutterSettings[s].currentAction != 'triggered' && shutterSettings[s].currentAction != 'triggered_Tilted') {
shutterSettings[s].currentHeight = state.val;
shutterSettings[s].currentAction = 'none'; //reset mode. e.g. mode can be set to sunProtect later if window is closed
shutterSettings[s].firstCompleteUp = false;
await adapter.setStateAsync('shutters.autoState.' + nameDevice, { val: shutterSettings[s].currentAction, ack: true })
.catch((e) => adapter.log.warn(e));
await adapter.setStateAsync('shutters.autoLevel.' + nameDevice, { val: parseFloat(shutterSettings[s].currentHeight), ack: true })
.catch((e) => adapter.log.warn(e));
adapter.log.debug(shutterSettings[s].shutterName + ' opened manually to ' + shutterSettings[s].heightUp + '. Old value = ' + shutterSettings[s].oldHeight + '. New value = ' + state.val + '. Possibility to activate sunprotect enabled.');
}
if (shutterSettings[s].firstCompleteUp == true && shutterSettings[s].currentAction != 'triggered' && shutterSettings[s].currentAction != 'triggered_Tilted' && shutterSettings[s].currentAction != 'none' && (state.val == shutterSettings[s].heightUp || state.val == shutterSettings[s].heightDownSun)) {
shutterSettings[s].firstCompleteUp = false; //reset firstCompleteUp if shutter has been moved up
}
//save old height
await sleep(60000 + waitTime4StateCheck);
shutterSettings[s].oldHeight = state.val; //set old Height after 60 Sek - after 60 Sek end position should be reached
saveCurrentStates(false);
}
}
}
}
});
if (id === adapter.namespace + '.info.Azimut') {
sunProtect(adapter, elevation, azimuth, shutterSettings);
}
if (id === adapter.namespace + '.info.Elevation') {
elevationDown(adapter, elevation, azimuth, shutterSettings);
}
if (id === adapter.namespace + '.control.closeAll') {
buttonAction(adapter, 'closeAll', shutterSettings);
}
if (id === adapter.namespace + '.control.openAll') {
buttonAction(adapter, 'openAll', shutterSettings);
}
if (id === adapter.namespace + '.control.closeLiving') {
buttonAction(adapter, 'closeLiving', shutterSettings);
}
if (id === adapter.namespace + '.control.openLiving') {
buttonAction(adapter, 'openLiving', shutterSettings);
}
if (id === adapter.namespace + '.control.closeSleep') {
buttonAction(adapter, 'closeSleep', shutterSettings);
}
if (id === adapter.namespace + '.control.openSleep') {
buttonAction(adapter, 'openSleep', shutterSettings);
}
if (id === adapter.namespace + '.control.closeChildren') {
buttonAction(adapter, 'closeChildren', shutterSettings);
}
if (id === adapter.namespace + '.control.openChildren') {
buttonAction(adapter, 'openChildren', shutterSettings);
}
if (id === adapter.namespace + '.control.sunProtect') {
buttonAction(adapter, 'sunProtect', shutterSettings);
}
if (id === adapter.namespace + '.control.sunProtectSleep') {
buttonAction(adapter, 'sunProtectSleep', shutterSettings);
}
if (id === adapter.namespace + '.control.sunProtectChildren') {
buttonAction(adapter, 'sunProtectChildren', shutterSettings);
}
if (id === adapter.namespace + '.control.sunProtectLiving') {
buttonAction(adapter, 'sunProtectLiving', shutterSettings);
}
if (id === adapter.namespace + '.control.autoAll') {
buttonAction(adapter, 'autoAll', shutterSettings);
}
}
});
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// +++++++++++++++++ Check all shutter values and set default values if values are not available ++++++++++++++++++++++++++++
async function shutterConfigCheck() {
return new Promise(async (resolve) => {
let num = 0;
if (shutterSettings) {
adapter.log.debug('shutter Config Check started');
try {
for (const s in shutterSettings) {
shutterSettings[s].triggerState = shutterSettings[s].triggerState ? shutterSettings[s].triggerState : 'none';
shutterSettings[s].triggerStateTilted = shutterSettings[s].triggerStateTilted ? shutterSettings[s].triggerStateTilted : 'none';
shutterSettings[s].typeUp = shutterSettings[s].typeUp ? shutterSettings[s].typeUp : 'sunrise';
shutterSettings[s].typeDown = shutterSettings[s].typeDown ? shutterSettings[s].typeDown : 'sunset';
shutterSettings[s].heightUp = shutterSettings[s].heightUp ? shutterSettings[s].heightUp : '100';
shutterSettings[s].heightDown = shutterSettings[s].heightDown ? shutterSettings[s].heightDown : '0';
shutterSettings[s].triggerDrive = shutterSettings[s].triggerDrive ? shutterSettings[s].triggerDrive : '100';
shutterSettings[s].triggerDriveTildet = shutterSettings[s].triggerDriveTildet ? shutterSettings[s].triggerDriveTildet : shutterSettings[s].triggerDrive;
shutterSettings[s].triggerChange = shutterSettings[s].triggerChange ? shutterSettings[s].triggerChange : 'off';
shutterSettings[s].elevation = shutterSettings[s].elevation ? shutterSettings[s].elevation : '8';
shutterSettings[s].type = shutterSettings[s].type ? shutterSettings[s].type : 'in- & outside temperature and direction';
shutterSettings[s].heightDownSun = shutterSettings[s].heightDownSun ? shutterSettings[s].heightDownSun : '30';
shutterSettings[s].direction = shutterSettings[s].direction ? shutterSettings[s].direction : '120';
shutterSettings[s].directionRange = shutterSettings[s].directionRange ? shutterSettings[s].directionRange : '50';
shutterSettings[s].tempInside = shutterSettings[s].tempInside ? shutterSettings[s].tempInside : '23';
shutterSettings[s].tempOutside = shutterSettings[s].tempOutside ? shutterSettings[s].tempOutside : '23';
shutterSettings[s].valueLight = shutterSettings[s].valueLight ? shutterSettings[s].valueLight : '15';
shutterSettings[s].autoDrive = shutterSettings[s].autoDrive ? shutterSettings[s].autoDrive : 'off';
shutterSettings[s].hysteresisOutside = shutterSettings[s].hysteresisOutside ? shutterSettings[s].hysteresisOutside : '5';
shutterSettings[s].hysteresisInside = shutterSettings[s].hysteresisInside ? shutterSettings[s].hysteresisInside : '5';
shutterSettings[s].hysteresisLight = shutterSettings[s].hysteresisLight ? shutterSettings[s].hysteresisLight : '5';
shutterSettings[s].XmasLevel = shutterSettings[s].XmasLevel ? shutterSettings[s].XmasLevel : '0';
shutterSettings[s].betweenPositionLevel = shutterSettings[s].betweenPositionLevel ? shutterSettings[s].betweenPositionLevel : '50';
shutterSettings[s].trigDelyUp = shutterSettings[s].trigDelyUp ? shutterSettings[s].trigDelyUp : '0';
shutterSettings[s].trigDelyDown = shutterSettings[s].trigDelyDown ? shutterSettings[s].trigDelyDown : '0';
shutterSettings[s].sunProtectEndDely = shutterSettings[s].sunProtectEndDely ? shutterSettings[s].sunProtectEndDely : '0';
shutterSettings[s].LateDown = shutterSettings[s].LateDown != null ? shutterSettings[s].LateDown : false;
shutterSettings[s].inSummerNotDown = shutterSettings[s].inSummerNotDown != null ? shutterSettings[s].inSummerNotDown : false;
shutterSettings[s].KeepSunProtect = shutterSettings[s].KeepSunProtect != null ? shutterSettings[s].KeepSunProtect : false;
shutterSettings[s].driveAfterClose = shutterSettings[s].driveAfterClose != null ? shutterSettings[s].driveAfterClose : false;
shutterSettings[s].useXmasLevel = shutterSettings[s].useXmasLevel != null ? shutterSettings[s].useXmasLevel : false;
shutterSettings[s].betweenPosition = shutterSettings[s].betweenPosition != null ? shutterSettings[s].betweenPosition : false;
shutterSettings[s].enableAlarmWind1 = shutterSettings[s].enableAlarmWind1 != null ? shutterSettings[s].enableAlarmWind1 : false;
shutterSettings[s].enableAlarmWind2 = shutterSettings[s].enableAlarmWind2 != null ? shutterSettings[s].enableAlarmWind2 : false;
shutterSettings[s].enableAlarmRain = shutterSettings[s].enableAlarmRain != null ? shutterSettings[s].enableAlarmRain : false;
shutterSettings[s].enableAlarmFrost = shutterSettings[s].enableAlarmFrost != null ? shutterSettings[s].enableAlarmFrost : false;
shutterSettings[s].enableAlarmFire = shutterSettings[s].enableAlarmFire != null ? shutterSettings[s].enableAlarmFire : false;
if (num == parseFloat(s)) {
adapter.log.debug('shutter Config Check successfully completed');
// @ts-ignore
resolve();
} else {
num++;
}
}
} catch (e) {
adapter.log.warn(`It is not possible to check the shutter configuration: ${e}`);
// @ts-ignore
resolve();
}
}
});
}
// +++++++++++++++++ save states on start and shutter change ++++++++++++++++++++++++++++
async function saveCurrentStates(onStart) {
if (onStart) {
await shutterConfigCheck();
}
let currentStates = {};
let shutterName = [];
let num = 0;
const _currentStates = await adapter.getStateAsync('shutters.currentStates').catch((e) => adapter.log.warn(e));
if (_currentStates && _currentStates.val && _currentStates.val !== null) {
try {
currentStates = JSON.parse(_currentStates.val);
} catch (err) {
adapter.log.debug('settings cannot be read from the state');
currentStates = {};
}
}
for (const s in shutterSettings) {
const nameDevice = shutterSettings[s].shutterName.replace(/[.;, ]/g, '_');
shutterName.push(shutterSettings[s].shutterName);
num++;
if (currentStates && currentStates[`${nameDevice}`] && !onStart) {
currentStates[`${nameDevice}`].currentAction = shutterSettings[s].currentAction;
currentStates[`${nameDevice}`].currentHeight = shutterSettings[s].currentHeight;
currentStates[`${nameDevice}`].triggerAction = shutterSettings[s].triggerAction;
currentStates[`${nameDevice}`].triggerHeight = shutterSettings[s].triggerHeight;
currentStates[`${nameDevice}`].oldHeight = shutterSettings[s].oldHeight;
currentStates[`${nameDevice}`].firstCompleteUp = shutterSettings[s].firstCompleteUp;
currentStates[`${nameDevice}`].alarmTriggerAction = shutterSettings[s].alarmTriggerAction;
currentStates[`${nameDevice}`].alarmTriggerLevel = shutterSettings[s].alarmTriggerLevel;
currentStates[`${nameDevice}`].lastAutoAction = shutterSettings[s].lastAutoAction;
} else if (currentStates && currentStates[`${nameDevice}`] && onStart) {
adapter.log.debug(nameDevice + ': save settings');
shutterSettings[s].currentAction = currentStates[`${nameDevice}`].currentAction;
shutterSettings[s].currentHeight = currentStates[`${nameDevice}`].currentHeight;
shutterSettings[s].triggerAction = currentStates[`${nameDevice}`].triggerAction;
shutterSettings[s].triggerHeight = currentStates[`${nameDevice}`].triggerHeight;
shutterSettings[s].oldHeight = currentStates[`${nameDevice}`].oldHeight;
shutterSettings[s].firstCompleteUp = currentStates[`${nameDevice}`].firstCompleteUp;
shutterSettings[s].alarmTriggerAction = currentStates[`${nameDevice}`].alarmTriggerAction;
shutterSettings[s].alarmTriggerLevel = currentStates[`${nameDevice}`].alarmTriggerLevel;
shutterSettings[s].lastAutoAction = currentStates[`${nameDevice}`].lastAutoAction;
} else if (currentStates && !currentStates[`${nameDevice}`] && onStart) {
adapter.log.debug(nameDevice + ': settings added');
currentStates[`${nameDevice}`] = null;
const states = ({
"shutterName": shutterSettings[s].shutterName,
"currentAction": shutterSettings[s].currentAction,
"currentHeight": shutterSettings[s].currentHeight,
"triggerAction": shutterSettings[s].triggerAction,
"triggerHeight": shutterSettings[s].triggerHeight,
"oldHeight": shutterSettings[s].oldHeight,
"firstCompleteUp": shutterSettings[s].firstCompleteUp,
"alarmTriggerLevel": shutterSettings[s].alarmTriggerLevel,
"alarmTriggerAction": shutterSettings[s].alarmTriggerAction,
"lastAutoAction": shutterSettings[s].lastAutoAction
});
currentStates[`${nameDevice}`] = states;
}
if (num == shutterSettings.length && onStart) {
for (const i in currentStates) {
if (shutterName.indexOf(currentStates[i].shutterName) === -1) {
const name = currentStates[i].shutterName.replace(/[.;, ]/g, '_')
adapter.log.debug(name + ': settings deleted');
delete currentStates[`${name}`];
}
await sleep(2000);
await adapter.setStateAsync('shutters.currentStates', { val: JSON.stringify(currentStates), ack: true })
.catch((e) => adapter.log.warn(e));
}
} else if (num == shutterSettings.length && !onStart) {
await adapter.setStateAsync('shutters.currentStates', { val: JSON.stringify(currentStates), ack: true })
.catch((e) => adapter.log.warn(e));
}
await sleep(100);
}
}
// +++++++++++++++++ Check States of Trigger after start ++++++++++++++++++++++++++++
async function checkStates() {
const _holidayStates = await adapter.getStateAsync('control.Holiday').catch((e) => adapter.log.warn(e));
if ((_holidayStates && _holidayStates === null) || (_holidayStates && _holidayStates.val === null)) {
await adapter.setStateAsync('control.Holiday', { val: false, ack: true })
.catch((e) => adapter.log.warn(e));
}
const _schoolfreeStates = await adapter.getStateAsync('control.schoolfree').catch((e) => adapter.log.warn(e));
if ((_schoolfreeStates && _schoolfreeStates === null) || (_schoolfreeStates && _schoolfreeStates.val === null)) {
await adapter.setStateAsync('control.schoolfree', { val: false, ack: true })
.catch((e) => adapter.log.warn(e));
}
const _autoLivingStates = await adapter.getStateAsync('control.autoLiving').catch((e) => adapter.log.warn(e));
if ((_autoLivingStates && _autoLivingStates === null) || (_autoLivingStates && _autoLivingStates.val === null)) {
await adapter.setStateAsync('control.autoLiving', { val: false, ack: true })
.catch((e) => adapter.log.warn(e));
}
const _autoSleepStates = await adapter.getStateAsync('control.autoSleep').catch((e) => adapter.log.warn(e));
if ((_autoSleepStates && _autoSleepStates === null) || (_autoSleepStates && _autoSleepStates.val === null)) {
await adapter.setStateAsync('control.autoSleep', { val: false, ack: true })
.catch((e) => adapter.log.warn(e));
}
const _autoChildrenStates = await adapter.getStateAsync('control.autoChildren').catch((e) => adapter.log.warn(e));
if ((_autoChildrenStates && _autoChildrenStates === null) || (_autoChildrenStates && _autoChildrenStates.val === null)) {
await adapter.setStateAsync('control.autoChildren', { val: false, ack: true })
.catch((e) => adapter.log.warn(e));
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// +++++++++++++++++++ check all current States an changes +++++++++++++++++++++++++
async function checkActualStates() {
const _holidayStates = await adapter.getStateAsync('control.Holiday').catch((e) => adapter.log.warn(e));
if (_holidayStates) {
HolidayStr = _holidayStates.val;
}
const _schoolfreeStates = await adapter.getStateAsync('control.schoolfree').catch((e) => adapter.log.warn(e));
if (_schoolfreeStates) {
SchoolfreeStr = _schoolfreeStates.val;
}
const _autoLivingStates = await adapter.getStateAsync('control.autoLiving').catch((e) => adapter.log.warn(e));
if (_autoLivingStates) {
autoLivingStr = _autoLivingStates.val;
}
const _autoSleepStates = await adapter.getStateAsync('control.autoSleep').catch((e) => adapter.log.warn(e));
if (_autoSleepStates) {
autoSleepStr = _autoSleepStates.val;
}
const _autoChildrenStates = await adapter.getStateAsync('control.autoChildren').catch((e) => adapter.log.warn(e));
if (_autoChildrenStates) {
autoChildrenStr = _autoChildrenStates.val;
}
if (adapter.config.publicHolidays === true && (adapter.config.publicHolInstance != 'none' || adapter.config.publicHolInstance != '')) {
const _publicHolidayStr = await adapter.getForeignStateAsync(adapter.config.publicHolInstance + '.heute.boolean').catch((e) => adapter.log.warn(e));
if (typeof _publicHolidayStr != undefined && _publicHolidayStr != null) {
publicHolidayStr = _publicHolidayStr.val;
}
const _publicHolidayTomorowStr = await adapter.getForeignStateAsync(adapter.config.publicHolInstance + '.morgen.boolean').catch((e) => adapter.log.warn(e));
if (typeof _publicHolidayTomorowStr != undefined && _publicHolidayTomorowStr != null) {
publicHolidayTomorowStr = _publicHolidayTomorowStr.val;
}
}
if (adapter.config.schoolfree === true && (adapter.config.schoolfreeInstance != 'none' || adapter.config.schoolfreeInstance != '')) {
const _schoolfreeStr = await adapter.getForeignStateAsync(adapter.config.schoolfreeInstance + '.info.today').catch((e) => adapter.log.warn(e));
if (typeof _schoolfreeStr != undefined && _schoolfreeStr != null) {
schoolfreeStr = _schoolfreeStr.val;
}
const _schoolfreeTomorowStr = await adapter.getForeignStateAsync(adapter.config.schoolfreeInstance + '.info.tomorrow').catch((e) => adapter.log.warn(e));
if (typeof _schoolfreeTomorowStr != undefined && _schoolfreeTomorowStr != null) {
schoolfreeTomorowStr = _schoolfreeTomorowStr.val;
}
}
if (adapter.config.HolidayDP !== '') {
adapter.log.debug('checking HolidayDP');
const _HolidayDP = await adapter.getForeignStateAsync(adapter.config.HolidayDP).catch((e) => adapter.log.warn(e));
if (typeof _HolidayDP != undefined && _HolidayDP != null) {
adapter.log.debug('got HolidayDP ' + _HolidayDP.val);
await adapter.setStateAsync('control.Holiday', { val: _HolidayDP.val, ack: true })
.catch((e) => adapter.log.warn(e));
}
}
if (adapter.config.schoolfreeDP !== '') {
adapter.log.debug('checking schoolfreeDP');
const _schoolfreeDP = await adapter.getForeignStateAsync(adapter.config.schoolfreeDP).catch((e) => adapter.log.warn(e));
if (typeof _schoolfreeDP != undefined && _schoolfreeDP != null) {
adapter.log.debug('got schoolfreeDP ' + _schoolfreeDP.val);
await adapter.setStateAsync('control.schoolfree', { val: _schoolfreeDP.val, ack: true })
.catch((e) => adapter.log.warn(e));
}
}
const _ObjautoUp = await adapter.getForeignObjectsAsync(adapter.namespace + '.shutters.autoUp.*', 'state').catch((e) => adapter.log.warn(e));
if (_ObjautoUp) {
ObjautoUp = _ObjautoUp;
}
const _ObjautoDown = await adapter.getForeignObjectsAsync(adapter.namespace + '.shutters.autoDown.*', 'state').catch((e) => adapter.log.warn(e));
if (_ObjautoDown) {
ObjautoDown = _ObjautoDown;
}
const _ObjautoSun = await adapter.getForeignObjectsAsync(adapter.namespace + '.shutters.autoSun.*', 'state').catch((e) => adapter.log.warn(e));
if (_ObjautoSun) {
ObjautoSun = _ObjautoSun;
}
const _ObjautoState = await adapter.getForeignObjectsAsync(adapter.namespace + '.shutters.autoState.*', 'state').catch((e) => adapter.log.warn(e));
if (_ObjautoState) {
ObjautoState = _ObjautoState;
}
const _ObjautoLevel = await adapter.getForeignObjectsAsync(adapter.namespace + '.shutters.autoLevel.*', 'state').catch((e) => adapter.log.warn(e));
if (_ObjautoLevel) {
ObjautoLevel = _ObjautoLevel;
}
await sleep(1000);
shutterDriveCalc();
createShutter();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// ++++++++++++++++++ reset current Action in the night at 02:30 +++++++++++++++++++++++
const calc = schedule.scheduleJob('calcTimer', '30 2 * * *', async function () {
shutterDriveCalc();
const resultStates = shutterSettings;
if (resultStates) {
for (const i in resultStates) {
const nameDevice = resultStates[i].shutterName.replace(/[.;, ]/g, '_');
const _shutterState = await adapter.getForeignStateAsync(resultStates[i].name).catch((e) => adapter.log.warn(e));
if (typeof _shutterState != undefined && _shutterState != null) {
// Case: Shutter in sunProtect mode. Auto-down in the evening before end of sunProtect. The sun is sill shining. Prevent that the shutter opens again with end of sunProtect.
// currentAction=sunprotect would be set in sunProtect(). But not if currentAction=down. So this is checked in sunProtect(). Reset here to enable possibility to set sunProtect in the morning ->
resultStates[i].currentAction = 'none';
resultStates[i].firstCompleteUp = true;
await adapter.setStateAsync('shutters.autoState.' + nameDevice, { val: resultStates[i].currentAction, ack: true })
.catch((e) => adapter.log.warn(e));
adapter.log.debug(resultStates[i].shutterName + " set currentHeight to " + _shutterState.val);
if (typeof _shutterState.val != undefined && _shutterState.val != null) {
resultStates[i].currentHeight = _shutterState.val;
await adapter.setStateAsync('shutters.autoLevel.' + nameDevice, { val: parseFloat(resultStates[i].currentHeight), ack: true })
.catch((e) => adapter.log.warn(e));
if (parseFloat(resultStates[i].heightDown) < parseFloat(resultStates[i].heightUp)) {
adapter.log.debug(resultStates[i].shutterName + ' level conversion is disabled ...');
} else if (parseFloat(resultStates[i].heightDown) > parseFloat(resultStates[i].heightUp)) {
adapter.log.debug(resultStates[i].shutterName + ' level conversion is enabled');
}
}
}
}
}
});
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// +++++++++++++++++ Get longitude an latidude from system config ++++++++++++++++++++
async function GetSystemData() {
if (typeof adapter.config.longitude == undefined || adapter.config.longitude == null || adapter.config.longitude.length == 0 || isNaN(adapter.config.longitude)
|| typeof adapter.config.latitude == undefined || adapter.config.latitude == null || adapter.config.latitude.length == 0 || isNaN(adapter.config.latitude)) {
try {
const obj = await adapter.getForeignObjectAsync('system.config', 'state');
if (obj && obj.common && obj.common.longitude && obj.common.latitude) {
adapter.config.longitude = obj.common.longitude;
adapter.config.latitude = obj.common.latitude;
adapter.log.debug(`longitude: ${adapter.config.longitude} | latitude: ${adapter.config.latitude}`);
} else {
adapter.log.error('system settings cannot be called up. Please check configuration!');
}
} catch (err) {
adapter.log.warn('system settings cannot be called up. Please check configuration!');
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// +++++++++++++++ calc the shutter time for all function ++++++++++++++++++
let sunsetStr, sunriseStr, goldenHour, goldenHourEnd, upTimeSleep, upTimeChildren, upTimeLiving, downTimeSleep, downTimeChildren;
let downTimeLiving, dayStr, HolidayStr, SchoolfreeStr, publicHolidayStr, publicHolidayTomorowStr, schoolfreeTomorowStr, schoolfreeStr;
function shutterDriveCalc() {
adapter.log.debug('Travel times of the shutters are calculated');
let times; // get today's sunlight times
try {
times = SunCalc.getTimes(new Date(), adapter.config.latitude, adapter.config.longitude);
adapter.log.debug('calculate astrodata ...');
// format sunset/sunrise time from the Date object
sunsetStr = ('0' + times.sunset.getHours()).slice(-2) + ':' + ('0' + times.sunset.getMinutes()).slice(-2);
sunriseStr = ('0' + times.sunrise.getHours()).slice(-2) + ':' + ('0' + times.sunrise.getMinutes()).slice(-2);
dayStr = times.sunrise.getDay();
// format goldenhour/goldenhourend time from the Date object
goldenHour = ('0' + times.goldenHour.getHours()).slice(-2) + ':' + ('0' + times.goldenHour.getMinutes()).slice(-2);
goldenHourEnd = ('0' + times.goldenHourEnd.getHours()).slice(-2) + ':' + ('0' + times.goldenHourEnd.getMinutes()).slice(-2);
} catch (e) {
adapter.log.warn('cannot calculate astrodata ... please check your config for latitude und longitude!!');
}
adapter.log.debug('goldenHourEnd today: ' + goldenHourEnd);
adapter.setState('info.GoldenHourEnd', { val: goldenHourEnd, ack: true });
adapter.log.debug('goldenHour today: ' + goldenHour);
adapter.setState('info.GoldenHour', { val: goldenHour, ack: true });
adapter.log.debug('current day: ' + dayStr);
adapter.log.debug('Sunrise today: ' + sunriseStr);
adapter.setState('info.Sunrise', { val: sunriseStr, ack: true });
adapter.log.debug('Sunset today: ' + sunsetStr);
adapter.setState('info.Sunset', { val: sunsetStr, ack: true });
sunriseStr = addMinutes(sunriseStr, adapter.config.astroDelayUp); // Add Delay for Sunrise
sunsetStr = addMinutes(sunsetStr, adapter.config.astroDelayDown); // Add Delay for Sunset
goldenHour = addMinutes(goldenHour, adapter.config.astroDelayDown); // Add Delay for GoldenHour
goldenHourEnd = addMinutes(goldenHourEnd, adapter.config.astroDelayUp); // Add Delay for GoldenHourEnd
adapter.log.debug('Starting up shutters GoldenHour area: ' + goldenHourEnd);
adapter.log.debug('Shutdown shutters GoldenHour area: ' + goldenHour);
adapter.log.debug('Starting up shutters Sunrise area: ' + sunriseStr);
adapter.log.debug('Shutdown shutters Sunset area: ' + sunsetStr);
shutterGoldenHour(adapter, goldenHourEnd, goldenHour, shutterSettings);
shutterSunriseSunset(adapter, sunriseStr, sunsetStr, shutterSettings);
switch (adapter.config.livingAutomatic) {
case 'livingSunriseSunset':
astroTimeLivingUp = sunriseStr;
astroTimeLivingDown = sunsetStr;
break;
case 'livingGoldenHour':
astroTimeLivingUp = goldenHourEnd;
astroTimeLivingDown = goldenHour;
break;
}
switch (adapter.config.sleepAutomatic) {
case 'sleepSunriseSunset':
astroTimeSleepUp = sunriseStr;
astroTimeSleepDown = sunsetStr;
break;
case 'sleepGoldenHour':
astroTimeSleepUp = goldenHourEnd;
astroTimeSleepDown = goldenHour;
break;
}
switch (adapter.config.childrenAutomatic) {
case 'childrenSunriseSunset':
astroTimeChildrenUp = sunriseStr;
astroTimeChildrenDown = sunsetStr;
break;
case 'childrenGoldenHour':
astroTimeChildrenUp = goldenHourEnd;
astroTimeChildrenDown = goldenHour;
break;
}
let debugCnt = 0;
// ******** Set Up-Time Living Area ********
switch (adapter.config.livingAutomatic) {
case 'livingTime':
if (dayStr === 6 || dayStr === 0 || (HolidayStr) === true || (SchoolfreeStr === true && adapter.config.schoolfreeLivingArea == true) || (publicHolidayStr) === true || (schoolfreeStr === true && adapter.config.schoolfreeLivingArea == true)) {
upTimeLiving = adapter.config.WE_shutterUpLivingMax;
debugCnt = 1;
} else {
upTimeLiving = adapter.config.W_shutterUpLivingMax;
debugCnt = 2;
}
break;
default:
if (dayStr === 6 || dayStr === 0 || (HolidayStr) === true || (SchoolfreeStr === true && adapter.config.schoolfreeLivingArea == true) || (publicHolidayStr) === true || (schoolfreeStr === true && adapter.config.schoolfreeLivingArea == true)) {
if (IsLater(astroTimeLivingUp, adapter.config.WE_shutterUpLivingMax)) {
upTimeLiving = adapter.config.WE_shutterUpLivingMax;
debugCnt = 10;
} else if (IsLater(astroTimeLivingUp, adapter.config.WE_shutterUpLivingMin) && IsEarlier(astroTimeLivingUp, adapter.config.WE_shutterUpLivingMax)) {
upTimeLiving = astroTimeLivingUp;
debugCnt = 11;
} else if (IsEqual(adapter.config.WE_shutterUpLivingMin, adapter.config.WE_shutterUpLivingMax)) {
upTimeLiving = adapter.config.WE_shutterUpLivingMax;
debugCnt = 12;
} else if (IsEqual(astroTimeLivingUp, adapter.config.WE_shutterUpLivingMax)) {
upTimeLiving = astroTimeLivingUp;
debugCnt = 13;
} else if (IsEarlier(astroTimeLivingUp, adapter.config.WE_shutterUpLivingMin)) {
upTimeLiving = adapter.config.WE_shutterUpLivingMin;
debugCnt = 14;
}
} else {
if (dayStr < 6 && dayStr > 0) {
if (IsLater(astroTimeLivingUp, adapter.config.W_shutterUpLivingMax)) {
upTimeLiving = adapter.config.W_shutterUpLivingMax;
debugCnt = 4;
} else if (IsLater(astroTimeLivingUp, adapter.config.W_shutterUpLivingMin) && IsEarlier(astroTimeLivingUp, adapter.config.W_shutterUpLivingMax)) {
upTimeLiving = astroTimeLivingUp;
debugCnt = 5;
} else if (IsEqual(adapter.config.W_shutterUpLivingMin, adapter.config.W_shutterUpLivingMax)) {
upTimeLiving = adapter.config.W_shutterUpLivingMax;
debugCnt = 6;
} else if (IsEqual(astroTimeLivingUp, adapter.config.W_shutterUpLivingMax)) {
upTimeLiving = astroTimeLivingUp;
debugCnt = 7;
} else if (IsEarlier(astroTimeLivingUp, adapter.config.W_shutterUpLivingMin)) {
upTimeLiving = adapter.config.W_shutterUpLivingMin;
debugCnt = 8;
}
}
}
break;
}
adapter.setState('info.upTimeLiving', { val: upTimeLiving, ack: true });
adapter.log.debug('Starting up shutters living area: ' + upTimeLiving + " debug " + debugCnt);
shutterUpLiving(adapter, upTimeLiving, autoLivingStr, shutterSettings);
// ******** Set Up-Time Sleep Area ********
switch (adapter.config.sleepAutomatic) {
case 'sleepTime':
if (dayStr === 6 || dayStr === 0 || (HolidayStr) === true || (SchoolfreeStr === true && adapter.config.schoolfreeSleepArea == true) || (publicHolidayStr) === true || (schoolfreeStr === true && adapter.config.schoolfreeSleepArea == true)) {
upTimeSleep = adapter.config.WE_shutterUpSleepMax;
debugCnt = 1;
} else {
upTimeSleep = adapter.config.W_shutterUpSleepMax;
debugCnt = 2;
}
break;
default:
if (dayStr === 6 || dayStr === 0 || (HolidayStr) === true || (SchoolfreeStr === true && adapter.config.schoolfreeSleepArea == true) || (publicHolidayStr) === true || (schoolfreeStr === true && adapter.config.schoolfreeSleepArea == true)) {
if (IsLater(astroTimeSleepUp, adapter.config.WE_shutterUpSleepMax)) {
upTimeSleep = adapter.config.WE_shutterUpSleepMax;
debugCnt = 10;
} else if (IsLater(astroTimeSleepUp, adapter.config.WE_shutterUpSleepMin) && IsEarlier(astroTimeSleepUp, adapter.config.WE_shutterUpSleepMax)) {
upTimeSleep = astroTimeSleepUp;
debugCnt = 11;
} else if (IsEqual(adapter.config.WE_shutterUpSleepMin, adapter.config.WE_shutterUpSleepMax)) {
upTimeSleep = adapter.config.WE_shutterUpSleepMax;
debugCnt = 12;
} else if (IsEqual(astroTimeSleepUp, adapter.config.WE_shutterUpSleepMax)) {
upTimeSleep = astroTimeSleepUp;
debugCnt = 13;
} else if (IsEarlier(astroTimeSleepUp, adapter.config.WE_shutterUpSleepMin)) {
upTimeSleep = adapter.config.WE_shutterUpSleepMin;
debugCnt = 14;
}
} else {
if (dayStr < 6 && dayStr > 0) {
if (IsLater(astroTimeSleepUp, adapter.config.W_shutterUpSleepMax)) {
upTimeSleep = adapter.config.W_shutterUpSleepMax;
debugCnt = 4;
} else if (IsLater(astroTimeSleepUp, adapter.config.W_shutterUpSleepMin) && IsEarlier(astroTimeSleepUp, adapter.config.W_shutterUpSleepMax)) {
upTimeSleep = astroTimeSleepUp;
debugCnt = 5;
} else if (IsEqual(adapter.config.W_shutterUpSleepMin, adapter.config.W_shutterUpSleepMax)) {
upTimeSleep = adapter.config.W_shutterUpSleepMax;
debugCnt = 6;
} else if (IsEqual(astroTimeSleepUp, adapter.config.W_shutterUpSleepMax)) {
upTimeSleep = astroTimeSleepUp;
debugCnt = 7;
} else if (IsEarlier(astroTimeSleepUp, adapter.config.W_shutterUpSleepMin)) {
upTimeSleep = adapter.config.W_shutterUpSleepMin;
debugCnt = 8;
}
}
}
break;
}
adapter.setState('info.upTimeSleep', { val: upTimeSleep, ack: true });
adapter.log.debug('Starting up shutters sleep area: ' + upTimeSleep + " debug " + debugCnt);
shutterUpSleep(adapter, upTimeSleep, delayUp, autoSleepStr, shutterSettings)
// ******** Set Up-Time Children Area ********
switch (adapter.config.childrenAutomatic) {
case 'childrenTime':
if (dayStr === 6 || dayStr === 0 || (HolidayStr) === true || (SchoolfreeStr === true && adapter.config.schoolfreeChildrenArea == true) || (publicHolidayStr) === true || (schoolfreeStr === true && adapter.config.schoolfreeChildrenArea == true)) {
upTimeChildren = adapter.config.WE_shutterUpChildrenMax;
debugCnt = 1;
} else {
upTimeChildren = adapter.config.W_shutterUpChildrenMax;
debugCnt = 2;
}
break;
default:
if (dayStr === 6 || dayStr === 0 || (HolidayStr) === true || (SchoolfreeStr === true && adapter.config.schoolfreeChildrenArea == true) || (publicHolidayStr) === true || (schoolfreeStr === true && adapter.config.schoolfreeChildrenArea == true)) {
if (IsLater(astroTimeChildrenUp, adapter.config.WE_shutterUpChildrenMax)) {
upTimeChildren = adapter.config.WE_shutterUpChildrenMax;
debugCnt = 10;
} else if (IsLater(astroTimeChildrenUp, adapter.config.WE_shutterUpChildrenMin) && IsEarlier(astroTimeChildrenUp, adapter.config.WE_shutterUpChildrenMax)) {
upTimeChildren = astroTimeChildrenUp;
debugCnt = 11;
} else if (IsEqual(adapter.config.WE_shutterUpChildrenMin, adapter.config.WE_shutterUpChildrenMax)) {
upTimeChildren = adapter.config.WE_shutterUpChildrenMax;
debugCnt = 12;
} else if (IsEqual(astroTimeChildrenUp, adapter.config.WE_shutterUpChildrenMax)) {
upTimeChildren = astroTimeChildrenUp;
debugCnt = 13;
} else if (IsEarlier(astroTimeChildrenUp, adapter.config.WE_shutterUpChildrenMin)) {
upTimeChildren = adapter.config.WE_shutterUpChildrenMin;
debugCnt = 14;
}
} else {
if (dayStr < 6 && dayStr > 0) {
if (IsLater(astroTimeChildrenUp, adapter.config.W_shutterUpChildrenMax)) {
upTimeChildren = adapter.config.W_shutterUpChildrenMax;
debugCnt = 4;
} else if (IsLater(astroTimeChildrenUp, adapter.config.W_shutterUpChildrenMin) && IsEarlier(astroTimeChildrenUp, adapter.config.W_shutterUpChildrenMax)) {
upTimeChildren = astroTimeChildrenUp;
debugCnt = 5;
} else if (IsEqual(adapter.config.W_shutterUpChildrenMin, adapter.config.W_shutterUpChildrenMax)) {
upTimeChildren = adapter.config.W_shutterUpChildrenMax;
debugCnt = 6;
} else if (IsEqual(astroTimeChildrenUp, adapter.config.W_shutterUpChildrenMax)) {
upTimeChildren = astroTimeChildrenUp;
debugCnt = 7;
} else if (IsEarlier(astroTimeChildrenUp, adapter.config.W_shutterUpChildrenMin)) {
upTimeChildren = adapter.config.W_shutterUpChildrenMin;
debugCnt = 8;
}
}
}
break;
}
adapter.setState('info.upTimeChildren', { val: upTimeChildren, ack: true });
adapter.log.debug('Starting up shutters children area: ' + upTimeChildren + " debug " + debugCnt);
shutterUpChildren(adapter, upTimeChildren, delayUpChildren, autoChildrenStr, shutterSettings)
// ******** Set Down-Time Living Area ********
switch (adapter.config.livingAutomatic) {
case 'livingTime':
if (dayStr === 5 || dayStr === 6 || (HolidayStr) === true || (SchoolfreeStr === true && adapter.config.schoolfreeLivingArea == true) || (publicHolidayTomorowStr) === true || (schoolfreeTomorowStr === true && adapter.config.schoolfreeLivingArea == true)) {
downTimeLiving = adapter.config.WE_shutterDownLiving;
debugCnt = 1;
} else {
downTimeLiving = adapter.config.W_shutterDownLiving;
debugCnt = 2;
}
break;
default:
if ((dayStr === 5 || dayStr === 6 || (HolidayStr) === true || (SchoolfreeStr === true && adapter.config.schoolfreeLivingArea == true) || (publicHolidayTomorowStr) === true || (schoolfreeTomorowStr === true && adapter.config.schoolfreeLivingArea == true)) && IsEarlier(adapter.config.WE_shutterDownLiving, astroTimeLivingDown)) {
downTimeLiving = adapter.config.WE_shutterDownLiving;
debugCnt = 3;
} else if ((dayStr === 5 || dayStr === 6 || (HolidayStr) === true || (SchoolfreeStr === true && adapter.config.schoolfreeLivingArea == true) || (publicHolidayTomorowStr) === true || (schoolfreeTomorowStr === true && adapter.config.schoolfreeLivingArea == true)) && IsLater(adapter.config.WE_shutterDownLiving, astroTimeLivingDown)) {
downTimeLiving = astroTimeLivingDown;
debugCnt = 4;
} else if ((dayStr === 5 || dayStr === 6 || (HolidayStr) === true || (SchoolfreeStr === true && adapter.config.schoolfreeLivingArea == true) || (publicHolidayTomorowStr) === true || (schoolfreeTomorowStr === true && adapter.config.schoolfreeLivingArea == true)) && IsEqual(adapter.config.WE_shutterDownLiving, astroTimeLivingDown)) {
downTimeLiving = astroTimeLivingDown;
debugCnt = 5;
} else if (dayStr < 5 && IsLater(astroTimeLivingDown, adapter.config.W_shutterDownLiving)) {
downTimeLiving = adapter.config.W_shutterDownLiving;
debugCnt = 6;
} else if (dayStr < 5 && IsEarlier(astroTimeLivingDown, adapter.config.W_shutterDownLiving)) {
downTimeLiving = astroTimeLivingDown;
debugCnt = 7;
} else if (dayStr < 5 && IsEqual(astroTimeLivingDown, adapter.config.W_shutterDownLiving)) {
downTimeLiving = astroTimeLivingDown;
debugCnt = 8;
}
break;
}
adapter.setState('info.downTimeLiving', { val: downTimeLiving, ack: true });
adapter.log.debug('Shutdown shutters living area: ' + downTimeLiving + " debug " + debugCnt);
shutterDownLiving(adapter, downTimeLiving, autoLivingStr, shutterSettings);
// ******** Set Down-Time Children Area ********
switch (adapter.config.childrenAutomatic) {
case 'childrenTime':