iobroker.luxtronik2-controller 1.2.1 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,448 @@
1
+ /**
2
+ * <luxtronik-schedule-radar>
3
+ * 24-Stunden-Zeitbalken für Heizung (Absenkung), Warmwasser (Sperrzeit) und Zirkulation (Freigabe)
4
+ * mit wanderndem Jetzt-Marker für `@iobroker/web-components`.
5
+ */
6
+ import { LuxtronikBaseCard } from './luxtronik-base.js';
7
+
8
+ const DAYS_EN = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
9
+ const DAYS_DE = ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'];
10
+ const TABLE_MODE_LABELS = { 0: 'Woche', 1: '5+2', 2: 'Tage' };
11
+
12
+ const TRACKS = [
13
+ {
14
+ id: 'hz',
15
+ label: 'Heizung',
16
+ kindLabel: 'Absenkung',
17
+ inBlockText: 'Abgesenkt',
18
+ outBlockText: 'Normal',
19
+ color: '#f59e0b',
20
+ inBlockCls: 'warn',
21
+ outBlockCls: 'ok',
22
+ },
23
+ {
24
+ id: 'ww',
25
+ label: 'Warmwasser',
26
+ kindLabel: 'Sperrzeit',
27
+ inBlockText: 'Gesperrt',
28
+ outBlockText: 'Freigegeben',
29
+ color: '#ef4444',
30
+ inBlockCls: 'bad',
31
+ outBlockCls: 'ok',
32
+ },
33
+ {
34
+ id: 'zip',
35
+ label: 'Zirkulation',
36
+ kindLabel: 'Freigabe',
37
+ inBlockText: 'Freigegeben',
38
+ outBlockText: 'Pausiert',
39
+ color: '#3b82f6',
40
+ inBlockCls: 'info',
41
+ outBlockCls: 'muted',
42
+ },
43
+ ];
44
+
45
+ class LuxtronikScheduleRadar extends LuxtronikBaseCard {
46
+ static get stateMap() {
47
+ const map = {
48
+ hz_sel: 'Settings.07_Tables.heatingOperationTimerTableSelected',
49
+ ww_sel: 'Settings.07_Tables.hotWaterOperationTimerTableSelected',
50
+ zip_sel: 'Settings.07_Tables.hotWaterCircPumpTimerTableSelected',
51
+ hz_week: 'Information.11_Tables.Heating.heatingOperationTimerTableWeek',
52
+ hz_monfri: 'Information.11_Tables.Heating.heatingOperationTimerTable52MonFri',
53
+ hz_satsun: 'Information.11_Tables.Heating.heatingOperationTimerTable52SatSun',
54
+ ww_week: 'Information.11_Tables.HotWater.hotWaterTableWeek',
55
+ ww_monfri: 'Information.11_Tables.HotWater.hotWaterTable52MonFri',
56
+ ww_satsun: 'Information.11_Tables.HotWater.hotWaterTable52SatSun',
57
+ zip_week: 'Information.11_Tables.Circulation.hotWaterCircPumpTimerTableWeek',
58
+ zip_monfri: 'Information.11_Tables.Circulation.hotWaterCircPumpTimerTable52MonFri',
59
+ zip_satsun: 'Information.11_Tables.Circulation.hotWaterCircPumpTimerTable52SatSun',
60
+ };
61
+ for (const day of DAYS_EN) {
62
+ map[`hz_${day}`] = `Information.11_Tables.Heating.heatingOperationTimerTableDay${day}`;
63
+ map[`ww_${day}`] = `Information.11_Tables.HotWater.hotWaterTableDay${day}`;
64
+ map[`zip_${day}`] = `Information.11_Tables.Circulation.hotWaterCircPumpTimerTableDay${day}`;
65
+ }
66
+ return map;
67
+ }
68
+
69
+ constructor() {
70
+ super();
71
+ this._clockTimer = null;
72
+ }
73
+
74
+ connectedCallback() {
75
+ super.connectedCallback();
76
+ if (!this._clockTimer) {
77
+ this._clockTimer = window.setInterval(() => {
78
+ if (this._rendered) {
79
+ this._updateView();
80
+ }
81
+ }, 60000);
82
+ }
83
+ }
84
+
85
+ disconnectedCallback() {
86
+ super.disconnectedCallback();
87
+ if (this._clockTimer) {
88
+ window.clearInterval(this._clockTimer);
89
+ this._clockTimer = null;
90
+ }
91
+ }
92
+
93
+ _toMinutes(val) {
94
+ if (val === null || val === undefined || val === '') {
95
+ return null;
96
+ }
97
+ if (typeof val === 'number' && !isNaN(val)) {
98
+ // Sekunde (0..86400) oder Minute (0..1440) erkennen
99
+ if (val > 1440) {
100
+ return Math.round(val / 60);
101
+ }
102
+ return Math.round(val);
103
+ }
104
+ const s = String(val).trim();
105
+ const m = s.match(/^(\d{1,2}):(\d{2})/);
106
+ if (m) {
107
+ return parseInt(m[1], 10) * 60 + parseInt(m[2], 10);
108
+ }
109
+ const n = parseFloat(s);
110
+ if (!isNaN(n)) {
111
+ return n > 1440 ? Math.round(n / 60) : Math.round(n);
112
+ }
113
+ return null;
114
+ }
115
+
116
+ _fmtMin(min) {
117
+ const m = Math.max(0, Math.min(1440, Math.round(min)));
118
+ const h = Math.floor(m / 60);
119
+ const mm = m % 60;
120
+ return `${String(h).padStart(2, '0')}:${String(mm).padStart(2, '0')}`;
121
+ }
122
+
123
+ _parseIntervals(raw) {
124
+ if (!raw) {
125
+ return [];
126
+ }
127
+ let data = raw;
128
+ if (typeof raw === 'string') {
129
+ const trimmed = raw.trim();
130
+ if (!trimmed) {
131
+ return [];
132
+ }
133
+ try {
134
+ data = JSON.parse(trimmed);
135
+ } catch {
136
+ // Fallback für reine Textlisten wie "06:00-22:00, 23:00-05:00"
137
+ const pairs = [];
138
+ const re = /(\d{1,2}:\d{2})\s*[-–]\s*(\d{1,2}:\d{2})/g;
139
+ let match;
140
+ while ((match = re.exec(trimmed)) !== null) {
141
+ const s = this._toMinutes(match[1]);
142
+ const e = this._toMinutes(match[2]);
143
+ if (s !== null && e !== null && s !== e) {
144
+ pairs.push([s, e]);
145
+ }
146
+ }
147
+ return pairs;
148
+ }
149
+ }
150
+
151
+ const rawPairs = [];
152
+ const addPair = (a, b) => {
153
+ const s = this._toMinutes(a);
154
+ const e = this._toMinutes(b);
155
+ if (s !== null && e !== null && s !== e) {
156
+ rawPairs.push([s, e]);
157
+ }
158
+ };
159
+
160
+ if (Array.isArray(data)) {
161
+ if (data.length > 0 && data.every(x => typeof x === 'number')) {
162
+ for (let i = 0; i + 1 < data.length; i += 2) {
163
+ addPair(data[i], data[i + 1]);
164
+ }
165
+ } else {
166
+ for (const entry of data) {
167
+ if (Array.isArray(entry) && entry.length >= 2) {
168
+ addPair(entry[0], entry[1]);
169
+ } else if (typeof entry === 'string') {
170
+ const m = entry.match(/(\d{1,2}:\d{2})\s*[-–]\s*(\d{1,2}:\d{2})/);
171
+ if (m) {
172
+ addPair(m[1], m[2]);
173
+ }
174
+ } else if (entry && typeof entry === 'object') {
175
+ const s = entry.on ?? entry.start ?? entry.from ?? entry.von ?? entry.Start;
176
+ const e = entry.off ?? entry.end ?? entry.to ?? entry.bis ?? entry.End ?? entry.Ende;
177
+ addPair(s, e);
178
+ }
179
+ }
180
+ }
181
+ } else if (data && typeof data === 'object') {
182
+ // z.B. { start1: ..., end1: ... }
183
+ const keys = Object.keys(data);
184
+ for (let i = 1; i <= 5; i++) {
185
+ const sKey = keys.find(k => new RegExp(`(start|on|von).*${i}$`, 'i').test(k));
186
+ const eKey = keys.find(k => new RegExp(`(end|ende|off|bis).*${i}$`, 'i').test(k));
187
+ if (sKey && eKey) {
188
+ addPair(data[sKey], data[eKey]);
189
+ }
190
+ }
191
+ }
192
+
193
+ return rawPairs;
194
+ }
195
+
196
+ _splitWrapped(pairs) {
197
+ const segments = [];
198
+ for (const [s, e] of pairs) {
199
+ if (s < e) {
200
+ segments.push([s, e]);
201
+ } else if (s > e) {
202
+ // Mitternachts-Überlauf (z.B. 22:00 - 05:30)
203
+ segments.push([s, 1440]);
204
+ if (e > 0) {
205
+ segments.push([0, e]);
206
+ }
207
+ }
208
+ }
209
+ return segments;
210
+ }
211
+
212
+ _selectTableValue(prefix, now) {
213
+ const mode = this._toNum(this._values[`${prefix}_sel`]) ?? 0;
214
+ const dayIdx = now.getDay();
215
+ const isWeekend = dayIdx === 0 || dayIdx === 6;
216
+
217
+ let raw = null;
218
+ if (mode === 1) {
219
+ raw = this._values[isWeekend ? `${prefix}_satsun` : `${prefix}_monfri`];
220
+ } else if (mode === 2) {
221
+ raw = this._values[`${prefix}_${DAYS_EN[dayIdx]}`];
222
+ } else {
223
+ raw = this._values[`${prefix}_week`];
224
+ }
225
+ return { mode, raw };
226
+ }
227
+
228
+ _renderBase() {
229
+ const tracksHtml = TRACKS.map(
230
+ t => `
231
+ <div class="track-card">
232
+ <div class="track-head">
233
+ <div class="track-left">
234
+ <span class="dot" style="background:${t.color}"></span>
235
+ <span class="track-name">${t.label}</span>
236
+ <span class="track-meta" data-ref="meta_${t.id}">–</span>
237
+ </div>
238
+ <span class="pill" data-ref="state_${t.id}">–</span>
239
+ </div>
240
+ <div class="bar-wrap">
241
+ <div class="bar-blocks" data-ref="blocks_${t.id}"></div>
242
+ <div class="now-line" data-ref="now_${t.id}"></div>
243
+ </div>
244
+ <div class="slots-text" data-ref="slots_${t.id}">Keine Zeitfenster hinterlegt</div>
245
+ </div>
246
+ `,
247
+ ).join('');
248
+
249
+ const tpl = document.createElement('template');
250
+ tpl.innerHTML = `
251
+ <style>
252
+ :host {
253
+ --lux-surface: rgba(127, 127, 127, 0.11);
254
+ --lux-border: rgba(127, 127, 127, 0.24);
255
+ --lux-ok: #22c55e;
256
+ --lux-warn: #f59e0b;
257
+ --lux-bad: #ef4444;
258
+ --lux-info: #3b82f6;
259
+ display: block;
260
+ width: 100%;
261
+ height: 100%;
262
+ box-sizing: border-box;
263
+ font-family: inherit;
264
+ color: inherit;
265
+ }
266
+
267
+ .card {
268
+ width: 100%;
269
+ height: 100%;
270
+ box-sizing: border-box;
271
+ display: flex;
272
+ flex-direction: column;
273
+ gap: 8px;
274
+ padding: 12px;
275
+ overflow: auto;
276
+ }
277
+
278
+ .header {
279
+ display: flex;
280
+ justify-content: space-between;
281
+ align-items: center;
282
+ gap: 8px;
283
+ }
284
+
285
+ .title { font-size: 0.98rem; font-weight: 600; }
286
+ .clock { font-size: 0.78rem; font-weight: 600; opacity: 0.78; font-variant-numeric: tabular-nums; }
287
+
288
+ .tracks {
289
+ display: flex;
290
+ flex-direction: column;
291
+ gap: 8px;
292
+ flex: 1;
293
+ }
294
+
295
+ .track-card {
296
+ background: var(--lux-surface);
297
+ border: 1px solid var(--lux-border);
298
+ border-radius: 10px;
299
+ padding: 8px 10px;
300
+ display: flex;
301
+ flex-direction: column;
302
+ gap: 6px;
303
+ }
304
+
305
+ .track-head {
306
+ display: flex;
307
+ justify-content: space-between;
308
+ align-items: center;
309
+ gap: 8px;
310
+ }
311
+
312
+ .track-left { display: flex; align-items: center; gap: 6px; }
313
+ .dot { width: 8px; height: 8px; border-radius: 50%; }
314
+ .track-name { font-size: 0.82rem; font-weight: 600; }
315
+ .track-meta { font-size: 0.72rem; opacity: 0.65; }
316
+
317
+ .pill {
318
+ padding: 1px 7px;
319
+ border-radius: 999px;
320
+ font-size: 0.7rem;
321
+ font-weight: 600;
322
+ background: var(--lux-surface);
323
+ border: 1px solid var(--lux-border);
324
+ }
325
+
326
+ .pill.ok { color: var(--lux-ok); border-color: rgba(34, 197, 94, 0.4); background: rgba(34, 197, 94, 0.14); }
327
+ .pill.warn { color: var(--lux-warn); border-color: rgba(245, 158, 11, 0.45); background: rgba(245, 158, 11, 0.14); }
328
+ .pill.bad { color: var(--lux-bad); border-color: rgba(239, 68, 68, 0.45); background: rgba(239, 68, 68, 0.14); }
329
+ .pill.info { color: var(--lux-info); border-color: rgba(59, 130, 246, 0.45); background: rgba(59, 130, 246, 0.14); }
330
+ .pill.muted { opacity: 0.72; }
331
+
332
+ .bar-wrap {
333
+ position: relative;
334
+ height: 14px;
335
+ border-radius: 6px;
336
+ background: rgba(127, 127, 127, 0.2);
337
+ overflow: hidden;
338
+ }
339
+
340
+ .bar-blocks {
341
+ position: absolute;
342
+ inset: 0;
343
+ }
344
+
345
+ .block {
346
+ position: absolute;
347
+ top: 0;
348
+ bottom: 0;
349
+ border-radius: 3px;
350
+ opacity: 0.82;
351
+ }
352
+
353
+ .now-line {
354
+ position: absolute;
355
+ top: -2px;
356
+ bottom: -2px;
357
+ width: 2px;
358
+ background: #ffffff;
359
+ box-shadow: 0 0 6px rgba(255, 255, 255, 0.9);
360
+ z-index: 2;
361
+ }
362
+
363
+ .slots-text {
364
+ font-size: 0.71rem;
365
+ opacity: 0.72;
366
+ font-variant-numeric: tabular-nums;
367
+ }
368
+
369
+ .axis {
370
+ display: flex;
371
+ justify-content: space-between;
372
+ padding: 0 10px;
373
+ font-size: 0.68rem;
374
+ opacity: 0.6;
375
+ font-variant-numeric: tabular-nums;
376
+ }
377
+ </style>
378
+
379
+ <div class="card">
380
+ <div class="header">
381
+ <div class="title" data-ref="title">Zeitschaltprogramme (Heute)</div>
382
+ <div class="clock" data-ref="clock">–</div>
383
+ </div>
384
+
385
+ <div class="tracks">${tracksHtml}</div>
386
+
387
+ <div class="axis">
388
+ <span>00:00</span><span>04:00</span><span>08:00</span><span>12:00</span><span>16:00</span><span>20:00</span><span>24:00</span>
389
+ </div>
390
+ </div>
391
+ `;
392
+ this.shadowRoot.appendChild(tpl.content.cloneNode(true));
393
+ }
394
+
395
+ _updateView() {
396
+ const r = this._refs;
397
+ if (!r.title) {
398
+ return;
399
+ }
400
+
401
+ const now = new Date();
402
+ const nowMin = now.getHours() * 60 + now.getMinutes();
403
+ const nowPct = (nowMin / 1440) * 100;
404
+
405
+ r.title.textContent = this._settings?.title || 'Zeitschaltprogramme (Heute)';
406
+ r.clock.textContent = `${DAYS_DE[now.getDay()]} · ${this._fmtMin(nowMin)}`;
407
+
408
+ for (const t of TRACKS) {
409
+ const { mode, raw } = this._selectTableValue(t.id, now);
410
+ const modeName = TABLE_MODE_LABELS[mode] || 'Woche';
411
+ r[`meta_${t.id}`].textContent = `(${t.kindLabel} · ${modeName})`;
412
+
413
+ const pairs = this._parseIntervals(raw);
414
+ const segments = this._splitWrapped(pairs);
415
+ const isInBlock = segments.some(([s, e]) => nowMin >= s && nowMin < e);
416
+
417
+ const badge = r[`state_${t.id}`];
418
+ badge.textContent = isInBlock ? t.inBlockText : t.outBlockText;
419
+ badge.className = `pill ${isInBlock ? t.inBlockCls : t.outBlockCls}`;
420
+
421
+ r[`now_${t.id}`].style.left = `${nowPct.toFixed(2)}%`;
422
+
423
+ const container = r[`blocks_${t.id}`];
424
+ while (container.firstChild) {
425
+ container.removeChild(container.firstChild);
426
+ }
427
+
428
+ for (const [s, e] of segments) {
429
+ const el = document.createElement('div');
430
+ el.className = 'block';
431
+ el.style.left = `${((s / 1440) * 100).toFixed(2)}%`;
432
+ el.style.width = `${(((e - s) / 1440) * 100).toFixed(2)}%`;
433
+ el.style.backgroundColor = t.color;
434
+ el.title = `${t.kindLabel}: ${this._fmtMin(s)} – ${this._fmtMin(e)}`;
435
+ container.appendChild(el);
436
+ }
437
+
438
+ r[`slots_${t.id}`].textContent =
439
+ pairs.length > 0
440
+ ? `${t.kindLabel}: ${pairs.map(([s, e]) => `${this._fmtMin(s)}–${this._fmtMin(e)}`).join(' · ')}`
441
+ : `Keine ${t.kindLabel} aktiv`;
442
+ }
443
+ }
444
+ }
445
+
446
+ if (!customElements.get('luxtronik-schedule-radar')) {
447
+ customElements.define('luxtronik-schedule-radar', LuxtronikScheduleRadar);
448
+ }
@@ -0,0 +1,34 @@
1
+ {
2
+ "manifestVersion": 1,
3
+ "tag": "luxtronik-schedule-radar",
4
+ "module": "./luxtronik-schedule-radar.js",
5
+ "name": {
6
+ "en": "Luxtronik 24h Schedule Radar",
7
+ "de": "Luxtronik 24h-Zeitschaltuhr-Radar"
8
+ },
9
+ "size": {
10
+ "width": 500,
11
+ "height": 265
12
+ },
13
+ "settings": {
14
+ "type": "panel",
15
+ "items": {
16
+ "instance": {
17
+ "type": "instance",
18
+ "adapter": "luxtronik2-controller",
19
+ "label": {
20
+ "en": "Adapter instance",
21
+ "de": "Adapter-Instanz"
22
+ }
23
+ },
24
+ "title": {
25
+ "type": "text",
26
+ "default": "Zeitschaltprogramme (Heute)",
27
+ "label": {
28
+ "en": "Title",
29
+ "de": "Titel"
30
+ }
31
+ }
32
+ }
33
+ }
34
+ }
@@ -17,8 +17,8 @@ const STATE_MAP = {
17
17
  compressor: 'Information.03_Outputs.VD1out',
18
18
  zipActive: 'Information.03_Outputs.Virtual_ZIP_Status',
19
19
  hupVoltage: 'Settings.04_HUP.heating_system_circ_pump_voltage_nominal',
20
- copToday: 'Information.16_Efficiency.cop_total_today',
21
- jazYear: 'Information.16_Efficiency.cop_total_year',
20
+ copToday: 'Information.16_Efficiency.Total.cop_total_today',
21
+ jazYear: 'Information.16_Efficiency.Total.cop_total_year',
22
22
  pvBoost: 'Information.17_PV_Surplus.pv_boost_active',
23
23
  };
24
24
 
@@ -847,6 +847,7 @@ const INFO_MAPPING = {
847
847
  luxWriteId: "56",
848
848
  factor: 3600,
849
849
  dataSource: "raw_value",
850
+ required: true,
850
851
  visiIndex: 80
851
852
  },
852
853
  starts_compressor1: {
@@ -856,6 +857,7 @@ const INFO_MAPPING = {
856
857
  type: "number",
857
858
  luxWriteId: "57",
858
859
  dataSource: "raw_value",
860
+ required: true,
859
861
  visiIndex: 81
860
862
  },
861
863
  hours_compressor2: {