-
Notifications
You must be signed in to change notification settings - Fork 15
/
Fensterauswertung.js
1462 lines (1295 loc) · 94 KB
/
Fensterauswertung.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
const Skriptversion = "1.6.15" //vom 22.11.2021 - https://github.com/Pittini/iobroker-Fensterauswertung - https://forum.iobroker.net/topic/31674/vorlage-generisches-fensteroffenskript-vis
//Script um offene Fenster/Türen pro Raum und insgesamt zu zählen.
//Möglichkeit eine Ansage nach x Minuten einmalig oder zyklisch bis Fensterschließung anzugeben
//Dynamische erzeugung einer HTML Übersichtstabelle
//WICHTIG!!!
//Vorraussetzungen: Den Geräten müssen Räume zugewiesen sein, sowie die Funktion "Fenster" bzw "Tuer" für jeden entsprechenden Datenpunkt.
//Grundeinstellungen
const logging = false; //Erweiterte Logs ausgeben?
const praefix = "javascript.0.FensterUeberwachung."; //Grundpfad für Script DPs - Muß innerhalb javascript.x sein.
const PresenceDp = "" //Pfad zum Anwesenheitsdatenpunkt, leer lassen wenn nicht vorhanden
const WhichWindowFunctionToUse = "Fenster"; // Legt fest nach welchem Begriff in Funktionen gesucht wird. Diese Funktion nur dem Datenpunkt zuweisen, NICHT dem ganzen Channel!
const WhichDoorFunctionToUse = "Tuer"; // Legt fest nach welchem Begriff in Funktionen gesucht wird. Diese Funktion nur dem Datenpunkt zuweisen, NICHT dem ganzen Channel!
const WindowIgnoreTime = 10000; // 10000 ms = 10 Sekunden - Zeit in ms für die kurzzeitiges öffnen/schliessen ignoriert wird
const DoorIgnoreTime = 1000; // 1000 ms = 1 Sekunden - Zeit in ms für die kurzzeitiges öffnen/schliessen ignoriert wird
const WhichEnumCategoryToUse = "functions"; // Legt fest in welcher Kategorie sich die Aufzählungen befinden! Nur ändern wer weis was er tut!
//Nachrichteneinstellungen
const TimeToWindowMsg = 900000 // 300000 ms = 5 Minuten - Zyklus- bzw. Ablaufzeit für Fenster-offenwarnung/en
const TimeToDoorMsg = 300000 // 300000 ms = 5 Minuten - Zyklus- bzw. Ablaufzeit für Tür-offenwarnung/en
const MaxMessages = 1; //Maximale Anzahl der Nachrichten pro Raum
//Telegram
const UseTelegram = false; // Sollen Nachrichten via Telegram gesendet werden?
//Pushover
const UsePushOver = false; // Sollen Nachrichten via PushOver gesendet werden?
const PushOverInstance = "pushover.0"; //Pushoverinstanz welche genutzt werden soll angeben
const PushOverDevice = "All"; //Welches Gerät soll die Nachricht bekommen
const PushOverTitle = "Fensterüberwachung";
const PushOverSound = "none"; //Welcher Sound soll abgespielt werden? "none" für kein Sound, "" für Standartsound, ansonsten Namen angeben z.B. "magic"
//Alexa
const UseAlexa = false; // Sollen Nachrichten via Alexa ausgegeben werden?
const AlexaInstance = "alexa2.0";
const AlexaId = ""; // Die Alexa Seriennummer.
const AlexaVolume = "50"; // Lautstärke der Nachrichten. Wert von 1 bis 100
//Other
const UseMail = false; //Nachricht via Mail versenden?
const UseSay = true; // Sollen Nachrichten via Say ausgegeben werden? Autorenfunktion, muß deaktiviert werden.
const UseEventLog = true; // Sollen Nachrichten ins Eventlog geschreiben werden? Autorenfunktion, muß deaktiviert werden.
const NoMsgAtPresence = false; //Sollen Nachrichten bei Anwesenheit unterdrückt werden?
//Tabelleneinstellungen
const DoorOpenImg = "/icons-mfd-svg/fts_door_open.svg"; //Icon für Tür offen
const DoorCloseImg = "/icons-mfd-svg/fts_door.svg"; // Icon für Tür geschlossen
const DoorTiltedImg = "/icons-mfd-svg/fts_door_tilt.svg" // Icon für Tür gekippt
const WindowOpenImg = "/icons-mfd-svg/fts_window_1w_open.svg"; //Icon für Fenster offen
const WindowCloseImg = "/icons-mfd-svg/fts_window_1w.svg"; // Icon für Fenster geschlossen
const WindowTiltedImg = "/icons-mfd-svg/fts_window_1w_tilt.svg" //Icon für Fenster gekippt
const WindowOpenTiltedImg = "/icons-mfd-svg/fts_window_2w_open_l_tilt_r.svg" //Icon für offen und gekippt in einem Raum gleichzeitig
const VentImg = "/icons-mfd-svg/vent_ventilation.svg"; //Icon für Lüftungsinfo
const ImgInvert = 1; // Bildfarben invertieren? Erlaubte Werte von 0 bis 1
const OpenWindowColor = "#f44336"; // Farbe für Fenster offen
const OpenDoorColor = "darkorange"; //Farbe für Tür offen
const TiltedWindowColor = "#F56C62"; //Farbe für gekippte Fenster o. Tür/en
const ClosedWindowColor = "#4caf50"; // Farbe für geschlossene Fenster o. Tür/en
const VentWarnColor = "#ffc107"; // Farbe für Lüftungswarnung
const ShowCaptionTbl = false; // Überschrift anzeigen?
const ShowSummaryTbl = true; // Zusammenfassung anzeigen?
const ShowDetailTbl = true; // Details anzeigen?
const RoomSortMode = 1; //0= Raumliste unsortiert, 1= alpabetisch sortiert, 2= Benutzerdefinierte Sortierung
//Logeinstellungen
const MaxLogEntrys = 20; //Maximale Anzahl der zu speichernden Logeinträge
const AutoAddTimestamp = true; //Soll den geloggten Nachrichten automatisch ein Zeitsempel zugeordnet werden?
const LogTimeStampFormat = "TT.MM.JJJJ SS:mm:ss"; //Zeitformatierung für Log Zeitstempel
const LogEntrySeparator = "<br>"; //Trennzeichen für Logeinträge
//Ab hier nix mehr ändern!
const SendVentMsg = [];
const SendDoorOpenCloseMsg = [];
const SendWindowOpenCloseMsg = [];
const SendWindowWarnMsg = [];
const SendDoorWarnMsg = [];
const OpenWindowListSeparator = "<br>"; //Trennzeichen für die Textausgabe der offenen Fenster pro Raum
const WindowIsOpenWhen = ["true", "offen", "open", "opened", "2"]; // Hier können eigene States für offen angegeben werden, immer !!! in Kleinschreibung
const WindowIsClosedWhen = ["false", "geschlossen", "closed", "0"]; // Hier können eigene States für geschlossen angegeben werden, immer !!! in Kleinschreibung
const WindowIsTiltedWhen = ["tilted", "gekippt", "1"]; // Hier können eigene States für gekippt angegeben werden, immer !!! in Kleinschreibung
let OpenDoorCount = 0; // Gesamtzahl der geöffneten Türen
let TiltedDoorCount = 0; // Gesamtzahl der gekippten Türen
let OpenWindowCount = 0; // Gesamtzahl der geöffneten Fenster
let TiltedWindowCount = 0; // Davon Anzahl der gekippten Fenster
const RoomOpenCount = []; // Array für Summe geöffneter Verschlüsse pro Raum
const RoomOpenDoorCount = []; // Array für Zähler offene Türen pro Raum
const RoomTiltedDoorCount = []; // Array für Zähler gekippte Türen pro Raum
const RoomOpenWindowCount = []; // Array für Zähler offene Fenster pro Raum
const RoomTiltedWindowCount = []; // Array für Zähler gekippte Fenster pro Raum
const RoomWindowMsgCount = []; //Zähler für bereits ausgegebene Fenster Warnmeldungen
const RoomDoorMsgCount = []; //Zähler für bereits ausgegebene Tür Warnmeldungen
let RoomHas = [] // 0=Weder Tür noch Fenster, 1 Tür, 2 Fenster, 3 Tür und Fenster
const RoomsWithCombinedOpenings = [];
let RoomsWithOpenings = ""; // Kombinierte Liste mit offenen Türen und Fenstern
let RoomsWithOpenDoors = ""; //Liste der Räume mit offenen Türen
let RoomsWithTiltedDoors = ""; //Liste der Räume mit offenen Türen
let RoomsWithOpenWindows = ""; //Liste der Räume mit offenen Fenstern
let RoomsWithTiltedWindows = ""; //Liste der Räume mit gekippten Fenstern
let RoomsWithVentWarnings = []; //Räume mit Lüftungswarnung
let RoomListOrderPriority = ""; //Sortierreihenfolge der Raumliste
const OpenWindowMsgHandler = []; // Objektarray für timeouts pro Raum/Fenster
const OpenDoorMsgHandler = []; // Objektarray für timeouts pro Raum/Tür
const IgnoreValue = []; //Vergleichswert für IgnoreTimeout
const VentMsgHandler = []; //Timeout/Intervall Objekt
const VentMsg = []; //Lüftungsnachricht
const Sensor = []; //Sensoren als Array anlegen
let SensorType = []; //Unterscheidung zwischen Tür und Fenstersensor
const SensorVal = [];//Sensorwerte als Array anlegen
const SensorOldVal = []; //Alte Sensorwerte als Array ablegen
const WindowWarnRuntime = []; //Timer WindowWarnRuntime pro Fenster
const DoorWarnRuntime = []; //Timer DoorWarnRuntime pro Tür
const VentWarnTime = []; // Array mit Zeiten nach dem eine Lüftungsempfehlung ausgegeben wird
let RoomList = []; // Raumlisten Array
const RoomStateTimeStamp = []; //Letzte Änderung des Fenster-Raumstatus
const RoomStateTimeCount = []; // Zeitspanne seit letzter Änderung
const RoomDoorStateTimeStamp = []; //Letzte Änderung des Tür-Raumstatus
const RoomDoorStateTimeCount = []; // Zeitspanne seit letzter Änderung
let z = 0; //Zähler
let DpCount = 0; //Zähler
let IsInit = true // Marker - Wird nach initialisierung auf false gesetzt
// /** @type {{ id: string, initial: any, forceCreation: boolean, common: iobJS.StateCommon }[]} */
const States = []; // Array mit anzulegenden Datenpunkten
let Funktionen = getEnums(WhichEnumCategoryToUse); //Array mit Aufzählung der Funktionen
let MessageLog = ""; //Log der ausgegebenen Meldungen
let MuteMode = 0; //Stummschaltungsmodus für Nachrichten. 0=Alles erlaubt, 1=Sprachnachrichten deaktivieren, 2=Alles deaktivieren
let Presence = true; //Anwesenheit als gegeben initialisieren
const IgnoreInProcess = []; //Läuft gerade eine Überprüfung ob eine Statusänderung ignoriert werden muß?
let SensorCount = 0; //Hilfszähler weil y bei mehreren Funktionen mehrmals bei 0 beginnt
let SendRoomsWithOpeningsMsg = false;
let SendRoomsWithOpeningsMsgRefresh = 0;
let RoomsWithOpeningsMsgRefreshTickerObj;
log("starting Fensterskript, Version " + Skriptversion);
for (let x in Funktionen) { // loop ueber alle Functions
let Funktion = Funktionen[x].name;
if (typeof Funktion == "undefined") {
log("Keine Funktion gefunden", "error");
}
else {
if (typeof Funktion == 'object') Funktion = Funktion.de;
let members = Funktionen[x].members;
if (Funktion == WhichWindowFunctionToUse || Funktion == WhichDoorFunctionToUse) { //Wenn Function ist Fenster oder Tür
for (let y in members) { // Loop über alle Fenster/Tür Members
Sensor[SensorCount] = members[y];
let room = getObject(Sensor[SensorCount], 'rooms').enumNames[0];
if (typeof room == 'object') room = room.de;
if (RoomList.indexOf(room) == -1) { //Raumliste ohne Raumduplikate und zugehörige Dps erzeugen
//Datenpunkte pro Raum vorbereiten
States[DpCount] = { id: praefix + room + ".RoomOrderPriority", initial: z, forceCreation: false, common: { read: true, write: true, name: "Raumpriorität für Tabelle", role: "state", type: "number", def: z } };
DpCount++;
States[DpCount] = { id: praefix + room + ".RoomOpenCount", initial: 0, forceCreation: false, common: { read: true, write: false, name: "Summe der geöffneten Fenster und Türen im Raum", role: "state", type: "number", def: 0 } };
DpCount++;
States[DpCount] = { id: praefix + room + ".RoomOpenDoorCount", initial: 0, forceCreation: false, common: { read: true, write: false, name: "Anzahl der geöffneten Türen im Raum", role: "state", type: "number", def: 0 } };
DpCount++;
States[DpCount] = { id: praefix + room + ".RoomTiltedDoorCount", initial: 0, forceCreation: false, common: { read: true, write: false, name: "Anzahl der gekippten Türen im Raum", role: "state", type: "number", def: 0 } };
DpCount++;
States[DpCount] = { id: praefix + room + ".RoomOpenWindowCount", initial: 0, forceCreation: false, common: { read: true, write: false, name: "Anzahl der geöffneten Fenster im Raum", role: "state", type: "number", def: 0 } };
DpCount++;
States[DpCount] = { id: praefix + room + ".RoomTiltedWindowCount", initial: 0, forceCreation: false, common: { read: true, write: false, name: "Anzahl der gekippten Fenster im Raum", role: "state", type: "number", def: 0 } };
DpCount++;
States[DpCount] = { id: praefix + room + ".SendVentMsg", initial: true, forceCreation: false, common: { read: true, write: true, name: "Sollen für diesen Raum Lüftungsnachrichten ausgegeben werden?", type: "boolean", role: "state", def: true } }; //
DpCount++;
States[DpCount] = { id: praefix + room + ".SendDoorOpenCloseMsg", initial: true, forceCreation: false, common: { read: true, write: true, name: "Sollen für diesen Raum Nachrichten bei öffnen/schliessen von Türen ausgegeben werden?", type: "boolean", role: "state", def: true } }; //
DpCount++;
States[DpCount] = { id: praefix + room + ".SendWindowOpenCloseMsg", initial: true, forceCreation: false, common: { read: true, write: true, name: "Sollen für diesen Raum Nachrichten bei öffnen/schliessen von Fenstern ausgegeben werden?", type: "boolean", role: "state", def: true } }; //
DpCount++;
States[DpCount] = { id: praefix + room + ".SendWindowWarnMsg", initial: true, forceCreation: false, common: { read: true, write: true, name: "Sollen für diesen Raum Nachrichten für überschrittene Fenster Öffnungszeit ausgegeben werden?", type: "boolean", role: "state", def: true } }; //
DpCount++;
States[DpCount] = { id: praefix + room + ".SendDoorWarnMsg", initial: true, forceCreation: false, common: { read: true, write: true, name: "Sollen für diesen Raum Nachrichten für überschrittene Tür Öffnungszeit ausgegeben werden?", type: "boolean", role: "state", def: true } }; //
DpCount++;
States[DpCount] = { id: praefix + room + ".WindowIsOpen", initial: false, forceCreation: false, common: { read: true, write: false, name: "Fenster im Raum offen oder gekippt?", type: "boolean", role: "state", def: false } }; //
DpCount++;
States[DpCount] = { id: praefix + room + ".DoorIsOpen", initial: false, forceCreation: false, common: { read: true, write: false, name: "Türen im Raum offen?", type: "boolean", role: "state", def: false } }; //
DpCount++;
States[DpCount] = { id: praefix + room + ".RoomIsOpen", initial: false, forceCreation: false, common: { read: true, write: false, name: "Raum offen?", type: "boolean", role: "state", def: false } }; //
DpCount++;
States[DpCount] = { id: praefix + room + ".VentWarnTime", initial: 0, forceCreation: false, common: { read: true, write: true, name: "Anzahl der Tage nach der eine Lüftungsempfehlung erzeugt wird", unit: "Tage", type: "number", role: "state", def: 0 } };
DpCount++;
//log(Funktion + ': ' + room);
RoomList[z] = room;
RoomOpenCount[z] = 0; // Array mit 0 initialisieren
RoomOpenDoorCount[z] = 0; // Array mit 0 initialisieren
RoomTiltedDoorCount[z] = 0; // Array mit 0 initialisieren
RoomOpenWindowCount[z] = 0; // Array mit 0 initialisieren
RoomTiltedWindowCount[z] = 0; // Array mit 0 initialisieren
RoomWindowMsgCount[z] = 0;
RoomDoorMsgCount[z] = 0;
WindowWarnRuntime[z] = 0; // Array mit 0 initialisieren
DoorWarnRuntime[z] = 0; // Array mit 0 initialisieren
RoomsWithCombinedOpenings[z] = []; //Zweite Dimension für jeden Raum initialisieren
z++;
};
let TempIndex = RoomList.indexOf(room);
if (Funktion == WhichWindowFunctionToUse) { //Fenster
if (typeof RoomHas[TempIndex] == "undefined") { //Für Raum festlegen ob Türen und/oder Fenster überwacht werden. Steuert ein/aus-blenden der Tabellenbilder
RoomHas[TempIndex] = 2; // 0=Weder Tür noch Fenster, 1 Tür, 2 Fenster, 3 Tür und Fenster
}
else if (RoomHas[TempIndex] == 1) {
RoomHas[TempIndex] = 3;
};
SensorType[SensorCount] = "Window";
} else if (Funktion == WhichDoorFunctionToUse) { //Tür
if (typeof RoomHas[TempIndex] == "undefined") { //Für Raum festlegen ob Türen und/oder Fenster überwacht werden. Steuert ein/aus-blenden der Tabellenbilder
RoomHas[TempIndex] = 1; // 0=Weder Tür noch Fenster, 1=Tür, 2=Fenster, 3=Tür+Fenster
}
else if (RoomHas[TempIndex] == 2) {
RoomHas[TempIndex] = 3;
};
SensorType[SensorCount] = "Door";
};
if (logging) {
if (RoomHas[TempIndex] == 1) log("Raum- " + TempIndex + " = " + RoomList[TempIndex] + " hat Türsensor/en");
if (RoomHas[TempIndex] == 2) log("Raum- " + TempIndex + " = " + RoomList[TempIndex] + " hat Fenstersensor/en");
if (RoomHas[TempIndex] == 3) log("Raum- " + TempIndex + " = " + RoomList[TempIndex] + " hat Tür- und Fenstersensor/en");
};
//log("Sensor " + SensorCount + " in " + room + " =" + Sensor[SensorCount] + " SensorType[y]=" + SensorType[SensorCount] + " x=" + x + " Funktion=" + Funktion);
SensorCount++;
};
};
};
};
//Struktur anlegen in js.0 um Sollwert und Summenergebniss zu speichern
//Generische Datenpunkte vorbereiten
States[DpCount] = { id: praefix + "AllWindowsClosed", initial: true, forceCreation: false, common: { read: true, write: false, name: "Sind aktuell alle Fenster geschlossen?", type: "boolean", role: "state", def: true } }; //
DpCount++;
States[DpCount] = { id: praefix + "AllDoorsClosed", initial: true, forceCreation: false, common: { read: true, write: false, name: "Sind aktuell alle Türen geschlossen?", type: "boolean", role: "state", def: true } }; //
DpCount++;
States[DpCount] = { id: praefix + "WindowsOpen", initial: 0, forceCreation: false, common: { read: true, write: false, name: "Anzahl der geöffneten Fenster", type: "number", def: 0 } };
DpCount++;
States[DpCount] = { id: praefix + "DoorsOpen", initial: 0, forceCreation: false, common: { read: true, write: false, name: "Anzahl der geöffneten Türen", type: "number", def: 0 } };
DpCount++;
States[DpCount] = { id: praefix + "WindowsTilted", initial: 0, forceCreation: false, common: { read: true, write: false, name: "Anzahl der gekippten Fenster", type: "number", def: 0 } };
DpCount++;
States[DpCount] = { id: praefix + "DoorsTilted", initial: 0, forceCreation: false, common: { read: true, write: false, name: "Anzahl der gekippten Türen", type: "number", def: 0 } };
DpCount++;
States[DpCount] = { id: praefix + "RoomsWithOpenings", initial: "", forceCreation: false, common: { read: true, write: false, name: "In welchen Räumen sind Türen/Fenster geöffnet?", type: "string", def: "" } };
DpCount++;
States[DpCount] = { id: praefix + "RoomsWithOpenDoors", initial: "", forceCreation: false, common: { read: true, write: false, name: "In welchen Räumen sind Türen geöffnet?", type: "string", def: "" } };
DpCount++;
States[DpCount] = { id: praefix + "RoomsWithTiltedDoors", initial: "", forceCreation: false, common: { read: true, write: false, name: "In welchen Räumen sind Türen gekippt?", type: "string", def: "" } };
DpCount++;
States[DpCount] = { id: praefix + "RoomsWithOpenWindows", initial: "", forceCreation: false, common: { read: true, write: false, name: "In welchen Räumen sind Fenster geöffnet?", type: "string", def: "" } };
DpCount++;
States[DpCount] = { id: praefix + "RoomsWithTiltedWindows", initial: "", forceCreation: false, common: { read: true, write: false, name: "In welchen Räumen sind Fenster gekippt?", type: "string", def: "" } };
DpCount++;
States[DpCount] = { id: praefix + "RoomsWithVentWarnings", initial: "", forceCreation: false, common: { read: true, write: false, name: "In welchen Räumen ist eine Lüftungswarnung aktiv?", type: "string", def: "" } };
DpCount++;
States[DpCount] = { id: praefix + "LastMessage", initial: "", forceCreation: false, common: { read: true, write: false, name: "Die zuletzt ausgegebene Meldung?", type: "string", def: "" } };
DpCount++;
States[DpCount] = { id: praefix + "MessageLog", initial: "", forceCreation: false, common: { read: true, write: false, name: "Liste der letzten x ausgebenen Meldungen", type: "string", def: "" } };
DpCount++;
States[DpCount] = { id: praefix + "OverviewTable", initial: "", forceCreation: false, common: { read: true, write: false, name: "Übersicht aller Räume und geöffneten Fenster", type: "string", def: "" } };
DpCount++;
States[DpCount] = { id: praefix + "SendRoomsWithOpeningsMsg", initial: false, forceCreation: false, common: { read: true, write: true, name: "Übersicht der offenen Türen und Fenster senden?", type: "boolean", role: "state", def: false } }; //
DpCount++;
States[DpCount] = { id: praefix + "SendRoomsWithOpeningsMsgRefresh", initial: 60, forceCreation: false, common: { read: true, write: true, name: "Refreshzeit der Übersicht der offenen Türen und Fenster", type: "number", unit: "Min.", role: "state", min: 0, def: 60 } }; //
DpCount++;
States[DpCount] = { id: praefix + "MuteMode", initial: 0, forceCreation: false, common: { read: true, write: true, name: "Stummschalten?", type: "number", min: 0, max: 2, def: 0 } };
//Alle States anlegen, Main aufrufen wenn fertig
let numStates = States.length;
States.forEach(function (state) {
createState(state.id, state.initial, state.forceCreation, state.common, function () {
numStates--;
if (numStates === 0) {
if (logging) log("CreateStates fertig!");
InitialSort();
};
});
});
function InitialSort() {
let TempRoomHas = [];
let TempRoomList = [];
let AlphabeticalSortedRoomList = RoomList.join(","); //Raumliste zu kommaseparierten String wandeln
let OrderPriority;
TempRoomList = AlphabeticalSortedRoomList.split(","); //String wieder zurück zu Array wandeln
AlphabeticalSortedRoomList = TempRoomList.sort(); //Array sortieren
if (RoomSortMode == 1) { //Raumliste sortieren //alphabetisch
for (let x = 0; x < RoomList.length; x++) { //Raum Dps durchlaufen
OrderPriority = AlphabeticalSortedRoomList.indexOf(RoomList[x]);
TempRoomList[OrderPriority] = RoomList[x];
TempRoomHas[OrderPriority] = RoomHas[x];
};
RoomList = TempRoomList;
RoomHas = TempRoomHas;
}
else if (RoomSortMode == 2) {//benutzerdefiniert
for (let x = 0; x < RoomList.length; x++) { //Raum Dps durchlaufen
OrderPriority = getState(praefix + RoomList[x] + ".RoomOrderPriority").val; //benutzdefinierte Reihenfolge lesen
TempRoomList[OrderPriority] = RoomList[x]; //und an entsprechende Stelle schreiben
TempRoomHas[OrderPriority] = RoomHas[x]; //RoomHas synchron halten
};
RoomList = TempRoomList;
RoomHas = TempRoomHas;
};
//log(RoomList);
//log(TempRoomList);
//log(RoomHas);
//log(TempRoomHas);
//log(AlphabeticalSortedRoomList);
main();
}
function init() {
MessageLog = getState(praefix + "MessageLog").val;
MuteMode = getState(praefix + "MuteMode").val;
SendRoomsWithOpeningsMsg = getState(praefix + "SendRoomsWithOpeningsMsg").val;
SendRoomsWithOpeningsMsgRefresh = getState(praefix + "SendRoomsWithOpeningsMsgRefresh").val;
if (PresenceDp != "") Presence = getState(PresenceDp).val;
for (let x = 0; x < RoomList.length; x++) { //Messaging DPs einlesen
SendVentMsg[x] = getState(praefix + RoomList[x] + ".SendVentMsg").val;
SendDoorOpenCloseMsg[x] = getState(praefix + RoomList[x] + ".SendDoorOpenCloseMsg").val;
SendWindowOpenCloseMsg[x] = getState(praefix + RoomList[x] + ".SendWindowOpenCloseMsg").val;
SendWindowWarnMsg[x] = getState(praefix + RoomList[x] + ".SendWindowWarnMsg").val;
SendDoorWarnMsg[x] = getState(praefix + RoomList[x] + ".SendDoorWarnMsg").val;
if (logging) log("x=" + x + "=" + RoomList[x] + " SendWindowWarnMsg=" + SendWindowWarnMsg[x] + " SendDoorWarnMsg=" + SendDoorWarnMsg[x] + " SendVentMsg=" + SendVentMsg[x] + " SendWindowOpenCloseMsg=" + SendWindowOpenCloseMsg[x] + " SendDoorOpenCloseMsg=" + SendDoorOpenCloseMsg[x]);
};
for (let x = 0; x < Sensor.length; x++) { //Sensor Dps einlesen
SensorVal[x] = SimplyfyWindowStates(getState(Sensor[x]).val, x); // Wert von Sensor in Schleife einlesen
SensorOldVal[x] = "";
CheckWindow(x);
};
for (let x = 0; x < RoomList.length; x++) { //Raum Dps einlesen
RoomsWithVentWarnings[x] = "";
VentWarnTime[x] = getState(praefix + RoomList[x] + ".VentWarnTime").val; //Lüftungswarnzeiten einlesen
VentMsg[x] = ""; // Lüftungsnachricht mit Leerstring initialisieren
VentCheck(x);
};
IsInit = false;
}
function main() {
init(); //Bei Scriptstart alle Sensoren und Räume einlesen
CreateTrigger(); //Trigger erstellen
CreateRoomsWithOpenDoorsList(); //Übersichtsliste mit Räumen mit offenen Türen erstellen
CreateRoomsWithTiltedDoorsList(); //Übersichtsliste mit Räumen mit offenen Türen erstellen
CreateRoomsWithOpenWindowsList(); //Übersichtsliste mit Räumen mit offenen Fenstern erstellen
CreateRoomsWithTiltedWindowsList(); //Übersichtsliste mit Räumen mit gekippten Fenstern erstellen
CreateRoomsWithOpeningsList();//Übersichtsliste mit Räumen mit offenen Fenstern und Türen erstellen
CreateRoomsWithVentWarnings();//Übersichtsliste mit Räumen mit Lüftungswarnung erstellen
CreateOverviewTable(); //HTML Tabelle erstellen
Ticker(); //Minutenticker für Tabellenrefresh starten
RoomsWithOpeningsMsgRefresh(SendRoomsWithOpeningsMsgRefresh);
}
function RoomsWithOpeningsMsgRefresh(refresh) {
if (typeof RoomsWithOpeningsMsgRefreshTickerObj == "object") clearInterval(RoomsWithOpeningsMsgRefreshTickerObj);
RoomsWithOpeningsMsgRefreshTickerObj = setInterval(function () { // Wenn
// log("RoomsWithOpeningsMsgRefresh working, refreshtime=" + refresh)
if (SendRoomsWithOpeningsMsg && RoomsWithOpenings != "") {
if (RoomsWithOpenings.substr(RoomsWithOpenings.length - LogEntrySeparator.length, RoomsWithOpenings.length) == LogEntrySeparator) {//Wenn Umbruch am Ende
// log("A " + RoomsWithOpenings.substr(0, RoomsWithOpenings.length - LogEntrySeparator.length));
Meldung(RoomsWithOpenings.substr(0, RoomsWithOpenings.length - LogEntrySeparator.length)); //Umbruch am Ende entfernen
} else {
// log("B" + RoomsWithOpenings)
Meldung(RoomsWithOpenings);
};
};
}, refresh * 1000 * 60);
}
function Meldung(msg) {
if (logging) log("Reaching Meldung, msg= " + msg + " NoMsgAtPresence= " + NoMsgAtPresence + " Presence= " + Presence);
if (NoMsgAtPresence && Presence) {
if (logging) log("Meldung blocked cause, NoMsgAtPresence= " + NoMsgAtPresence + " Presence= " + Presence);
}
else {
if (MuteMode != 1 && MuteMode != 2) {
if (UseSay) Say(msg);
if (UseAlexa) {
if (AlexaId != "") setState(AlexaInstance + ".Echo-Devices." + AlexaId + ".Commands.announcement"/*announcement*/, AlexaVolume + "; " + msg);
};
};
if (MuteMode != 2) {
if (UseEventLog) {
WriteEventLog(msg);
};
if (UseTelegram) {
sendTo("telegram.0", "send", {
text: msg
});
};
if (UsePushOver) {
sendTo(PushOverInstance, "send", {
device: PushOverDevice, message: msg, title: PushOverTitle, sound: PushOverSound
});
};
if (UseMail) {
sendTo("email", {
html: msg
});
};
}
setState(praefix + "LastMessage", msg, true);
WriteMessageLog(msg);
};
}
function WriteMessageLog(msg) {
if (logging) log("Reaching WriteMessageLog, Message=" + msg);
let LogEntrys = 0; //Arrayeinträge zählen
let TempMessageLog = [];
if (MessageLog == null) { //Fehler "Cannot read property 'split' of null" abfangen
if (logging) log("MessageLog=null skiping split");
}
else {
TempMessageLog = MessageLog.split(LogEntrySeparator); //Logstring in Array wandeln (Entfernt den Separator, deswegen am Funktionsende wieder anhängen)
};
if (AutoAddTimestamp) {
LogEntrys = TempMessageLog.unshift(formatDate(new Date(), LogTimeStampFormat) + ": " + msg); //neuen Eintrag am Anfang des Array einfügen, Rückgabewert setzt Zähler
} else {
LogEntrys = TempMessageLog.unshift(msg); //neuen Eintrag am Anfang des Array einfügen, Rückgabewert setzt Zähler
};
if (LogEntrys > MaxLogEntrys) { //Wenn durchs anfügen MaxLogEntrys überschritten, einen Eintrag am Ende entfernen
TempMessageLog.splice(MaxLogEntrys - LogEntrys); //Vom Ende des Arrays benötigte Anzahl Einträge löschen. Berücksichtig auch Einstellungsänderung auf niedrigere Zahl.
LogEntrys = TempMessageLog.length;
};
// log("TempMessageLog=" + TempMessageLog + " Logentrys=" + LogEntrys);
MessageLog = TempMessageLog.join(LogEntrySeparator); //Array zu String wandeln und Separator anhängen
setState(praefix + "MessageLog", MessageLog, true); //Logstring schreiben
}
function CreateOverviewTable() { // Erzeugt tabellarische Übersicht als HTML Tabelle
let OverviewTable = "";
let TableSubString = [];
TableSubString[0] = "<td style='border: 1px solid black; background-color:";
TableSubString[1] = ";'><img style='margin: auto; display: block; filter: invert(";
//TableSubString[2] = ";'><img style='margin: auto; display: block; opacity: 0.2; filter: invert(";
TableSubString[3] = "<td colspan='2' style='border: 1px solid black; background-color:";
TableSubString[5] = "<td style='border: 1px solid black; padding-left: 10px; padding-right: 10px; font-size:16px; font-weight: bold; text-align:center;background-color:";
TableSubString[6] = "<td style='border: 1px solid black; padding-left: 10px; padding-right: 10px; padding-top: 4px; font-size: 16px; font-weight: bold; background-color:";
//Überschrift
if (ShowCaptionTbl) {
OverviewTable += "<table style='width:100%; border-collapse: collapse; border: 0px solid black;'><tr><td style='height: 20px; text-align:center; padding-top: 5px; font-size:20px; font-weight: bold;'>Fensterstatus</td></tr></table>"
};
//Zusammenfassung
if (ShowSummaryTbl) {
OverviewTable += "<table style='width:100%; border-collapse: collapse; border: 0px solid black;'><tr><td style='height: 20px; text-align:center; padding-top: 5px; padding-bottom: 5px; font-size:14px; font-weight: normal;'>" + RoomsWithOpenings + "</td></tr></table>";
};
// Details / Head
if (ShowDetailTbl) {
OverviewTable += "<table style='width:100%; border-collapse: collapse;'>";
OverviewTable += "<thead><tr>";
OverviewTable += "<th width='40px' style='text-align:left;'</th>";
OverviewTable += "<th width='40px' style='text-align:left;'</th>";
OverviewTable += "<th width='20px' style='text-align:center;'></th><th style='text-align:left;'></th></tr></thead><tbody>";
//Tabelle der Raumdetails
for (let x = 0; x < RoomList.length; x++) { //Alle Räume durchgehen
OverviewTable += "<tr>";
RoomStateTimeCount[x] = CalcTimeDiff("now", RoomStateTimeStamp[x]);
RoomDoorStateTimeCount[x] = CalcTimeDiff("now", RoomDoorStateTimeStamp[x]);
//log("x=" + x + " Raum = "+RoomList[x] + " RoomStateTimeCount[x] = "+CreateTimeString(RoomStateTimeCount[x]) +" RoomDoorStateTimeCount[x] = "+CreateTimeString(RoomDoorStateTimeCount[x]))
if (RoomOpenWindowCount[x] > 0 || RoomOpenDoorCount[x] > 0) { // Räume mit offenen Fenstern oder Türen
if (RoomTiltedWindowCount[x] == 0 && RoomOpenWindowCount[x] > 0 && RoomOpenDoorCount[x] == 0) { //Fenster ist offen, keines ist gekippt, Tür/en sind geschlossen
if (RoomHas[x] == 2) { //RoomHas[] 1=Tür, 2=Fenster, 3=Tür+Fenster
OverviewTable += TableSubString[3] + OpenWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowOpenImg + "'></td>";
} else if (RoomHas[x] == 1) {
OverviewTable += TableSubString[3] + ClosedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorCloseImg + "'></td>";
} else {
OverviewTable += TableSubString[0] + OpenWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowOpenImg + "'></td>";
OverviewTable += TableSubString[0] + ClosedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorCloseImg + "'></td>";
};
OverviewTable += TableSubString[5] + OpenWindowColor + ";'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += RoomOpenWindowCount[x] + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += RoomOpenDoorCount[x];
OverviewTable += "</td>";
OverviewTable += TableSubString[6] + OpenWindowColor + ";'>" + ReplaceChars(RoomList[x]) + "<br><div style='font-size:12px; font-weight:bold;'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += "Fenster geöffnet: " + CreateTimeString(RoomStateTimeCount[x]) + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += "Tür geschlossen: " + CreateTimeString(RoomDoorStateTimeCount[x]);
}
else if (RoomTiltedWindowCount[x] > 0 && RoomTiltedWindowCount[x] == RoomOpenWindowCount[x] && RoomOpenDoorCount[x] == 0) { //Fenster ist gekippt, Tür/en sind geschlossen
if (RoomHas[x] == 2) { //RoomHas[] 0=Weder Tür noch Fenster, 1=Tür, 2=Fenster, 3=Tür+Fenster
OverviewTable += TableSubString[3] + TiltedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowTiltedImg + "'></td>";
} else if (RoomHas[x] == 1) {
OverviewTable += TableSubString[3] + ClosedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorCloseImg + "'></td>";
} else {
OverviewTable += TableSubString[0] + TiltedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowTiltedImg + "'></td>";
OverviewTable += TableSubString[0] + ClosedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorCloseImg + "'></td>";
};
OverviewTable += TableSubString[5] + TiltedWindowColor + ";'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += RoomOpenWindowCount[x] + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += RoomOpenDoorCount[x];
OverviewTable += "</td>";
OverviewTable += TableSubString[6] + TiltedWindowColor + ";'>" + ReplaceChars(RoomList[x]) + "<br><div style='font-size:12px; font-weight:bold;'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += "Fenster gekippt:" + CreateTimeString(RoomStateTimeCount[x]) + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += "Tür geschlossen:" + CreateTimeString(RoomDoorStateTimeCount[x]);
}
else if (RoomTiltedWindowCount[x] < RoomOpenWindowCount[x] && RoomOpenDoorCount[x] == 0) { // Fenster sind offen und gekippt, Tür/en sind geschlossen
if (RoomHas[x] == 2) { //RoomHas[] 0=Weder Tür noch Fenster, 1=Tür, 2=Fenster, 3=Tür+Fenster
OverviewTable += TableSubString[3] + OpenWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowOpenTiltedImg + "'></td>";
} else if (RoomHas[x] == 1) {
OverviewTable += TableSubString[3] + ClosedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorCloseImg + "'></td>";
} else {
OverviewTable += TableSubString[0] + OpenWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowOpenTiltedImg + "'></td>";
OverviewTable += TableSubString[0] + ClosedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorCloseImg + "'></td>";
};
OverviewTable += TableSubString[5] + OpenWindowColor + ";'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += RoomOpenWindowCount[x] + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += RoomOpenDoorCount[x];
OverviewTable += "</td>";
OverviewTable += TableSubString[6] + OpenWindowColor + ";'>" + ReplaceChars(RoomList[x]) + "<br><div style='font-size:12px; font-weight:bold;'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += "Fenster geöffnet/gekippt:" + CreateTimeString(RoomStateTimeCount[x]) + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += "Tür geschlossen: " + CreateTimeString(RoomDoorStateTimeCount[x]);
}
//*****************
if (RoomTiltedDoorCount[x] > 0 && RoomOpenWindowCount[x] == 0) { // Tür/en gekippt, kein Fenster ist geöffnet
if (RoomHas[x] == 2) { //RoomHas[] 1=Tür, 2=Fenster, 3=Tür+Fenster
OverviewTable += TableSubString[3] + ClosedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowCloseImg + "'></td>";
} else if (RoomHas[x] == 1) {
OverviewTable += TableSubString[3] + TiltedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorTiltedImg + "'></td>";
} else {
OverviewTable += TableSubString[0] + ClosedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowCloseImg + "'></td>";
OverviewTable += TableSubString[0] + TiltedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorTiltedImg + "'></td>";
};
OverviewTable += TableSubString[5] + OpenDoorColor + ";'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += RoomOpenWindowCount[x] + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += RoomOpenDoorCount[x];
OverviewTable += "</td>";
OverviewTable += TableSubString[6] + OpenDoorColor + ";'>" + ReplaceChars(RoomList[x]) + "<br><div style='font-size:12px; font-weight:bold;'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += "Fenster geschlossen: " + CreateTimeString(RoomStateTimeCount[x]) + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += "Tür gekippt: " + CreateTimeString(RoomDoorStateTimeCount[x]);
}
else if (RoomOpenWindowCount[x] > 0 && RoomTiltedWindowCount[x] == 0 && RoomTiltedDoorCount[x] > 0) { //Fenster ist offen, keines ist gekippt, Tür/en sind gekippt
if (RoomHas[x] == 2) { //RoomHas[] 1=Tür, 2=Fenster, 3=Tür+Fenster
OverviewTable += TableSubString[3] + OpenWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowOpenImg + "'></td>";
} else if (RoomHas[x] == 1) {
OverviewTable += TableSubString[3] + TiltedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorTiltedImg + "'></td>";
} else {
OverviewTable += TableSubString[0] + OpenWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowOpenImg + "'></td>";
OverviewTable += TableSubString[0] + TiltedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorTiltedImg + "'></td>";
};
OverviewTable += TableSubString[5] + OpenWindowColor + ";'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += RoomOpenWindowCount[x] + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += RoomOpenDoorCount[x];
OverviewTable += "</td>";
OverviewTable += TableSubString[6] + OpenWindowColor + ";'>" + ReplaceChars(RoomList[x]) + "<br><div style='font-size:12px; font-weight:bold;'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += "Fenster geöffnet: " + CreateTimeString(RoomStateTimeCount[x]) + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += "Tür gekippt: " + CreateTimeString(RoomDoorStateTimeCount[x]);
}
else if (RoomTiltedWindowCount[x] > 0 && RoomTiltedWindowCount[x] == RoomOpenWindowCount[x] && RoomTiltedDoorCount[x] > 0) { //Fenster ist gekippt, Tür/en sind gekippt
if (RoomHas[x] == 2) { //RoomHas[] 0=Weder Tür noch Fenster, 1=Tür, 2=Fenster, 3=Tür+Fenster
OverviewTable += TableSubString[3] + TiltedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowTiltedImg + "'></td>";
} else if (RoomHas[x] == 1) {
OverviewTable += TableSubString[3] + TiltedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorTiltedImg + "'></td>";
} else {
OverviewTable += TableSubString[0] + TiltedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowTiltedImg + "'></td>";
OverviewTable += TableSubString[0] + TiltedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorTiltedImg + "'></td>";
};
OverviewTable += TableSubString[5] + TiltedWindowColor + ";'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += RoomOpenWindowCount[x] + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += RoomOpenDoorCount[x];
OverviewTable += "</td>";
OverviewTable += TableSubString[6] + TiltedWindowColor + ";'>" + ReplaceChars(RoomList[x]) + "<br><div style='font-size:12px; font-weight:bold;'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += "Fenster gekippt: " + CreateTimeString(RoomStateTimeCount[x]) + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += "Tür gekippt: " + CreateTimeString(RoomDoorStateTimeCount[x]);
}
else if (RoomOpenWindowCount[x] > 0 && RoomTiltedWindowCount[x] < RoomOpenWindowCount[x] && RoomTiltedDoorCount[x] > 0) { // Fenster sind offen und gekippt, Tür/en sind gekippt
if (RoomHas[x] == 2) { //RoomHas[] 0=Weder Tür noch Fenster, 1=Tür, 2=Fenster, 3=Tür+Fenster
OverviewTable += TableSubString[3] + OpenWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowOpenTiltedImg + "'></td>";
} else if (RoomHas[x] == 1) {
OverviewTable += TableSubString[3] + TiltedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorTiltedImg + "'></td>";
} else {
OverviewTable += TableSubString[0] + OpenWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowOpenTiltedImg + "'></td>";
OverviewTable += TableSubString[0] + TiltedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorTiltedImg + "'></td>";
};
OverviewTable += TableSubString[5] + OpenWindowColor + ";'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += RoomOpenWindowCount[x] + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += RoomOpenDoorCount[x];
OverviewTable += "</td>";
OverviewTable += TableSubString[6] + OpenWindowColor + ";'>" + ReplaceChars(RoomList[x]) + "<br><div style='font-size:12px; font-weight:bold;'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += "Fenster geöffnet/gekippt: " + CreateTimeString(RoomStateTimeCount[x]) + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += "Tür gekippt: " + CreateTimeString(RoomDoorStateTimeCount[x]);
}
//*******************/
else if (RoomOpenDoorCount[x] > 0 && RoomOpenWindowCount[x] == 0) { // Tür/en geöffnet, kein Fenster ist geöffnet
if (RoomHas[x] == 2) { //RoomHas[] 0=Weder Tür noch Fenster, 1=Tür, 2=Fenster, 3=Tür+Fenster
OverviewTable += TableSubString[3] + ClosedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowCloseImg + "'></td>";
} else if (RoomHas[x] == 1) {
OverviewTable += TableSubString[3] + OpenDoorColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorOpenImg + "'></td>";
} else {
OverviewTable += TableSubString[0] + ClosedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowCloseImg + "'></td>";
OverviewTable += TableSubString[0] + OpenDoorColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorOpenImg + "'></td>";
};
OverviewTable += TableSubString[5] + OpenDoorColor + ";'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += RoomOpenWindowCount[x] + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += RoomOpenDoorCount[x];
OverviewTable += "</td>";
OverviewTable += TableSubString[6] + OpenDoorColor + ";'>" + ReplaceChars(RoomList[x]) + "<br><div style='font-size:12px; font-weight:bold;'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += "Fenster geschlossen: " + CreateTimeString(RoomStateTimeCount[x]) + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += "Tür geöffnet: " + CreateTimeString(RoomDoorStateTimeCount[x]);
}
else if (RoomOpenWindowCount[x] > 0 && RoomTiltedWindowCount[x] == 0 && RoomOpenDoorCount[x] > 0) { //Fenster ist offen, keines ist gekippt, Tür/en sind geöffnet
if (RoomHas[x] == 2) { //RoomHas[] 0=Weder Tür noch Fenster, 1=Tür, 2=Fenster, 3=Tür+Fenster
OverviewTable += TableSubString[3] + OpenWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowOpenImg + "'></td>";
} else if (RoomHas[x] == 1) {
OverviewTable += TableSubString[3] + OpenDoorColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorOpenImg + "'></td>";
} else {
OverviewTable += TableSubString[0] + OpenWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowOpenImg + "'></td>";
OverviewTable += TableSubString[0] + OpenDoorColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorOpenImg + "'></td>";
};
OverviewTable += TableSubString[5] + OpenWindowColor + ";'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += RoomOpenWindowCount[x] + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += RoomOpenDoorCount[x];
OverviewTable += "</td>";
OverviewTable += TableSubString[6] + OpenWindowColor + ";'>" + ReplaceChars(RoomList[x]) + "<br><div style='font-size:12px; font-weight:bold;'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += "Fenster geöffnet: " + CreateTimeString(RoomStateTimeCount[x]) + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += "Tür geöffnet: " + CreateTimeString(RoomDoorStateTimeCount[x]);
}
else if (RoomTiltedWindowCount[x] > 0 && RoomTiltedWindowCount[x] == RoomOpenWindowCount[x] && RoomOpenDoorCount[x] > 0) { //Fenster ist gekippt, Tür/en sind geöffnet
if (RoomHas[x] == 2) { //RoomHas[] 0=Weder Tür noch Fenster, 1=Tür, 2=Fenster, 3=Tür+Fenster
OverviewTable += TableSubString[3] + TiltedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowTiltedImg + "'></td>";
} else if (RoomHas[x] == 1) {
OverviewTable += TableSubString[3] + OpenDoorColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorOpenImg + "'></td>";
} else {
OverviewTable += TableSubString[0] + TiltedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowTiltedImg + "'></td>";
OverviewTable += TableSubString[0] + OpenDoorColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorOpenImg + "'></td>";
};
OverviewTable += TableSubString[5] + TiltedWindowColor + ";'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += RoomOpenWindowCount[x] + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += RoomOpenDoorCount[x];
OverviewTable += "</td>";
OverviewTable += TableSubString[6] + TiltedWindowColor + ";'>" + ReplaceChars(RoomList[x]) + "<br><div style='font-size:12px; font-weight:bold;'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += "Fenster gekippt: " + CreateTimeString(RoomStateTimeCount[x]) + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += "Tür geöffnet: " + CreateTimeString(RoomDoorStateTimeCount[x]);
}
else if (RoomOpenWindowCount[x] > 0 && RoomTiltedWindowCount[x] < RoomOpenWindowCount[x] && RoomOpenDoorCount[x] > 0) { // Fenster sind offen und gekippt, Tür/en sind geöffnet
if (RoomHas[x] == 2) { //RoomHas[] 0=Weder Tür noch Fenster, 1=Tür, 2=Fenster, 3=Tür+Fenster
OverviewTable += TableSubString[3] + OpenWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowOpenTiltedImg + "'></td>";
} else if (RoomHas[x] == 1) {
OverviewTable += TableSubString[3] + OpenDoorColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorOpenImg + "'></td>";
} else {
OverviewTable += TableSubString[0] + OpenWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + WindowOpenTiltedImg + "'></td>";
OverviewTable += TableSubString[0] + OpenDoorColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorOpenImg + "'></td>";
};
OverviewTable += TableSubString[5] + OpenWindowColor + ";'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += RoomOpenWindowCount[x] + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += RoomOpenDoorCount[x];
OverviewTable += "</td>";
OverviewTable += TableSubString[6] + OpenWindowColor + ";'>" + ReplaceChars(RoomList[x]) + "<br><div style='font-size:12px; font-weight:bold;'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += "Fenster geöffnet/gekippt: " + CreateTimeString(RoomStateTimeCount[x]) + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += "Tür geöffnet: " + CreateTimeString(RoomDoorStateTimeCount[x]);
}
OverviewTable += "</td></tr>";
}
else { // Geschlossene Räume
if (VentMsg[x] == "") { //geschlossen + keine Lüftungswarnung
if (RoomHas[x] == 2) { //RoomHas[] 0=Weder Tür noch Fenster, 1=Tür, 2=Fenster, 3=Tür+Fenster
OverviewTable += TableSubString[3] + ClosedWindowColor + ";'><img style=' margin: auto; display: block; filter: invert(" + ImgInvert + "); height: 40px;' src='" + WindowCloseImg + "'></td>";
} else if (RoomHas[x] == 1) {
OverviewTable += TableSubString[3] + ClosedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorCloseImg + "'></td>";
} else {
OverviewTable += TableSubString[0] + ClosedWindowColor + ";'><img style=' margin: auto; display: block; filter: invert(" + ImgInvert + "); height: 40px;' src='" + WindowCloseImg + "'></td>";
OverviewTable += TableSubString[0] + ClosedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorCloseImg + "'></td>";
};
OverviewTable += "<td style='border: 1px solid black; padding-left: 10px; padding-right: 10px; font-size:16px; font-weight: bold; text-align:center; background-color:" + ClosedWindowColor + ";'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += RoomOpenWindowCount[x] + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += RoomOpenDoorCount[x];
OverviewTable += "</td>";
if (RoomHas[x] == 2) OverviewTable += TableSubString[6] + ClosedWindowColor + ";'>" + ReplaceChars(RoomList[x]) + "<br><div style='font-size:12px; font-weight:normal;'>Fenster geschlossen: " + CreateTimeString(RoomStateTimeCount[x]) + "<br>";
if (RoomHas[x] == 1) OverviewTable += TableSubString[6] + ClosedWindowColor + ";'>" + ReplaceChars(RoomList[x]) + "<br><div style='font-size:12px; font-weight:normal;'>Tür geschlossen: " + CreateTimeString(RoomDoorStateTimeCount[x]);
if (RoomHas[x] == 3) OverviewTable += TableSubString[6] + ClosedWindowColor + ";'>" + ReplaceChars(RoomList[x]) + "<br><div style='font-size:12px; font-weight:normal;'>Fenster geschlossen: " + CreateTimeString(RoomStateTimeCount[x]) + "<br><div style='font-size:12px; font-weight:normal;'>Tür geschlossen: " + CreateTimeString(RoomDoorStateTimeCount[x]);
OverviewTable += "</div></td></tr>"
}
else { //geschlossen + Lüftungswarnung
if (RoomHas[x] == 2) { //RoomHas[] 0=Weder Tür noch Fenster, 1=Tür, 2=Fenster, 3=Tür+Fenster
OverviewTable += TableSubString[3] + VentWarnColor + ";'><img style=' margin: auto; display: block; filter: invert(" + ImgInvert + "); height: 40px;' src='" + VentImg + "'></td>";
} else if (RoomHas[x] == 1) {
OverviewTable += TableSubString[3] + ClosedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorOpenImg + "'></td>";
} else {
OverviewTable += TableSubString[0] + VentWarnColor + ";'><img style=' margin: auto; display: block; filter: invert(" + ImgInvert + "); height: 40px;' src='" + VentImg + "'></td>";
OverviewTable += TableSubString[0] + ClosedWindowColor + TableSubString[1] + ImgInvert + "); height: 40px;' src='" + DoorOpenImg + "'></td>";
};
OverviewTable += "<td style='border: 1px solid black; padding-left: 10px; padding-right: 10px; font-size:16px; font-weight: bold; text-align:center; background-color:" + VentWarnColor + ";'>";
if (RoomHas[x] == 2 || RoomHas[x] == 3) OverviewTable += RoomOpenWindowCount[x] + "<br>";
if (RoomHas[x] == 1 || RoomHas[x] == 3) OverviewTable += RoomOpenDoorCount[x];
OverviewTable += "</td>";
OverviewTable += TableSubString[6] + VentWarnColor + ";'>" + ReplaceChars(RoomList[x]) + "<br><div style='font-size:12px; font-weight:bold;'>Raum nicht gelüftet: " + CreateTimeString(RoomStateTimeCount[x]);
OverviewTable += "</div></td></tr>";
};
};
};
OverviewTable += "</tbody></table>";
};
setState(praefix + "OverviewTable", OverviewTable, true);
}
function CalcTimeDiff(time1, time2) {
if (time1 == "now") {
time1 = new Date().getTime();
};
//if (logging) log("Reaching CalcTimeDiff, time1=" + time1 + ", time2=" + time2 + ", result= " + CreateTimeString(time1 - time2));
return (time1 - time2);
}
function Ticker() {
setInterval(function () { // Wenn
//if (logging) log("Refreshing OverviewTable")
CreateOverviewTable();
}, 60000);
}
function ReplaceChars(OrigString) {
//log(typeof OrigString)
if (typeof OrigString == "undefined") OrigString = "";
let NewString = OrigString.replace("_", " ");
NewString = NewString.replace("ae", "ä");
NewString = NewString.replace("ue", "ü");
NewString = NewString.replace("oe", "ö");
return NewString;
}
function CreateRoomsWithOpenWindowsList() { //Erzeugt Textliste mit Räumen welche geöffnete Fenster haben
if (logging) log("Reaching CreateRoomsWithOpenWindowsList");
RoomsWithOpenWindows = ""; //Liste Initialisieren
for (let x = 0; x < RoomList.length; x++) { //Alle Räume durchgehen
//RoomsWithCombinedOpenings[x] = [];
if (RoomOpenWindowCount[x] > 0) { // Nur Räume mit offenen Fenstern berücksichtigen
if (RoomOpenWindowCount[x] == 1) { //Wenn 1 Fenster offen, Singular Schreibweise
if (RoomTiltedWindowCount[x] == 1) { //Wenn das eine Fenster gekippt ist
RoomsWithOpenWindows += ReplaceChars(RoomList[x]) + " " + RoomOpenWindowCount[x] + " gekipptes Fenster" + OpenWindowListSeparator;
RoomsWithCombinedOpenings[x][0] = RoomOpenWindowCount[x] + " gekipptes Fenster";
}
else {
RoomsWithOpenWindows += ReplaceChars(RoomList[x]) + " " + RoomOpenWindowCount[x] + " offenes Fenster" + OpenWindowListSeparator;
RoomsWithCombinedOpenings[x][0] = RoomOpenWindowCount[x] + " offenes Fenster";
};
}
else { //ansonsten Plural Schreibweise
if (RoomTiltedWindowCount[x] == RoomOpenWindowCount[x]) { //Wenn gekippte Fenster = offene Fenster
RoomsWithOpenWindows += RoomTiltedWindowCount[x] + " gekippte Fenster" + OpenWindowListSeparator;
RoomsWithCombinedOpenings[x][0] = RoomOpenWindowCount[x] + " gekippte Fenster";
}
else {
RoomsWithOpenWindows += ReplaceChars(RoomList[x]) + " " + RoomOpenWindowCount[x] + " offene Fenster" + OpenWindowListSeparator;
RoomList[x][0] = RoomOpenWindowCount[x] + " offene Fenster";
RoomsWithCombinedOpenings[x][0] = RoomOpenWindowCount[x] + " offene Fenster";
if (RoomTiltedWindowCount[x] == 1) { //Wenn 1 Fenster gekippt Singular schreibweise
RoomsWithOpenWindows += " davon " + RoomTiltedWindowCount[x] + " gekipptes Fenster" + OpenWindowListSeparator;
RoomsWithCombinedOpenings[x][0] = RoomOpenWindowCount[x] + " offene Fenster," + " davon " + RoomTiltedWindowCount[x] + " gekipptes Fenster";
}
else if (RoomTiltedWindowCount[x] > 1) { //ansonsten Plural Schreibweise
RoomsWithOpenWindows += " davon " + RoomTiltedWindowCount[x] + " gekippte Fenster" + OpenWindowListSeparator;
RoomsWithCombinedOpenings[x][0] = RoomOpenWindowCount[x] + " offene Fenster," + " davon " + RoomTiltedWindowCount[x] + " gekippte Fenster";
};
};
};
} else {
RoomsWithCombinedOpenings[x][0] = "Alle Fenster sind geschlossen";
};
};
RoomsWithOpenWindows = RoomsWithOpenWindows.substr(0, RoomsWithOpenWindows.length - OpenWindowListSeparator.length); //letzten <br> Umbruch wieder entfernen
if (RoomsWithOpenWindows == "") {
RoomsWithOpenWindows = "Alle Fenster sind geschlossen";
};
setState(praefix + "RoomsWithOpenWindows", RoomsWithOpenWindows, true);
if (logging) log("RoomsWithOpenWindows: " + RoomsWithOpenWindows);
}
function CreateRoomsWithTiltedWindowsList() { //Erzeugt Textliste mit Räumen welche gekippte Fenster haben
if (logging) log("Reaching CreateRoomsWithTiltedWindowsList");
RoomsWithTiltedWindows = ""; //Liste Initialisieren
for (let x = 0; x < RoomList.length; x++) { //Alle Räume durchgehen
if (RoomTiltedWindowCount[x] > 0) { // Nur Räume mit gekippten Fenstern berücksichtigen
if (RoomTiltedWindowCount[x] == 1) { //Wenn 1 Fenster gekippt, Singular Schreibweise
RoomsWithTiltedWindows += ReplaceChars(RoomList[x]) + " " + RoomTiltedWindowCount[x] + " gekipptes Fenster" + OpenWindowListSeparator;
}
else { //ansonsten Plural Schreibweise
RoomsWithTiltedWindows += ReplaceChars(RoomList[x]) + " " + RoomOpenWindowCount[x] + " gekippte Fenster" + OpenWindowListSeparator;
};
};
};
RoomsWithTiltedWindows = RoomsWithTiltedWindows.substr(0, RoomsWithTiltedWindows.length - OpenWindowListSeparator.length); //letzten <br> Umbruch wieder entfernen
if (RoomsWithTiltedWindows == "") {
RoomsWithTiltedWindows = "Keine Fenster gekippt";
};
setState(praefix + "RoomsWithTiltedWindows", RoomsWithTiltedWindows, true);
if (logging) log("RoomsWithTiltedWindows: " + RoomsWithTiltedWindows);
}
function CreateRoomsWithOpenDoorsList() { //Erzeugt Textliste mit Räumen welche offene Türen haben
if (logging) log("Reaching CreateRoomsWithOpenDoorsList");
RoomsWithOpenDoors = ""; //Liste Initialisieren
for (let x = 0; x < RoomList.length; x++) { //Alle Räume durchgehen
//RoomsWithCombinedOpenings[x] = [];
if (RoomOpenDoorCount[x] > 0) { // Nur Räume mit offenen Türen berücksichtigen
if (RoomOpenDoorCount[x] == 1) { //Wenn 1 Tür offen, Singular Schreibweise
RoomsWithOpenDoors += ReplaceChars(RoomList[x]) + " " + RoomOpenDoorCount[x] + " offene Tür" + OpenWindowListSeparator;
RoomsWithCombinedOpenings[x][1] = RoomOpenDoorCount[x] + " offene Tür";
}
else { //ansonsten Plural Schreibweise
RoomsWithOpenDoors += ReplaceChars(RoomList[x]) + " " + RoomOpenDoorCount[x] + " offene Türen" + OpenWindowListSeparator;
RoomsWithCombinedOpenings[x][1] = RoomOpenDoorCount[x] + " offene Türen";
};
} else {
RoomsWithCombinedOpenings[x][1] = "Keine Tür/en geöffnet";
};
};
RoomsWithOpenDoors = RoomsWithOpenDoors.substr(0, RoomsWithOpenDoors.length - OpenWindowListSeparator.length); //letzten <br> Umbruch wieder entfernen
if (RoomsWithOpenDoors == "") {
RoomsWithOpenDoors = "Keine Tür/en geöffnet";
};
setState(praefix + "RoomsWithOpenDoors", RoomsWithOpenDoors, true);
if (logging) log("RoomsWithOpenDoors: " + RoomsWithOpenDoors);
}
function CreateRoomsWithTiltedDoorsList() { //Erzeugt Textliste mit Räumen welche gekippte Türen haben
if (logging) log("Reaching CreateRoomsWithTiltedDoorsList");
RoomsWithTiltedDoors = ""; //Liste Initialisieren
for (let x = 0; x < RoomList.length; x++) { //Alle Räume durchgehen
if (RoomTiltedDoorCount[x] > 0) { // Nur Räume mit gekippten Türen berücksichtigen
if (RoomTiltedDoorCount[x] == 1) { //Wenn 1 Tür gekippt, Singular Schreibweise
RoomsWithTiltedDoors += ReplaceChars(RoomList[x]) + " " + RoomTiltedDoorCount[x] + " gekippte Tür" + OpenWindowListSeparator;
}
else { //ansonsten Plural Schreibweise
RoomsWithTiltedDoors += ReplaceChars(RoomList[x]) + " " + RoomTiltedDoorCount[x] + " gekippte Türen" + OpenWindowListSeparator;
};
};
};
RoomsWithTiltedDoors = RoomsWithTiltedDoors.substr(0, RoomsWithTiltedDoors.length - OpenWindowListSeparator.length); //letzten <br> Umbruch wieder entfernen
if (RoomsWithTiltedDoors == "") {
RoomsWithTiltedDoors = "Keine Tür gekippt";
};
setState(praefix + "RoomsWithTiltedDoors", RoomsWithTiltedDoors, true);
if (logging) log("RoomsWithTiltedDoors: " + RoomsWithTiltedDoors);
}
function CreateRoomsWithOpeningsList() { //Erzeugt Textliste mit Räumen welche offene Türen und/oder Fenster haben
if (logging) log("CreateOpenRoomsList()");
RoomsWithOpenings = "";
for (let x = 0; x < RoomList.length; x++) { //Alle Räume durchgehen
if (RoomOpenWindowCount[x] == 0 && RoomOpenDoorCount[x] > 0) {
RoomsWithOpenings += ReplaceChars(RoomList[x]) + " " + RoomsWithCombinedOpenings[x][1] + OpenWindowListSeparator;
}
else if (RoomOpenWindowCount[x] > 0 && RoomOpenDoorCount[x] == 0) {
RoomsWithOpenings += ReplaceChars(RoomList[x]) + " " + RoomsWithCombinedOpenings[x][0] + OpenWindowListSeparator;
}
else if (RoomOpenWindowCount[x] > 0 && RoomOpenDoorCount[x] > 0) {
RoomsWithOpenings += ReplaceChars(RoomList[x]) + " " + RoomsWithCombinedOpenings[x].join(", ") + OpenWindowListSeparator;
}
};
setState(praefix + "RoomsWithOpenings", RoomsWithOpenings, true);
if (logging) log("RoomsWithOpenings: " + RoomsWithOpenings);
}
function CreateRoomsWithVentWarnings(x, Warning) { //Erzeugt Liste mit Räumen für die eine Lüftungswarnung besteht
let Tempstring = "";
if (logging) log("Reaching CreateRoomsWithVentWarnings");
RoomsWithVentWarnings[x] = Warning;
for (let y = 0; y < RoomsWithVentWarnings.length; y++) {
if (RoomsWithVentWarnings[y] != "")
Tempstring += RoomList[y] + " nicht gelüftet seit: " + RoomsWithVentWarnings[y] + OpenWindowListSeparator;
};
Tempstring = Tempstring.substr(0, Tempstring.length - OpenWindowListSeparator.length);
setState(praefix + "RoomsWithVentWarnings", Tempstring, true);
}
function VentCheck(x) { //Überprüft wie lange Räume geschlossen sind und gibt Lüftungswarnung aus
if (logging) log("Reaching VentCheck x=" + x + " Init=" + IsInit + " VentwarnTime[x]=" + VentWarnTime[x] + " RoomStateTimeStamp[x]=" + RoomStateTimeStamp[x]);
if (RoomOpenWindowCount[x] == 0 && VentWarnTime[x] != 0) { //VentTimeout starten wenn alle Fenster im Raum geschlossen und Warnzeit nicht 0 (= deaktiviert)
if (logging) log("Starting VentInterval for Room " + RoomList[x] + " Time set to: " + VentWarnTime[x] + " days");
if (IsInit) { //Bei Skriptstart
if (CalcTimeDiff("now", RoomStateTimeStamp[x]) >= getDateObject(VentWarnTime[x] * 24 * 60 * 60 * 1000).getTime()) { //Wenn Ventwarnzeit bei Skriptstart schon überschritten, sofortige Meldung
VentMsg[x] = CreateTimeString(RoomStateTimeCount[x]);
CreateRoomsWithVentWarnings(x, VentMsg[x]);
if (SendVentMsg[x]) Meldung(ReplaceChars(RoomList[x]) + " nicht gelüftet " + VentMsg[x]);
} else { //Wenn Ventwarnzeit bei Skriptstart noch nicht überschritten, Restzeit berechnen und einmaligen Timeout starten welcher bei Ablauf den regulären Interval startet
if (logging) log("Remaining Vent Warn DiffTime at startup= " + CreateTimeString(CalcTimeDiff(VentWarnTime[x] * 24 * 60 * 60 * 1000, RoomStateTimeCount[x])))
VentMsgHandler[x] = setTimeout(function () {
RoomStateTimeCount[x] = CalcTimeDiff("now", RoomStateTimeStamp[x]); //RoomstateTimeCount aktualisieren um exakten Wert bei Ausgabe zu haben und 23 Stunden 59 Minuten Meldungen zu vermeiden
VentMsg[x] = CreateTimeString(RoomStateTimeCount[x]);
CreateRoomsWithVentWarnings(x, VentMsg[x]);
if (SendVentMsg[x]) {
Meldung(ReplaceChars(RoomList[x]) + " nicht gelüftet " + VentMsg[x]);
CreateOverviewTable();
};
if (logging) log("Init Vent Timeout exceeded now calling regular Interval for x=" + x);
VentCheck(x);
}, CalcTimeDiff(VentWarnTime[x] * 24 * 60 * 60 * 1000, RoomStateTimeCount[x]));
};
} else { //Normalbetrieb, kein Init
VentMsgHandler[x] = setInterval(function () { // Neuen Timeout setzen, volle Warnzeit
RoomStateTimeCount[x] = CalcTimeDiff("now", RoomStateTimeStamp[x]); //RoomstateTimeCount aktualisieren um exakten Wert bei Ausgabe zu haben und 23 Stunden 59 Minuten Meldungen zu vermeiden
VentMsg[x] = CreateTimeString(RoomStateTimeCount[x]); //Watch!!
CreateRoomsWithVentWarnings(x, VentMsg[x])
if (SendVentMsg[x]) {
Meldung(ReplaceChars(RoomList[x]) + " nicht gelüftet " + VentMsg[x]);
CreateOverviewTable();
};
}, VentWarnTime[x] * 24 * 60 * 60 * 1000);
};
if (logging) log("VentMsg=" + VentMsg[x]);
}
else if (RoomOpenWindowCount[x] != 0 || VentWarnTime[x] == 0) {
if (logging) log("Room " + x + " = " + RoomList[x] + " is open or disabled, no vent warning set");
CreateRoomsWithVentWarnings(x, "");
ClearVentTime(x);
VentMsg[x] = "";
};
}
function GetRoom(x) { // Liefert den Raum von Sensor x
if (logging) log("Reaching GetRoom x=" + x)
let room = getObject(Sensor[x], 'rooms').enumNames[0];
if (typeof room == "undefined") {
log("Kein Raum definiert bei Sensor " + Sensor[x], 'error');
return "Kein Raum definiert";
};
if (typeof room == 'object') room = room.de;
return room;
}
function CheckWindow(x) { //Für einzelnes Fenster/Tür. Via Trigger angesteuert. Eigentliche Primärauswertefunktion des Skriptes
let TempRoom = GetRoom(x); //Raum des aktuellen Sensors bestimmen
let TempRoomIndex = RoomList.indexOf(TempRoom); // Raumlistenindex für aktuellen Raum bestimmen
if (logging) log("reaching CheckWindow, SensorVal[" + x + "]=" + SensorVal[x] + " SensorOldVal=" + SensorOldVal[x] + " TempRoom=" + TempRoom + " SensorType[x]=" + SensorType[x] + " TempRoomIndex=" + TempRoomIndex)
if (((SensorVal[x] == "open") && (SensorOldVal[x] == "closed" || SensorOldVal[x] == "" || SensorOldVal[x] != "tilted")) || ((SensorVal[x] == "tilted") && (SensorOldVal[x] == "closed" || SensorOldVal[x] == "" || SensorOldVal[x] != "open"))) { //Fenster war geschlossen und wurde geöffnet oder gekippt - Wechsel von open auf tilted nicht berücksichtigt!!!
if (SensorType[x] == "Window") {
if (RoomOpenWindowCount[TempRoomIndex] == 0) setState(praefix + TempRoom + ".WindowIsOpen", true, true);
if (RoomOpenWindowCount[TempRoomIndex] == 0) setState(praefix + TempRoom + ".RoomIsOpen", true, true);