iobroker.luxtronik2-controller 1.0.4 → 1.1.0

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.
package/build/main.js CHANGED
@@ -62,8 +62,8 @@ class Luxtronik2Controller extends utils.Adapter {
62
62
  updateRunning = false;
63
63
  /** Timestamp tracking the last dynamic pump voltage optimization execution */
64
64
  lastPumpOptimization = 0;
65
- /** Merkt sich, ob Takt-Optimierung oder Zwangsheizen aktuell über den flüchtigen SHI-Modbus-Offset (+10 K) aktiv ist */
66
- forcedHeatingShiActive = false;
65
+ /** Merkt sich, ob Takt-Optimierung oder Zwangsheizen aktuell einen temporären Heiz-Offset hält */
66
+ forcedHeatingBoostActive = false;
67
67
  /** Internal array storing pending serial hardware write tasks */
68
68
  writeQueue = [];
69
69
  /** Lock flag indicating that the write queue is currently being processed */
@@ -83,6 +83,10 @@ class Luxtronik2Controller extends utils.Adapter {
83
83
  zipEndTime;
84
84
  /** Cron-Job Handle für die Firmware-Update-Prüfung */
85
85
  updateCronJob;
86
+ /** Merker für Heizgrund */
87
+ forcedHeatingReason = "";
88
+ /** Merkt sich den ursprünglichen WW-Sollwert, falls forceSoll temporär erhöht hat */
89
+ forcedWwOriginalTarget = null;
86
90
  /**
87
91
  * Initializes a new instance of the Luxtronik2Controller class.
88
92
  *
@@ -417,73 +421,6 @@ class Luxtronik2Controller extends utils.Adapter {
417
421
  config.operation_mode !== "readonly" && config.modbus_active && this.modbusManager && this.modbusManager.isAvailable && this.modbusManager.protocolVersion === "shi" && config.sync_modbus_holding_23 === true
418
422
  );
419
423
  }
420
- /**
421
- * Aktiviert eine temporäre Heizungsanhebung (Takt-Optimierung, Vorheizen oder Zwangsheizen).
422
- * Nutzt im V3.9x-SHI-Modus flüchtiges Modbus-RAM (+10.0 K über Holding 23 -> SHI 10002),
423
- * sonst wie bisher den Heizkurven-Fußpunkt (35 °C).
424
- *
425
- * @param reason - Optionaler Kontext für das Debug-Log.
426
- */
427
- async activateForcedHeatingBoost(reason = "CycleOpt") {
428
- if (this.isShiModbusActive()) {
429
- if (!this.forcedHeatingShiActive) {
430
- await this.modbusManager.writeRegister(23, 100, false);
431
- this.forcedHeatingShiActive = true;
432
- const dpHeatingTemp = (0, import_stateMapping.getDpPath)("heating_temperature");
433
- if (dpHeatingTemp) {
434
- await this.setOwnStateIfDifferent(dpHeatingTemp, 10, true);
435
- }
436
- if (this.isDebugLogActive) {
437
- (0, import_logger.writeLog)(
438
- `[${reason}] SHI Modbus active: Setting volatile heating offset to +10.0 K (Holding 23 -> SHI 10002, 0 EEPROM writes).`,
439
- "info"
440
- );
441
- }
442
- }
443
- return;
444
- }
445
- await this.syncConfigValue("heating_curve_parallel_offset", 35);
446
- }
447
- /**
448
- * Setzt eine aktive temporäre Heizungsanhebung sauber zurück.
449
- * Im SHI-Modus wird der flüchtige Offset auf den Basiswert zurückgesetzt und ein aktiver PV-Boost optional wiederhergestellt.
450
- *
451
- * @param reapplyPv - Stellt bei aktivem PV-Boost dessen Sollwert im Anschluss sofort wieder her.
452
- */
453
- async resetForcedHeatingBoost(reapplyPv = true) {
454
- var _a, _b;
455
- const config = this.config;
456
- if (this.isShiModbusActive()) {
457
- const heatingTempState = await this.getStateAsync((0, import_stateMapping.getDpPath)("heating_temperature"));
458
- const isShiOffsetStuckHigh = typeof (heatingTempState == null ? void 0 : heatingTempState.val) === "number" && heatingTempState.val >= 10;
459
- if (!this.forcedHeatingShiActive && !isShiOffsetStuckHigh) {
460
- return;
461
- }
462
- this.forcedHeatingShiActive = false;
463
- const baseOffset = Number((_a = config.sync_heating_temperature) != null ? _a : 0);
464
- await this.modbusManager.writeRegister(23, Math.round(baseOffset * 10), false);
465
- const dpHeatingTemp = (0, import_stateMapping.getDpPath)("heating_temperature");
466
- if (dpHeatingTemp) {
467
- await this.setOwnStateIfDifferent(dpHeatingTemp, baseOffset, true);
468
- }
469
- if (this.isDebugLogActive) {
470
- (0, import_logger.writeLog)(
471
- `[CycleOpt] SHI Modbus active: Resetting volatile heating offset back to ${baseOffset} K (Holding 23 -> SHI 10002).`,
472
- "info"
473
- );
474
- }
475
- if (reapplyPv && import_pvManager.pvIsBoostActive) {
476
- await (0, import_pvManager.evaluatePvBoost)(this, true);
477
- }
478
- return;
479
- }
480
- const fusspunktState = await this.getStateAsync((0, import_stateMapping.getDpPath)("heating_curve_parallel_offset"));
481
- const currentFusspunkt = typeof (fusspunktState == null ? void 0 : fusspunktState.val) === "number" ? fusspunktState.val : this.currentRawParams[12] !== void 0 ? this.currentRawParams[12] / 10 : 0;
482
- if (currentFusspunkt === 35) {
483
- const fallbackFusspunkt = (_b = config.fusspunkt) != null ? _b : 21.7;
484
- await this.syncConfigValue("heating_curve_parallel_offset", fallbackFusspunkt);
485
- }
486
- }
487
424
  /**
488
425
  * Configures fallback factory parameter baselines for the heat pump when in an idle state.
489
426
  *
@@ -492,45 +429,230 @@ class Luxtronik2Controller extends utils.Adapter {
492
429
  async setIdleDefaults() {
493
430
  var _a, _b, _c, _d, _e, _f, _g, _h, _i;
494
431
  try {
432
+ this.forcedWwOriginalTarget = null;
495
433
  const config = this.config;
496
- await this.resetForcedHeatingBoost(false);
434
+ const isPvControlling = import_pvManager.pvIsBoostActive && !import_pvManager.pvWaitingForCycleEnd;
497
435
  if (!this.isShiModbusActive()) {
498
436
  await this.syncConfigValue("heating_curve_end_point", (_a = config.endpunkt) != null ? _a : 23);
499
437
  await this.syncConfigValue("heating_curve_parallel_offset", (_b = config.fusspunkt) != null ? _b : 21.7);
500
438
  }
501
- await this.syncConfigValue("heating_temperature", (_c = config.sync_heating_temperature) != null ? _c : 0);
502
439
  if (config.hup_optimierung_aktiv === true) {
503
440
  await this.syncConfigValue(
504
441
  "heating_system_circ_pump_voltage_minimal",
505
- (_d = config.sync_heating_system_circ_pump_voltage_minimal_heating) != null ? _d : 3
442
+ (_c = config.sync_heating_system_circ_pump_voltage_minimal_heating) != null ? _c : 3
506
443
  );
507
444
  await this.syncConfigValue(
508
445
  "heating_system_circ_pump_voltage_nominal",
509
- (_e = config.sync_heating_system_circ_pump_voltage_nominal_heating) != null ? _e : 7
446
+ (_d = config.sync_heating_system_circ_pump_voltage_nominal_heating) != null ? _d : 7
510
447
  );
511
448
  }
512
- await this.syncConfigValue("temperature_hot_water_target", (_f = config.sync_warmwater_target_temperature) != null ? _f : 54);
513
- await this.syncConfigValue("returnTemperatureHysteresis", (_g = config.sync_return_temperature_hysteresis) != null ? _g : 1.5);
514
- await this.syncConfigValue("zip_aktiv", (_h = config.zip_aktiv) != null ? _h : 0);
515
- await this.syncConfigValue("Heizen_nach_Wasser", (_i = config.Heating_after_warmwater) != null ? _i : false);
516
- if (import_pvManager.pvIsBoostActive) {
449
+ await this.syncConfigValue("returnTemperatureHysteresis", (_e = config.sync_return_temperature_hysteresis) != null ? _e : 1.5);
450
+ await this.syncConfigValue("zip_aktiv", (_f = config.zip_aktiv) != null ? _f : 0);
451
+ await this.syncConfigValue("Heizen_nach_Wasser", (_g = config.Heating_after_warmwater) != null ? _g : false);
452
+ if (isPvControlling) {
453
+ this.forcedHeatingBoostActive = false;
454
+ this.forcedHeatingReason = "";
517
455
  await (0, import_pvManager.evaluatePvBoost)(this, true);
456
+ } else {
457
+ const baseOffset = parseFloat(String((_h = config.sync_heating_temperature) != null ? _h : 0).replace(",", ".")) || 0;
458
+ const baseWw = parseFloat(String((_i = config.sync_warmwater_target_temperature) != null ? _i : 54).replace(",", ".")) || 54;
459
+ await this.resetForcedHeatingBoost(false);
460
+ await this.syncConfigValue("heating_temperature", baseOffset);
461
+ await this.syncConfigValue("temperature_hot_water_target", baseWw);
518
462
  }
519
463
  } catch (err) {
520
464
  (0, import_logger.writeLog)(`Failed to apply the baseline idle configuration defaults: ${err.message}`, "error");
521
465
  }
522
466
  }
523
467
  /**
524
- * Evaluates whether the current active operating state timestamp is older than ten minutes.
468
+ * Prüft, ob die Heizung aktuell generell heizen darf (nicht Aus/Urlaub, nicht Heizgrenze/Frostschutz).
469
+ *
470
+ * @param rawValues - Aktuelle Rohwerte (CMD 3004).
471
+ * @param rawParams - Aktuelle Rohparameter (CMD 3003).
472
+ * @param isHeatingAllowedByLimit - Ergebnis der konfigurierten Heizgrenzen-Prüfung.
473
+ * @returns true, wenn Heizen erlaubt ist.
474
+ */
475
+ isHeatingAllowed(rawValues, rawParams, isHeatingAllowedByLimit) {
476
+ if (!isHeatingAllowedByLimit) {
477
+ return false;
478
+ }
479
+ const heatingOpMode = rawParams[3];
480
+ if (heatingOpMode === 3 || heatingOpMode === 4) {
481
+ return false;
482
+ }
483
+ const opStateHeating = rawValues[125];
484
+ if (opStateHeating === 2 || opStateHeating === 3 || opStateHeating === 4) {
485
+ return false;
486
+ }
487
+ return true;
488
+ }
489
+ /**
490
+ * Prüft anhand der Luxtronik-WW-Zeitschaltuhr (P405..P505 = Sperrzeiten),
491
+ * ob Warmwasser zum angegebenen Zeitpunkt gesperrt ist (inkl. Mitternachts-Übergang).
525
492
  *
526
- * @returns A promise that resolves to true if the state has remained unaltered for at least 10 minutes.
493
+ * @param rawParams - Aktuelle Rohparameter (CMD 3003).
494
+ * @param targetDate - Zu prüfender Zeitpunkt.
495
+ * @returns true, wenn zu diesem Zeitpunkt eine WW-Sperrzeit aktiv ist.
527
496
  */
528
- async istBetriebszustandAelterAls10Min() {
497
+ isHotWaterLockedAt(rawParams, targetDate) {
498
+ var _a;
499
+ if (!rawParams || rawParams.length <= 505) {
500
+ return false;
501
+ }
502
+ const tableMode = (_a = rawParams[405]) != null ? _a : 0;
503
+ const dayOfWeek = targetDate.getDay();
504
+ const prevDayOfWeek = (dayOfWeek + 6) % 7;
505
+ const secOfDay = targetDate.getHours() * 3600 + targetDate.getMinutes() * 60 + targetDate.getSeconds();
506
+ const getBaseIndex = (day) => {
507
+ if (tableMode === 1) {
508
+ return day >= 1 && day <= 5 ? 416 : 426;
509
+ }
510
+ if (tableMode === 2) {
511
+ return 436 + day * 10;
512
+ }
513
+ return 406;
514
+ };
515
+ const todayBase = getBaseIndex(dayOfWeek);
516
+ for (let i = 0; i < 5; i++) {
517
+ const start = rawParams[todayBase + i * 2];
518
+ const end = rawParams[todayBase + i * 2 + 1];
519
+ if (start === void 0 || end === void 0 || start === end) {
520
+ continue;
521
+ }
522
+ if (start < end) {
523
+ if (secOfDay >= start && secOfDay < end) {
524
+ return true;
525
+ }
526
+ } else {
527
+ if (secOfDay >= start) {
528
+ return true;
529
+ }
530
+ }
531
+ }
532
+ const prevBase = getBaseIndex(prevDayOfWeek);
533
+ for (let i = 0; i < 5; i++) {
534
+ const start = rawParams[prevBase + i * 2];
535
+ const end = rawParams[prevBase + i * 2 + 1];
536
+ if (start === void 0 || end === void 0 || start <= end) {
537
+ continue;
538
+ }
539
+ if (secOfDay < end) {
540
+ return true;
541
+ }
542
+ }
543
+ return false;
544
+ }
545
+ /**
546
+ * Prüft, ob Warmwasser aktuell (leadMinutes = 0) oder in X Minuten freigegeben ist.
547
+ *
548
+ * @param rawValues - Aktuelle Rohwerte (CMD 3004).
549
+ * @param rawParams - Aktuelle Rohparameter (CMD 3003).
550
+ * @param leadMinutes - Vorschau in Minuten (0 = jetzt sofort, z.B. 25 = Vorheiz-Check).
551
+ * @returns true, wenn Warmwasser erlaubt ist.
552
+ */
553
+ isHotWaterAllowed(rawValues, rawParams, leadMinutes = 0) {
554
+ const wwOpMode = rawParams[4];
555
+ if (wwOpMode === 3 || wwOpMode === 4) {
556
+ return false;
557
+ }
558
+ if (wwOpMode === 2) {
559
+ return true;
560
+ }
561
+ if (leadMinutes <= 0) {
562
+ const opStateWw = rawValues[124];
563
+ if (opStateWw !== void 0) {
564
+ return opStateWw !== 0 && opStateWw !== 3;
565
+ }
566
+ }
567
+ const targetDate = new Date(Date.now() + leadMinutes * 6e4);
568
+ return !this.isHotWaterLockedAt(rawParams, targetDate);
569
+ }
570
+ /**
571
+ * Aktiviert eine temporäre Heizungsanhebung (Takt-Optimierung, Vorheizen oder Zwangsheizen)
572
+ * über die Parallelverschiebung (`heating_temperature`) mit automatischem, relativem Offset.
573
+ *
574
+ * @param reason - Optionaler Kontext für das Debug-Log.
575
+ * @param deltaK - Relative Anhebung in Kelvin über dem Basis-Offset (z.B. Hysterese + 0.5 K).
576
+ */
577
+ async activateForcedHeatingBoost(reason = "CycleOpt", deltaK = 2) {
578
+ var _a;
579
+ this.forcedHeatingReason = reason;
580
+ const config = this.config;
581
+ const baseOffset = parseFloat(String((_a = config.sync_heating_temperature) != null ? _a : 0).replace(",", ".")) || 0;
582
+ const maxAllowedOffset = this.isShiModbusActive() ? 10 : 5;
583
+ let targetOffset = Math.round((baseOffset + Math.max(0.5, deltaK)) * 10) / 10;
584
+ targetOffset = Math.min(targetOffset, maxAllowedOffset);
585
+ if (import_pvManager.pvIsBoostActive) {
586
+ const currentState = await this.getStateAsync((0, import_stateMapping.getDpPath)("heating_temperature"));
587
+ if (typeof (currentState == null ? void 0 : currentState.val) === "number" && currentState.val > targetOffset) {
588
+ targetOffset = currentState.val;
589
+ }
590
+ }
591
+ const currentHeatingState = await this.getStateAsync((0, import_stateMapping.getDpPath)("heating_temperature"));
592
+ if (this.forcedHeatingBoostActive && (currentHeatingState == null ? void 0 : currentHeatingState.val) === targetOffset) {
593
+ return;
594
+ }
595
+ this.forcedHeatingBoostActive = true;
596
+ await this.syncConfigValue("heating_temperature", targetOffset);
597
+ if (this.isDebugLogActive) {
598
+ (0, import_logger.writeLog)(
599
+ `[${reason}] Setting dynamic heating offset to +${targetOffset} K (base: ${baseOffset} K, delta: +${deltaK} K, SHI: ${this.isShiModbusActive()}).`,
600
+ "info"
601
+ );
602
+ }
603
+ }
604
+ /**
605
+ * Setzt eine aktive temporäre Heizungsanhebung sauber auf den Basis-Offset zurück
606
+ * und stellt einen eventuell aktiven PV-Boost wieder her.
607
+ *
608
+ * @param reapplyPv - Stellt bei aktivem PV-Boost dessen Sollwert im Anschluss sofort wieder her.
609
+ */
610
+ async resetForcedHeatingBoost(reapplyPv = true) {
611
+ var _a;
612
+ if (!this.forcedHeatingBoostActive) {
613
+ return;
614
+ }
615
+ this.forcedHeatingBoostActive = false;
616
+ this.forcedHeatingReason = "";
617
+ if (reapplyPv && import_pvManager.pvIsBoostActive && !import_pvManager.pvWaitingForCycleEnd) {
618
+ await (0, import_pvManager.evaluatePvBoost)(this, true);
619
+ return;
620
+ }
621
+ const config = this.config;
622
+ const baseOffset = parseFloat(String((_a = config.sync_heating_temperature) != null ? _a : 0).replace(",", ".")) || 0;
623
+ await this.syncConfigValue("heating_temperature", baseOffset);
624
+ if (this.isDebugLogActive) {
625
+ (0, import_logger.writeLog)(`[CycleOpt] Resetting temporary heating offset back to ${baseOffset} K.`, "info");
626
+ }
627
+ }
628
+ /**
629
+ * Setzt eine temporäre WW-Anhebung (z.B. durch forceSoll) nach dem WW-Takt zurück,
630
+ * ohne einen aktiven PV-Boost unnötig umzuschalten.
631
+ */
632
+ async restoreForcedWwTarget() {
633
+ var _a, _b;
634
+ const config = this.config;
635
+ const fallbackWw = parseFloat(String((_a = config.sync_warmwater_target_temperature) != null ? _a : 54).replace(",", ".")) || 54;
636
+ const targetWw = (_b = this.forcedWwOriginalTarget) != null ? _b : fallbackWw;
637
+ this.forcedWwOriginalTarget = null;
638
+ if (import_pvManager.pvIsBoostActive && !import_pvManager.pvWaitingForCycleEnd) {
639
+ await (0, import_pvManager.evaluatePvBoost)(this, true);
640
+ return;
641
+ }
642
+ await this.syncConfigValue("temperature_hot_water_target", targetWw);
643
+ }
644
+ /**
645
+ * Prüft, ob der aktuelle Betriebszustand (WP_BZ_akt) mindestens `minutes` Minuten anliegt.
646
+ *
647
+ * @param minutes - Mindestdauer in Minuten.
648
+ * @returns true, wenn die letzte Änderung mindestens `minutes` Minuten zurückliegt.
649
+ */
650
+ async istBetriebszustandAelterAls(minutes) {
529
651
  var _a;
530
652
  try {
531
653
  const state = await this.getStateAsync((0, import_stateMapping.getDpPath)("WP_BZ_akt"));
532
654
  const lastChange = (_a = state == null ? void 0 : state.lc) != null ? _a : 0;
533
- return (Date.now() - lastChange) / 6e4 >= 10;
655
+ return (Date.now() - lastChange) / 6e4 >= minutes;
534
656
  } catch {
535
657
  return false;
536
658
  }
@@ -544,12 +666,13 @@ class Luxtronik2Controller extends utils.Adapter {
544
666
  * @returns A promise that resolves when the execution cycle finishes.
545
667
  */
546
668
  async runOptimizationSchedule(rawValues = [], rawParams = []) {
547
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
669
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
548
670
  try {
549
671
  const config = this.config;
550
672
  if (config.operation_mode === "readonly") {
551
673
  return;
552
674
  }
675
+ const effectiveParams = rawParams.length > 0 ? rawParams : this.currentRawParams;
553
676
  const bzState = await this.getStateAsync((0, import_stateMapping.getDpPath)("WP_BZ_akt"));
554
677
  const bzVal = bzState && bzState.val !== null ? String(bzState.val).trim() : rawValues[80] !== void 0 ? String(rawValues[80]) : "";
555
678
  const regelungAktivState = await this.getStateAsync((0, import_stateMapping.getDpPath)("Regelung_Aktiv"));
@@ -565,61 +688,64 @@ class Luxtronik2Controller extends utils.Adapter {
565
688
  if (istLeerlauf) {
566
689
  if (config.idle_defaults_aktiv === true) {
567
690
  await this.setIdleDefaults();
568
- } else if (this.forcedHeatingShiActive) {
569
- await this.resetForcedHeatingBoost();
691
+ } else {
692
+ if (this.forcedHeatingBoostActive) {
693
+ await this.resetForcedHeatingBoost();
694
+ }
695
+ if (this.forcedWwOriginalTarget !== null) {
696
+ await this.restoreForcedWwTarget();
697
+ }
570
698
  }
571
699
  } else if (istHeizen) {
572
- if (this.lastBzVal === "1" && config.idle_defaults_aktiv === true) {
573
- await this.syncConfigValue(
574
- "temperature_hot_water_target",
575
- (_a = config.sync_warmwater_target_temperature) != null ? _a : 54
576
- );
577
- if (import_pvManager.pvIsBoostActive) {
578
- await (0, import_pvManager.evaluatePvBoost)(this, true);
579
- }
700
+ if (this.lastBzVal === "1" && (config.idle_defaults_aktiv === true || this.forcedWwOriginalTarget !== null)) {
701
+ await this.restoreForcedWwTarget();
580
702
  }
581
703
  if (config.zip_optimierung_aktiv === true) {
582
- await this.syncConfigValue("zip_aktiv", (_b = config.zip_aktiv) != null ? _b : 0);
704
+ await this.syncConfigValue("zip_aktiv", (_a = config.zip_aktiv) != null ? _a : 0);
583
705
  }
584
706
  if (config.hup_optimierung_aktiv === true) {
585
707
  await this.syncConfigValue(
586
708
  "heating_system_circ_pump_voltage_minimal",
587
- (_c = config.sync_heating_system_circ_pump_voltage_minimal_heating) != null ? _c : 3
709
+ (_b = config.sync_heating_system_circ_pump_voltage_minimal_heating) != null ? _b : 3
588
710
  );
589
711
  await this.syncConfigValue(
590
712
  "heating_system_circ_pump_voltage_nominal",
591
- (_d = config.sync_heating_system_circ_pump_voltage_nominal_heating) != null ? _d : 7
713
+ (_c = config.sync_heating_system_circ_pump_voltage_nominal_heating) != null ? _c : 7
592
714
  );
593
715
  }
594
716
  if (isRegelungAktiv) {
595
- await this.syncConfigValue("Heizen_nach_Wasser", (_e = config.Heating_after_warmwater) != null ? _e : false);
717
+ await this.syncConfigValue("Heizen_nach_Wasser", (_d = config.Heating_after_warmwater) != null ? _d : false);
596
718
  }
597
719
  } else if (istWarmwasser) {
720
+ const nachWasserTransition = await this.getStateAsync((0, import_stateMapping.getDpPath)("Heizen_nach_Wasser"));
721
+ if (!(nachWasserTransition == null ? void 0 : nachWasserTransition.val) && this.forcedHeatingBoostActive) {
722
+ await this.resetForcedHeatingBoost();
723
+ }
598
724
  if (config.zip_optimierung_aktiv === true) {
599
725
  const mode = config.zip_control_mode || "controller";
600
726
  const actors = config.actors || [];
601
727
  const validActors = actors.filter(
602
728
  (a) => a.zip_external_relay_id && a.zip_external_relay_id.trim() !== ""
603
729
  );
604
- const canRunWearFree = mode === "actor" && validActors.length > 0 || mode === "modbus" && ((_f = this.modbusManager) == null ? void 0 : _f.isAvailable);
730
+ const canRunWearFree = mode === "actor" && validActors.length > 0 || mode === "modbus" && ((_e = this.modbusManager) == null ? void 0 : _e.isAvailable);
605
731
  if (canRunWearFree) {
606
732
  if (this.isDebugLogActive) {
607
733
  this.log.debug(
608
734
  `[ZIP] Wear-free mode (${mode}) active. Starting circulation synchronous to hot water generation.`
609
735
  );
610
736
  }
611
- await this.syncConfigValue("zip_aktiv", (_g = config.zip_aktiv_ww) != null ? _g : 120);
737
+ await this.syncConfigValue("zip_aktiv", (_f = config.zip_aktiv_ww) != null ? _f : 120);
612
738
  await this.setOwnStateIfDifferent((0, import_stateMapping.getDpPath)("Activate_Zip"), true, false);
613
739
  }
614
740
  }
615
741
  if (config.hup_optimierung_aktiv === true) {
616
742
  await this.syncConfigValue(
617
743
  "heating_system_circ_pump_voltage_minimal",
618
- (_h = config.sync_heating_system_circ_pump_voltage_minimal_water) != null ? _h : 3
744
+ (_g = config.sync_heating_system_circ_pump_voltage_minimal_water) != null ? _g : 3
619
745
  );
620
746
  await this.syncConfigValue(
621
747
  "heating_system_circ_pump_voltage_nominal",
622
- (_i = config.sync_heating_system_circ_pump_voltage_nominal_water) != null ? _i : 10
748
+ (_h = config.sync_heating_system_circ_pump_voltage_nominal_water) != null ? _h : 10
623
749
  );
624
750
  }
625
751
  }
@@ -640,7 +766,8 @@ class Luxtronik2Controller extends utils.Adapter {
640
766
  mitteltempState,
641
767
  thresholdHeatingLimitState,
642
768
  heatingLimitState,
643
- aelterAls10
769
+ aelterAls10,
770
+ aelterAls3
644
771
  ] = await Promise.all([
645
772
  this.getStateAsync((0, import_stateMapping.getDpPath)("Wamwassertemperatur_Soll")),
646
773
  this.getStateAsync((0, import_stateMapping.getDpPath)("temperature_hot_water_target")),
@@ -656,26 +783,30 @@ class Luxtronik2Controller extends utils.Adapter {
656
783
  this.getStateAsync((0, import_stateMapping.getDpPath)("Mitteltemperatur")),
657
784
  this.getStateAsync((0, import_stateMapping.getDpPath)("thresholdHeatingLimit")),
658
785
  this.getStateAsync((0, import_stateMapping.getDpPath)("heatingLimit")),
659
- this.istBetriebszustandAelterAls10Min()
786
+ this.istBetriebszustandAelterAls(10),
787
+ this.istBetriebszustandAelterAls(3)
660
788
  ]);
661
- const wwSoll = typeof (wwSollState == null ? void 0 : wwSollState.val) === "number" ? wwSollState.val : typeof (wwTargetParamState == null ? void 0 : wwTargetParamState.val) === "number" ? wwTargetParamState.val : rawValues[18] !== void 0 ? rawValues[18] / 10 : rawParams[105] !== void 0 ? rawParams[105] / 10 : 54;
789
+ const wwSoll = typeof (wwSollState == null ? void 0 : wwSollState.val) === "number" ? wwSollState.val : typeof (wwTargetParamState == null ? void 0 : wwTargetParamState.val) === "number" ? wwTargetParamState.val : rawValues[18] !== void 0 ? rawValues[18] / 10 : effectiveParams[105] !== void 0 ? effectiveParams[105] / 10 : 54;
662
790
  const wwIst = typeof (wwIstState == null ? void 0 : wwIstState.val) === "number" ? wwIstState.val : rawValues[17] !== void 0 ? rawValues[17] / 10 : 0;
663
791
  const ruecklauf = typeof (ruecklaufState == null ? void 0 : ruecklaufState.val) === "number" ? ruecklaufState.val : rawValues[11] !== void 0 ? rawValues[11] / 10 : 0;
664
792
  const ruecklaufSoll = typeof (ruecklaufSollState == null ? void 0 : ruecklaufSollState.val) === "number" ? ruecklaufSollState.val : rawValues[12] !== void 0 ? rawValues[12] / 10 : 0;
665
793
  const spreizung = typeof (spreizungState == null ? void 0 : spreizungState.val) === "number" ? spreizungState.val : rawValues[10] !== void 0 && rawValues[11] !== void 0 ? (rawValues[10] - rawValues[11]) / 10 : 0;
666
794
  const vd1 = (vd1State == null ? void 0 : vd1State.val) !== void 0 && (vd1State == null ? void 0 : vd1State.val) !== null ? vd1State.val === 1 || vd1State.val === true || String(vd1State.val).toLowerCase() === "true" : rawValues[44] === 1;
667
- const wwHysterese = typeof (wwHystereseState == null ? void 0 : wwHystereseState.val) === "number" ? wwHystereseState.val : rawParams[74] !== void 0 ? rawParams[74] / 10 : 2;
668
- const currentHupVolt = (_j = currentHupVoltState == null ? void 0 : currentHupVoltState.val) != null ? _j : 7;
669
- const heizenHysterese = typeof (heizenHystereseState == null ? void 0 : heizenHystereseState.val) === "number" ? heizenHystereseState.val : rawParams[88] !== void 0 ? rawParams[88] / 10 : 1.5;
795
+ const wwHysterese = typeof (wwHystereseState == null ? void 0 : wwHystereseState.val) === "number" ? wwHystereseState.val : effectiveParams[74] !== void 0 ? effectiveParams[74] / 10 : 2;
796
+ const currentHupVolt = (_i = currentHupVoltState == null ? void 0 : currentHupVoltState.val) != null ? _i : 7;
797
+ const heizenHysterese = typeof (heizenHystereseState == null ? void 0 : heizenHystereseState.val) === "number" ? heizenHystereseState.val : effectiveParams[88] !== void 0 ? effectiveParams[88] / 10 : 1.5;
670
798
  const mitteltemperatur = typeof (mitteltempState == null ? void 0 : mitteltempState.val) === "number" ? mitteltempState.val : rawValues[16] !== void 0 ? rawValues[16] / 10 : 0;
671
- const thresholdHeatingLimit = typeof (thresholdHeatingLimitState == null ? void 0 : thresholdHeatingLimitState.val) === "number" ? thresholdHeatingLimitState.val : rawParams[700] !== void 0 ? rawParams[700] / 10 : 15;
672
- const isHeatingLimitEnabled = (heatingLimitState == null ? void 0 : heatingLimitState.val) !== void 0 && (heatingLimitState == null ? void 0 : heatingLimitState.val) !== null ? heatingLimitState.val === 1 || heatingLimitState.val === true || String(heatingLimitState.val) === "1" || String(heatingLimitState.val).toLowerCase() === "true" : rawParams[699] === 1;
799
+ const thresholdHeatingLimit = typeof (thresholdHeatingLimitState == null ? void 0 : thresholdHeatingLimitState.val) === "number" ? thresholdHeatingLimitState.val : effectiveParams[700] !== void 0 ? effectiveParams[700] / 10 : 15;
800
+ const isHeatingLimitEnabled = (heatingLimitState == null ? void 0 : heatingLimitState.val) !== void 0 && (heatingLimitState == null ? void 0 : heatingLimitState.val) !== null ? heatingLimitState.val === 1 || heatingLimitState.val === true || String(heatingLimitState.val) === "1" || String(heatingLimitState.val).toLowerCase() === "true" : effectiveParams[699] === 1;
673
801
  const nachWasser = Boolean(nachWasserState == null ? void 0 : nachWasserState.val);
802
+ const isHeatingAllowedByLimit = !isHeatingLimitEnabled || mitteltemperatur < thresholdHeatingLimit;
803
+ const heatingAllowed = this.isHeatingAllowed(rawValues, effectiveParams, isHeatingAllowedByLimit);
804
+ const wwAllowedNow = this.isHotWaterAllowed(rawValues, effectiveParams, 0);
805
+ const wwAllowedSoon = this.isHotWaterAllowed(rawValues, effectiveParams, 25);
806
+ const dynamicDeltaK = Math.round((heizenHysterese + 0.5) * 10) / 10;
674
807
  if (istHeizen) {
675
808
  if (aelterAls10 && vd1) {
676
809
  await this.resetForcedHeatingBoost();
677
- }
678
- if (aelterAls10 && vd1) {
679
810
  this.lastPumpOptimization = await (0, import_hupManager.handleHupOptimization)(
680
811
  this,
681
812
  istHeizen,
@@ -685,33 +816,41 @@ class Luxtronik2Controller extends utils.Adapter {
685
816
  );
686
817
  }
687
818
  if (isRegelungAktiv) {
688
- if (ruecklauf >= ruecklaufSoll + heizenHysterese - 0.1) {
689
- if (aelterAls10) {
819
+ const rlZielErreicht = ruecklauf >= ruecklaufSoll + heizenHysterese - 0.1;
820
+ if (rlZielErreicht) {
821
+ if (aelterAls3) {
690
822
  await this.syncConfigValue("Heizen_nach_Wasser", false);
691
823
  }
824
+ if (aelterAls3 && wwAllowedNow && wwSoll - wwIst > 2) {
825
+ if (this.forcedWwOriginalTarget === null) {
826
+ const fallbackWw = parseFloat(
827
+ String((_j = config.sync_warmwater_target_temperature) != null ? _j : 54).replace(",", ".")
828
+ ) || 54;
829
+ this.forcedWwOriginalTarget = config.idle_defaults_aktiv === true ? fallbackWw : wwSoll;
830
+ }
831
+ let forceSoll = wwIst + wwHysterese + 1.5;
832
+ if (import_pvManager.pvIsBoostActive) {
833
+ const baseWw = parseFloat(
834
+ String((_k = config.sync_warmwater_target_temperature) != null ? _k : 54).replace(",", ".")
835
+ ) || 54;
836
+ const boostWw = parseFloat(String((_l = config.pv_boost_ww) != null ? _l : 0).replace(",", ".")) || 0;
837
+ const pvTarget = baseWw + boostWw;
838
+ forceSoll = Math.max(forceSoll, pvTarget);
839
+ }
840
+ if (forceSoll > 70) {
841
+ forceSoll = 70;
842
+ }
843
+ forceSoll = Math.round(forceSoll * 10) / 10;
844
+ await this.syncConfigValue("temperature_hot_water_target", forceSoll);
845
+ }
692
846
  } else if (!nachWasser && config.Heating_after_warmwater === true) {
693
847
  await this.syncConfigValue("Heizen_nach_Wasser", true);
694
848
  }
695
- if (wwSoll - wwIst > 2 && ruecklauf >= ruecklaufSoll + heizenHysterese - 0.1) {
696
- let forceSoll = wwIst + wwHysterese + 1.5;
697
- if (import_pvManager.pvIsBoostActive) {
698
- const baseWw = parseFloat(String(config.sync_warmwater_target_temperature).replace(",", ".")) || 54;
699
- const boostWw = parseFloat(String(config.pv_boost_ww).replace(",", ".")) || 0;
700
- const pvTarget = baseWw + boostWw;
701
- forceSoll = Math.max(forceSoll, pvTarget);
702
- }
703
- if (forceSoll > 70) {
704
- forceSoll = 70;
705
- }
706
- forceSoll = Math.round(forceSoll * 10) / 10;
707
- await this.syncConfigValue("temperature_hot_water_target", forceSoll);
708
- }
709
849
  }
710
850
  }
711
- const isHeatingAllowedByLimit = !isHeatingLimitEnabled || mitteltemperatur < thresholdHeatingLimit;
712
851
  if (istWarmwasser && nachWasser) {
713
- if (isRegelungAktiv && isHeatingAllowedByLimit) {
714
- await this.activateForcedHeatingBoost("CycleOpt-AfterWW");
852
+ if (isRegelungAktiv && heatingAllowed) {
853
+ await this.activateForcedHeatingBoost("CycleOpt-AfterWW", dynamicDeltaK);
715
854
  }
716
855
  }
717
856
  if (istLeerlauf) {
@@ -721,14 +860,16 @@ class Luxtronik2Controller extends utils.Adapter {
721
860
  }
722
861
  }
723
862
  if (isRegelungAktiv) {
724
- if (wwSoll - wwIst >= wwHysterese - 1.5 && ruecklauf <= ruecklaufSoll && isHeatingAllowedByLimit) {
863
+ if (wwAllowedSoon && heatingAllowed && wwSoll - wwIst >= wwHysterese - 1.5 && ruecklauf <= ruecklaufSoll) {
725
864
  if (this.isDebugLogActive) {
726
865
  (0, import_logger.writeLog)(
727
- `[CycleOpt] Pre-starting heating before WW (WW: ${wwIst}/${wwSoll}\xB0C, Hyst: ${wwHysterese}K, RL: ${ruecklauf}/${ruecklaufSoll}\xB0C).`,
866
+ `[CycleOpt] Pre-starting heating before WW (WW: ${wwIst}/${wwSoll}\xB0C, Hyst: ${wwHysterese}K, RL: ${ruecklauf}/${ruecklaufSoll}\xB0C, Offset: +${dynamicDeltaK}K).`,
728
867
  "info"
729
868
  );
730
869
  }
731
- await this.activateForcedHeatingBoost("CycleOpt-PreHeat");
870
+ await this.activateForcedHeatingBoost("CycleOpt-PreHeat", dynamicDeltaK);
871
+ } else if (this.forcedHeatingBoostActive && this.forcedHeatingReason === "CycleOpt-PreHeat") {
872
+ await this.resetForcedHeatingBoost();
732
873
  }
733
874
  }
734
875
  }
@@ -913,7 +1054,7 @@ class Luxtronik2Controller extends utils.Adapter {
913
1054
  }
914
1055
  await Promise.all(statePromises);
915
1056
  await (0, import_virtualStates.calculateTotalThermalEnergy)(this, rawValues);
916
- await (0, import_virtualStates.calculateTotalEnergy)(this, rawValues);
1057
+ await (0, import_virtualStates.calculateTotalEnergy)(this, rawParams);
917
1058
  const fehlerDp = (0, import_stateMapping.getDpPath)("Fehlerspeicher");
918
1059
  const oldFehlerState = fehlerDp ? await this.getStateAsync(fehlerDp) : null;
919
1060
  const oldFehlerVal = oldFehlerState == null ? void 0 : oldFehlerState.val;