iobroker.nexowatt-ui 0.8.7 → 0.8.8

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.
@@ -2,7 +2,7 @@
2
2
  * AUTO-GENERATED RUNTIME FILE - NICHT MANUELL BEARBEITEN.
3
3
  *
4
4
  * Quelle: src-ts/runtime-executables/ems/modules/charging-management.ts
5
- * Quell-Hash: sha256:406d1b740d83369b217261963476dfed76788cc3e9278038ccd057f34617f9e2
5
+ * Quell-Hash: sha256:5b0aab67fe8fbba739701e9ebeec3482db17acb740fb6d494592d999dcf27f6b
6
6
  * Erzeugung: npm run sync:ts-runtime-executables
7
7
  *
8
8
  * Zweck:
@@ -99,6 +99,19 @@ function requireChargingAllocationTsMirror() {
99
99
  }
100
100
  }
101
101
 
102
+
103
+ /**
104
+ * Code-Teil: requireChargingPhaseSelectionTsMirror
105
+ * Zweck: Lädt die TS-Entscheidungsschicht für AC-1p/3p-Auto-Phasenwahl im PV-Überschussladen.
106
+ */
107
+ function requireChargingPhaseSelectionTsMirror() {
108
+ try {
109
+ return require('../../lib/ts-mirrors/ems/charging-management/charging-phase-selection');
110
+ } catch (_e) {
111
+ return null;
112
+ }
113
+ }
114
+
102
115
  /**
103
116
  * Code-Teil: requireChargingWritePlanTsMirror
104
117
  * Zweck: Lädt den TS-Shadow für den späteren Setpoint-Write-Plan. JavaScript bleibt
@@ -642,6 +655,13 @@ class ChargingManagementModule extends BaseModule {
642
655
  this._chargingLegacyDecisionTreeLast = null;
643
656
  this._chargingEvcsJsRemovalTsLast = null;
644
657
  this._adapterTsRuntimeHandoverLast = null;
658
+ // EVCS AC-Phasenautomatik (1p/3p PV-Überschuss): Zustandsmarker für Hysterese, Cooldown und Settle-Zeit.
659
+ this._chargingPhaseHighSinceMs = new Map();
660
+ this._chargingPhaseLowSinceMs = new Map();
661
+ this._chargingPhaseCooldownUntilMs = new Map();
662
+ this._chargingPhaseSettleUntilMs = new Map();
663
+ this._chargingPhaseAssumedBySafe = new Map();
664
+ this._chargingPhaseSelectionTsLast = null;
645
665
  }
646
666
 
647
667
 
@@ -840,6 +860,9 @@ class ChargingManagementModule extends BaseModule {
840
860
  async _publishChargingAllocationTsShadow(input) {
841
861
  const allocationMirror = requireChargingAllocationTsMirror();
842
862
  const writePlanMirror = requireChargingWritePlanTsMirror();
863
+ const phaseMirror = requireChargingPhaseSelectionTsMirror();
864
+ let phasePlan = null;
865
+ let allocationInput = input || {};
843
866
  let shadow = null;
844
867
  let productivePrep = null;
845
868
  let productiveDecision = null;
@@ -847,6 +870,39 @@ class ChargingManagementModule extends BaseModule {
847
870
  let writePlan = null;
848
871
  let writePlanProductivePrep = null;
849
872
  let writePlanProductive = null;
873
+ try {
874
+ if (phaseMirror && typeof phaseMirror.buildChargingPhaseSelectionPlan === 'function') {
875
+ phasePlan = phaseMirror.buildChargingPhaseSelectionPlan((input && input.phaseSelection) ? input.phaseSelection : (input || {}));
876
+ } else {
877
+ phasePlan = {
878
+ source: 'ts-charging-phase-selection-v1',
879
+ available: false,
880
+ ok: false,
881
+ productive: false,
882
+ fallback: true,
883
+ fallbackReason: 'missing-ts-phase-selection-mirror',
884
+ wallboxes: [],
885
+ blockers: ['missing-ts-phase-selection-mirror'],
886
+ warnings: [],
887
+ ts: Date.now(),
888
+ };
889
+ }
890
+ } catch (e) {
891
+ phasePlan = {
892
+ source: 'ts-charging-phase-selection-v1',
893
+ available: false,
894
+ ok: false,
895
+ productive: false,
896
+ fallback: true,
897
+ fallbackReason: 'ts-phase-selection-runtime-error',
898
+ error: e && e.message ? e.message : String(e),
899
+ wallboxes: [],
900
+ blockers: ['ts-phase-selection-runtime-error'],
901
+ warnings: [],
902
+ ts: Date.now(),
903
+ };
904
+ }
905
+ allocationInput = { ...(input || {}), phasePlan };
850
906
  try {
851
907
  if (!allocationMirror || typeof allocationMirror.buildChargingAllocationShadowPlan !== 'function') {
852
908
  shadow = {
@@ -893,12 +949,12 @@ class ChargingManagementModule extends BaseModule {
893
949
  ts: Date.now(),
894
950
  };
895
951
  } else {
896
- const plan = allocationMirror.buildChargingAllocationShadowPlan(input || {});
952
+ const plan = allocationMirror.buildChargingAllocationShadowPlan(allocationInput || {});
897
953
  const comparison = (typeof allocationMirror.compareChargingAllocationShadowPlan === 'function')
898
- ? allocationMirror.compareChargingAllocationShadowPlan(input || {}, plan)
954
+ ? allocationMirror.compareChargingAllocationShadowPlan(allocationInput || {}, plan)
899
955
  : { ok: true, mismatchCount: 0, mismatches: [] };
900
956
  productivePrep = (typeof allocationMirror.buildChargingAllocationProductivePrep === 'function')
901
- ? allocationMirror.buildChargingAllocationProductivePrep(input || {}, plan, comparison)
957
+ ? allocationMirror.buildChargingAllocationProductivePrep(allocationInput || {}, plan, comparison)
902
958
  : {
903
959
  source: 'ts-charging-allocation-productive-prep-v1',
904
960
  available: false,
@@ -912,7 +968,7 @@ class ChargingManagementModule extends BaseModule {
912
968
  apply: null,
913
969
  };
914
970
  productiveDecision = (typeof allocationMirror.buildChargingAllocationProductive === 'function')
915
- ? allocationMirror.buildChargingAllocationProductive(input || {}, plan, comparison)
971
+ ? allocationMirror.buildChargingAllocationProductive(allocationInput || {}, plan, comparison)
916
972
  : {
917
973
  source: 'ts-charging-allocation-productive-v1',
918
974
  available: false,
@@ -926,7 +982,7 @@ class ChargingManagementModule extends BaseModule {
926
982
  apply: null,
927
983
  };
928
984
  normalSourceDecision = (typeof allocationMirror.buildChargingAllocationNormalSource === 'function')
929
- ? allocationMirror.buildChargingAllocationNormalSource(input || {}, plan, comparison)
985
+ ? allocationMirror.buildChargingAllocationNormalSource(allocationInput || {}, plan, comparison)
930
986
  : {
931
987
  source: 'ts-charging-allocation-normal-source-v1',
932
988
  available: false,
@@ -943,6 +999,7 @@ class ChargingManagementModule extends BaseModule {
943
999
  };
944
1000
  shadow = {
945
1001
  ...plan,
1002
+ phasePlan,
946
1003
  comparison,
947
1004
  productivePrep,
948
1005
  productiveDecision,
@@ -1049,13 +1106,13 @@ class ChargingManagementModule extends BaseModule {
1049
1106
  ? { wallboxes: allocationDecisionForWritePlan.apply.wallboxes || [] }
1050
1107
  : (productivePrep && productivePrep.plan ? productivePrep.plan : shadow);
1051
1108
  writePlan = writePlanMirror.buildChargingSetpointWritePlan({
1052
- ...(input || {}),
1109
+ ...(allocationInput || {}),
1053
1110
  allocationPlan: productiveAllocationPlan,
1054
1111
  allowWrites: false,
1055
1112
  });
1056
1113
  writePlanProductivePrep = (typeof writePlanMirror.buildChargingSetpointWritePlanProductivePrep === 'function')
1057
1114
  ? writePlanMirror.buildChargingSetpointWritePlanProductivePrep({
1058
- ...(input || {}),
1115
+ ...(allocationInput || {}),
1059
1116
  allocationPlan: productiveAllocationPlan,
1060
1117
  allowWrites: false,
1061
1118
  }, writePlan)
@@ -1073,7 +1130,7 @@ class ChargingManagementModule extends BaseModule {
1073
1130
  };
1074
1131
  writePlanProductive = (typeof writePlanMirror.buildChargingSetpointWritePlanProductive === 'function')
1075
1132
  ? writePlanMirror.buildChargingSetpointWritePlanProductive({
1076
- ...(input || {}),
1133
+ ...(allocationInput || {}),
1077
1134
  allocationPlan: productiveAllocationPlan,
1078
1135
  allowWrites: !!(allocationDecisionForWritePlan && (allocationDecisionForWritePlan.normalSource || allocationDecisionForWritePlan.productive)),
1079
1136
  }, writePlan)
@@ -1130,6 +1187,7 @@ class ChargingManagementModule extends BaseModule {
1130
1187
  };
1131
1188
  }
1132
1189
 
1190
+ this._chargingPhaseSelectionTsLast = phasePlan;
1133
1191
  this._chargingAllocationTsShadowLast = shadow;
1134
1192
  this._chargingAllocationTsProductivePrepLast = productivePrep;
1135
1193
  this._chargingAllocationTsProductiveLast = productiveDecision;
@@ -1138,6 +1196,8 @@ class ChargingManagementModule extends BaseModule {
1138
1196
  this._chargingWritePlanTsProductivePrepLast = writePlanProductivePrep;
1139
1197
  this._chargingWritePlanTsProductiveLast = writePlanProductive;
1140
1198
  try {
1199
+ await this._queueState('chargingManagement.control.phaseSelectionJson', JSON.stringify(phasePlan || {}), true);
1200
+ await this._queueState('chargingManagement.control.phaseSelectionSource', phasePlan && phasePlan.available !== false ? 'ts-phase-selection' : 'unavailable', true);
1141
1201
  await this._queueState('chargingManagement.control.tsAllocationShadowJson', JSON.stringify(shadow || {}), true);
1142
1202
  await this._queueState('chargingManagement.control.tsAllocationProductivePrepJson', JSON.stringify(productivePrep || {}), true);
1143
1203
  await this._queueState('chargingManagement.control.tsAllocationProductiveJson', JSON.stringify(productiveDecision || {}), true);
@@ -1148,7 +1208,7 @@ class ChargingManagementModule extends BaseModule {
1148
1208
  await this._queueState('chargingManagement.control.tsWritePlanProductiveJson', JSON.stringify(writePlanProductive || {}), true);
1149
1209
  await this._queueState('chargingManagement.control.tsWritePlanSource', writePlanProductive && writePlanProductive.productive ? 'ts-write-plan' : (writePlanProductivePrep && writePlanProductivePrep.prepared ? 'ts-write-plan-prepared' : (writePlan && writePlan.available !== false ? 'ts-write-plan-shadow' : 'js-runtime')), true);
1150
1210
  } catch (_eWrite) {}
1151
- return { shadow, productivePrep, productiveDecision, normalSourceDecision, writePlan, writePlanProductivePrep, writePlanProductive };
1211
+ return { phasePlan, shadow, productivePrep, productiveDecision, normalSourceDecision, writePlan, writePlanProductivePrep, writePlanProductive };
1152
1212
  }
1153
1213
 
1154
1214
  /**
@@ -1172,6 +1232,20 @@ class ChargingManagementModule extends BaseModule {
1172
1232
  chargerType: w && w.chargerType,
1173
1233
  controlBasis: w && w.controlBasis,
1174
1234
  phases: w && w.phases,
1235
+ phaseMode: w && w.phaseMode,
1236
+ configuredPhaseCount: w && w.configuredPhaseCount,
1237
+ currentPhaseCount: w && w.currentPhaseCount,
1238
+ targetPhaseCount: w && w.targetPhaseCount,
1239
+ allocationPhaseCount: w && w.allocationPhaseCount,
1240
+ phaseSwitchRequired: w && w.phaseSwitchRequired,
1241
+ phaseSwitchAllowed: w && w.phaseSwitchAllowed,
1242
+ phaseSwitchCommandAllowed: w && w.phaseSwitchCommandAllowed,
1243
+ phaseSwitchKey: w && w.phaseSwitchKey,
1244
+ phaseSwitchValue: w && w.phaseSwitchValue,
1245
+ phaseSwitchReason: w && w.phaseSwitchReason,
1246
+ phaseSwitchSafetyStopRequired: w && w.phaseSwitchSafetyStopRequired,
1247
+ phaseSwitchCooldownRemainingMs: w && w.phaseSwitchCooldownRemainingMs,
1248
+ stopBeforePhaseSwitch: w && w.stopBeforePhaseSwitch,
1175
1249
  voltageV: w && w.voltageV,
1176
1250
  minPowerW: w && w.minPW,
1177
1251
  maxPowerW: w && w.maxPW,
@@ -1191,6 +1265,39 @@ class ChargingManagementModule extends BaseModule {
1191
1265
  }));
1192
1266
  }
1193
1267
 
1268
+
1269
+ /**
1270
+ * Code-Teil: _publishChargingPhaseSelectionRuntimeStates
1271
+ * Zweck: Übernimmt Hysterese-/Cooldown-Zustände aus der TS-Phasenwahl und veröffentlicht lesbare Diagnose pro Ladepunkt.
1272
+ */
1273
+ async _publishChargingPhaseSelectionRuntimeStates(phasePlan, wbList) {
1274
+ const decisions = phasePlan && Array.isArray(phasePlan.wallboxes) ? phasePlan.wallboxes : [];
1275
+ const bySafe = new Map((Array.isArray(wbList) ? wbList : []).filter(w => w && w.safe).map(w => [String(w.safe), w]));
1276
+ for (const d of decisions) {
1277
+ if (!d || typeof d !== 'object') continue;
1278
+ const safe = String(d.safe || '').trim();
1279
+ if (!safe) continue;
1280
+ const w = bySafe.get(safe);
1281
+ const high = Number(d.nextHighSinceMs || 0);
1282
+ const low = Number(d.nextLowSinceMs || 0);
1283
+ if (this._chargingPhaseHighSinceMs) {
1284
+ if (Number.isFinite(high) && high > 0) this._chargingPhaseHighSinceMs.set(safe, high);
1285
+ else this._chargingPhaseHighSinceMs.delete(safe);
1286
+ }
1287
+ if (this._chargingPhaseLowSinceMs) {
1288
+ if (Number.isFinite(low) && low > 0) this._chargingPhaseLowSinceMs.set(safe, low);
1289
+ else this._chargingPhaseLowSinceMs.delete(safe);
1290
+ }
1291
+ if (!w || !w.ch) continue;
1292
+ try { await this._queueState(`${w.ch}.phaseMode`, String(d.mode || w.phaseMode || ''), true); } catch { /* ignore */ }
1293
+ try { await this._queueState(`${w.ch}.currentPhaseCount`, Number(d.currentPhaseCount || w.currentPhaseCount || 0), true); } catch { /* ignore */ }
1294
+ try { await this._queueState(`${w.ch}.targetPhaseCount`, Number(d.targetPhaseCount || w.targetPhaseCount || 0), true); } catch { /* ignore */ }
1295
+ try { await this._queueState(`${w.ch}.phaseSwitchState`, d.switchRequired ? (d.switchCommandAllowed ? 'command-ready' : (d.safetyStopRequired ? 'safe-stop-before-switch' : 'pending')) : 'idle', true); } catch { /* ignore */ }
1296
+ try { await this._queueState(`${w.ch}.phaseSwitchReason`, String(d.reason || d.blocker || d.warning || ''), true); } catch { /* ignore */ }
1297
+ try { await this._queueState(`${w.ch}.phaseCooldownRemainingMs`, Number(d.cooldownRemainingMs || 0), true); } catch { /* ignore */ }
1298
+ }
1299
+ }
1300
+
1194
1301
  /**
1195
1302
  * Code-Teil: _publishChargingNormalSourceState
1196
1303
  * Zweck: Veröffentlicht den EVCS-TypeScript-Normalquellen-Lockdown. Dieser Status
@@ -1612,10 +1719,60 @@ class ChargingManagementModule extends BaseModule {
1612
1719
  : ((rawEntryBasis === 'power' || rawEntryBasis === 'powerw' || rawEntryBasis === 'w' || rawEntryBasis === 'watt' || rawEntryBasis === 'watts') ? 'powerW' : (w.controlBasis || 'auto'));
1613
1720
  const plannedSetpointKey = String(entry.setpointKey || '').trim();
1614
1721
  const shouldWrite = !!(entry.writeRequired !== false && !entry.blocked);
1722
+ const isPhaseSwitchEntry = String(entry.type || '').trim() === 'phaseSwitch' || rawEntryBasis === 'phase' || rawEntryBasis === 'phasemode';
1615
1723
  let applied = false;
1616
1724
  let applyStatus = shouldWrite ? 'planned' : (entry && entry.reason ? String(entry.reason) : 'skipped');
1617
1725
  let applyWrites = null;
1618
- if (!shouldWrite) {
1726
+ if (isPhaseSwitchEntry) {
1727
+ const phaseValue = entry ? entry.targetValue : undefined;
1728
+ if (!shouldWrite) {
1729
+ result.skippedCount += 1;
1730
+ } else if (!this.dp || !plannedSetpointKey || !(this.dp.getEntry && this.dp.getEntry(plannedSetpointKey))) {
1731
+ applyStatus = 'missing-phase-switch-setpoint';
1732
+ result.failedCount += 1;
1733
+ result.ok = false;
1734
+ } else {
1735
+ try {
1736
+ let writeResult = false;
1737
+ if (typeof phaseValue === 'boolean' && this.dp.writeBoolean) {
1738
+ writeResult = await this.dp.writeBoolean(plannedSetpointKey, phaseValue, false);
1739
+ } else {
1740
+ const n = Number(phaseValue);
1741
+ if (Number.isFinite(n) && this.dp.writeNumber) {
1742
+ writeResult = await this.dp.writeNumber(plannedSetpointKey, n, false);
1743
+ } else {
1744
+ const dpEntry = this.dp.getEntry(plannedSetpointKey);
1745
+ await this.adapter.setForeignStateAsync(dpEntry.objectId, phaseValue, false);
1746
+ if (this.dp.lastWriteByObjectId && typeof this.dp.lastWriteByObjectId.set === 'function') {
1747
+ this.dp.lastWriteByObjectId.set(dpEntry.objectId, { val: phaseValue, ts: Date.now() });
1748
+ }
1749
+ writeResult = true;
1750
+ }
1751
+ }
1752
+ applied = writeResult !== false;
1753
+ applyStatus = applied ? 'phase-switch-applied' : 'phase-switch-write-skipped';
1754
+ applyWrites = [{ key: plannedSetpointKey, value: phaseValue, basis: 'phase' }];
1755
+ if (applied) {
1756
+ result.appliedCount += 1;
1757
+ const targetPhase = Number(entry.targetPhaseCount || 0);
1758
+ if (targetPhase === 1 || targetPhase === 3) {
1759
+ if (this._chargingPhaseAssumedBySafe && typeof this._chargingPhaseAssumedBySafe.set === 'function') this._chargingPhaseAssumedBySafe.set(w.safe, targetPhase);
1760
+ const cooldownMs = Number(w.phaseSwitchCooldownMs || 15 * 60 * 1000);
1761
+ const settleMs = Number(w.phaseSwitchSettleMs || 30 * 1000);
1762
+ const nowMs = Date.now();
1763
+ if (this._chargingPhaseCooldownUntilMs && typeof this._chargingPhaseCooldownUntilMs.set === 'function') this._chargingPhaseCooldownUntilMs.set(w.safe, nowMs + (Number.isFinite(cooldownMs) && cooldownMs > 0 ? cooldownMs : 15 * 60 * 1000));
1764
+ if (this._chargingPhaseSettleUntilMs && typeof this._chargingPhaseSettleUntilMs.set === 'function') this._chargingPhaseSettleUntilMs.set(w.safe, nowMs + (Number.isFinite(settleMs) && settleMs > 0 ? settleMs : 30 * 1000));
1765
+ }
1766
+ } else {
1767
+ result.skippedCount += 1;
1768
+ }
1769
+ } catch (e) {
1770
+ applyStatus = e && e.message ? `phase_switch_executor_error:${e.message}` : 'phase_switch_executor_error';
1771
+ result.failedCount += 1;
1772
+ result.ok = false;
1773
+ }
1774
+ }
1775
+ } else if (!shouldWrite) {
1619
1776
  result.skippedCount += 1;
1620
1777
  } else if (!this.dp) {
1621
1778
  applyStatus = 'no_dp_registry';
@@ -1659,6 +1816,10 @@ class ChargingManagementModule extends BaseModule {
1659
1816
  }
1660
1817
  try { await this._queueState(`${w.ch}.targetCurrentA`, targetA, true); } catch { /* ignore */ }
1661
1818
  try { await this._queueState(`${w.ch}.targetPowerW`, targetW, true); } catch { /* ignore */ }
1819
+ if (isPhaseSwitchEntry) {
1820
+ try { await this._queueState(`${w.ch}.phaseSwitchState`, applyStatus, true); } catch { /* ignore */ }
1821
+ try { await this._queueState(`${w.ch}.targetPhaseCount`, Number(entry.targetPhaseCount || 0), true); } catch { /* ignore */ }
1822
+ }
1662
1823
  try { await this._queueState(`${w.ch}.applied`, applied, true); } catch { /* ignore */ }
1663
1824
  try { await this._queueState(`${w.ch}.applyStatus`, applyStatus, true); } catch { /* ignore */ }
1664
1825
  try {
@@ -1681,8 +1842,12 @@ class ChargingManagementModule extends BaseModule {
1681
1842
  dbg.writePlanFallbackReason = fallbackReason || '';
1682
1843
  dbg.executorBasis = plannedBasis;
1683
1844
  dbg.executorSetpointKey = plannedSetpointKey || '';
1845
+ if (isPhaseSwitchEntry) {
1846
+ dbg.phaseSwitchApplied = applied;
1847
+ dbg.phaseSwitchValue = entry.targetValue;
1848
+ }
1684
1849
  }
1685
- result.entries.push({ safe, targetW, targetA, basis: plannedBasis, setpointKey: plannedSetpointKey || '', applied, status: applyStatus, source: executorSource || '' });
1850
+ result.entries.push({ safe, targetW, targetA, basis: isPhaseSwitchEntry ? 'phase' : plannedBasis, setpointKey: plannedSetpointKey || '', applied, status: applyStatus, source: executorSource || '', targetPhaseCount: Number(entry.targetPhaseCount || 0), targetValue: entry.targetValue });
1686
1851
  }
1687
1852
  this._chargingWritePlanExecutorLast = result;
1688
1853
  try {
@@ -2256,6 +2421,8 @@ class ChargingManagementModule extends BaseModule {
2256
2421
  await mk('chargingManagement.control.tsAllocationProductiveJson', 'TypeScript EVCS-Allocation produktiv (JSON)', 'string', 'json');
2257
2422
  await mk('chargingManagement.control.tsAllocationNormalSourceJson', 'TypeScript EVCS-Allocation Normalquelle (JSON)', 'string', 'json');
2258
2423
  await mk('chargingManagement.control.tsAllocationSource', 'TypeScript EVCS-Allocation source/prep state', 'string', 'text');
2424
+ await mk('chargingManagement.control.phaseSelectionJson', 'EVCS AC-Phasenwahl 1p/3p Auto-PV (JSON)', 'string', 'json');
2425
+ await mk('chargingManagement.control.phaseSelectionSource', 'EVCS AC-Phasenwahl source', 'string', 'text');
2259
2426
  await mk('chargingManagement.control.tsWritePlanShadowJson', 'TypeScript EVCS-Setpoint Write-Plan Shadow (JSON)', 'string', 'json');
2260
2427
  await mk('chargingManagement.control.tsWritePlanProductivePrepJson', 'TypeScript EVCS-Setpoint Write-Plan Produktiv-Vorbereitung (JSON)', 'string', 'json');
2261
2428
  await mk('chargingManagement.control.tsWritePlanProductiveJson', 'TypeScript EVCS-Setpoint Write-Plan produktiv (JSON)', 'string', 'json');
@@ -2505,6 +2672,12 @@ class ChargingManagementModule extends BaseModule {
2505
2672
  await mk('boostRemainingMin', 'Boost remaining (min)', 'number', 'value');
2506
2673
  await mk('boostTimeoutMin', 'Boost timeout (min) (effective)', 'number', 'value');
2507
2674
  await mk('phases', 'Phases', 'number', 'value');
2675
+ await mk('phaseMode', 'AC Phasenmodus (fixed-1p|fixed-3p|auto-pv)', 'string', 'text');
2676
+ await mk('currentPhaseCount', 'Aktuelle AC-Phasen', 'number', 'value');
2677
+ await mk('targetPhaseCount', 'Ziel AC-Phasen', 'number', 'value');
2678
+ await mk('phaseSwitchState', 'Phasenumschaltung Status', 'string', 'text');
2679
+ await mk('phaseSwitchReason', 'Phasenumschaltung Grund', 'string', 'text');
2680
+ await mk('phaseCooldownRemainingMs', 'Phasenumschaltung Cooldown Rest (ms)', 'number', 'value.time');
2508
2681
  await mk('minPowerW', 'Min power (W)', 'number', 'value.power');
2509
2682
  await mk('maxPowerW', 'Max power (W)', 'number', 'value.power');
2510
2683
  await mk('para14aCapW', '§14a cap (W)', 'number', 'value.power');
@@ -2875,6 +3048,14 @@ class ChargingManagementModule extends BaseModule {
2875
3048
  const defaultMaxA = clamp(num(cfg.maxCurrentA, 16), 0, 2000);
2876
3049
 
2877
3050
  const acMinPower3pW = clamp(num(cfg.acMinPower3pW, 4200), 0, 1e12);
3051
+ const phaseAutoEnabled = cfg.phaseAutoEnabled !== false;
3052
+ const phaseSwitchUpThresholdW = clamp(num(cfg.phaseSwitchUpThresholdW, 4800), 0, 1e12);
3053
+ const phaseSwitchDownThresholdW = clamp(num(cfg.phaseSwitchDownThresholdW, 3700), 0, 1e12);
3054
+ const phaseSwitchUpStableMs = clamp(num(cfg.phaseSwitchUpStableSec, 300), 0, 86400) * 1000;
3055
+ const phaseSwitchDownStableMs = clamp(num(cfg.phaseSwitchDownStableSec, 120), 0, 86400) * 1000;
3056
+ const phaseSwitchCooldownMs = clamp(num(cfg.phaseSwitchCooldownSec, 900), 0, 86400) * 1000;
3057
+ const phaseSwitchSettleMs = clamp(num(cfg.phaseSwitchSettleSec, 30), 0, 3600) * 1000;
3058
+ const phaseSwitchSafePowerW = clamp(num(cfg.phaseSwitchSafePowerW, 150), 0, 10000);
2878
3059
  const activityThresholdW = clamp(num(cfg.activityThresholdW, 200), 0, 1e12);
2879
3060
  const stopGraceSec = clamp(num(cfg.stopGraceSec, 30), 0, 3600);
2880
3061
  const sessionKeepSec = clamp(num(cfg.sessionKeepSec, 300), 0, 86400);
@@ -3104,6 +3285,25 @@ class ChargingManagementModule extends BaseModule {
3104
3285
 
3105
3286
  // For AC: phases/current bounds apply. For DC: phases are informational; distribution is watt-based.
3106
3287
  const phases = Number(wb.phases || defaultPhases) === 1 ? 1 : 3;
3288
+ const normalizePhaseModeRuntime = (value, fallbackPhases) => {
3289
+ const raw = String(value || '').trim().toLowerCase().replace(/[^a-z0-9]+/g, '');
3290
+ if (raw === 'autopv' || raw === 'pvauto' || raw === 'auto13' || raw === 'auto1p3p' || raw === 'auto') return 'auto-pv';
3291
+ if (raw === 'fixed1p' || raw === '1p' || raw === 'onephase' || raw === 'fixed1') return 'fixed-1p';
3292
+ if (raw === 'fixed3p' || raw === '3p' || raw === 'threephase' || raw === 'fixed3') return 'fixed-3p';
3293
+ return Number(fallbackPhases) === 1 ? 'fixed-1p' : 'fixed-3p';
3294
+ };
3295
+ const phaseMode = chargerType === 'AC' ? normalizePhaseModeRuntime(wb.phaseMode, phases) : 'fixed-1p';
3296
+ const phaseSwitchId = String(wb.phaseSwitchId || wb.phaseSwitchKey || wb.phaseModeWriteId || '').trim();
3297
+ const phaseFeedbackId = String(wb.phaseFeedbackId || wb.phaseFeedbackKey || wb.phaseModeReadId || '').trim();
3298
+ const phaseSwitchValue1p = (wb.phaseSwitchValue1p !== undefined && wb.phaseSwitchValue1p !== null && String(wb.phaseSwitchValue1p).trim() !== '') ? wb.phaseSwitchValue1p : 1;
3299
+ const phaseSwitchValue3p = (wb.phaseSwitchValue3p !== undefined && wb.phaseSwitchValue3p !== null && String(wb.phaseSwitchValue3p).trim() !== '') ? wb.phaseSwitchValue3p : 3;
3300
+ const stopBeforePhaseSwitch = wb.stopBeforePhaseSwitch !== false;
3301
+ const wbPhaseSwitchUpThresholdW = clamp(num(wb.phaseSwitchUpThresholdW, phaseSwitchUpThresholdW), 0, 1e12);
3302
+ const wbPhaseSwitchDownThresholdW = clamp(num(wb.phaseSwitchDownThresholdW, phaseSwitchDownThresholdW), 0, 1e12);
3303
+ const wbPhaseSwitchUpStableMs = clamp(num(wb.phaseSwitchUpStableSec, phaseSwitchUpStableMs / 1000), 0, 86400) * 1000;
3304
+ const wbPhaseSwitchDownStableMs = clamp(num(wb.phaseSwitchDownStableSec, phaseSwitchDownStableMs / 1000), 0, 86400) * 1000;
3305
+ const wbPhaseSwitchCooldownMs = clamp(num(wb.phaseSwitchCooldownSec, phaseSwitchCooldownMs / 1000), 0, 86400) * 1000;
3306
+ const wbPhaseSwitchSettleMs = clamp(num(wb.phaseSwitchSettleSec, phaseSwitchSettleMs / 1000), 0, 3600) * 1000;
3107
3307
  let minA = clamp(num(wb.minA, defaultMinA), 0, 2000);
3108
3308
  const maxA = clamp(num(wb.maxA, defaultMaxA), 0, 2000);
3109
3309
 
@@ -3140,6 +3340,8 @@ class ChargingManagementModule extends BaseModule {
3140
3340
  if (setPowerWId) await this.dp.upsert({ key: `cm.wb.${safe}.setW`, objectId: setPowerWId, dataType: 'number', direction: 'out', unit: 'W', deadband: 25, maxWriteIntervalMs: 45000 });
3141
3341
  if (enableId) await this.dp.upsert({ key: `cm.wb.${safe}.en`, objectId: enableId, dataType: 'boolean', direction: 'out' });
3142
3342
  if (statusId) await this.dp.upsert({ key: `cm.wb.${safe}.st`, objectId: statusId, dataType: 'mixed', direction: 'in' });
3343
+ if (phaseSwitchId) await this.dp.upsert({ key: `cm.wb.${safe}.phaseSet`, objectId: phaseSwitchId, dataType: 'mixed', direction: 'out' });
3344
+ if (phaseFeedbackId) await this.dp.upsert({ key: `cm.wb.${safe}.phaseFb`, objectId: phaseFeedbackId, dataType: 'mixed', direction: 'in' });
3143
3345
 
3144
3346
  if (l1Id) await this.dp.upsert({ key: `cm.wb.${safe}.l1A`, objectId: l1Id, dataType: 'number', direction: 'in', unit: 'A' });
3145
3347
  if (l2Id) await this.dp.upsert({ key: `cm.wb.${safe}.l2A`, objectId: l2Id, dataType: 'number', direction: 'in', unit: 'A' });
@@ -3165,6 +3367,22 @@ class ChargingManagementModule extends BaseModule {
3165
3367
  }
3166
3368
  }
3167
3369
 
3370
+ const normalizePhaseFeedbackRuntime = (value) => {
3371
+ const raw = String(value ?? '').trim().toLowerCase();
3372
+ if (!raw) return null;
3373
+ if (raw === '1' || raw === '1p' || raw === 'one' || raw.includes('1-phase') || raw.includes('single')) return 1;
3374
+ if (raw === '3' || raw === '3p' || raw === 'three' || raw.includes('3-phase')) return 3;
3375
+ const n = Number(raw.replace(',', '.'));
3376
+ if (Number.isFinite(n)) return Math.round(n) === 1 ? 1 : (Math.round(n) === 3 ? 3 : null);
3377
+ return null;
3378
+ };
3379
+ const phaseFeedbackRaw = (phaseFeedbackId && this.dp) ? this.dp.getRaw(`cm.wb.${safe}.phaseFb`) : null;
3380
+ const feedbackPhaseCount = normalizePhaseFeedbackRuntime(phaseFeedbackRaw);
3381
+ const assumedPhaseCount = this._chargingPhaseAssumedBySafe && this._chargingPhaseAssumedBySafe.has(safe) ? this._chargingPhaseAssumedBySafe.get(safe) : null;
3382
+ const currentPhaseCount = chargerType === 'AC'
3383
+ ? (feedbackPhaseCount === 1 || feedbackPhaseCount === 3 ? feedbackPhaseCount : ((assumedPhaseCount === 1 || assumedPhaseCount === 3) ? assumedPhaseCount : phases))
3384
+ : 1;
3385
+ const effectiveRuntimePhaseCount = chargerType === 'AC' ? currentPhaseCount : 1;
3168
3386
 
3169
3387
  // Diagnostics: freshness + mapping completeness
3170
3388
  const hasSetpoint = !!(setCurrentAId || setPowerWId);
@@ -3261,6 +3479,16 @@ class ChargingManagementModule extends BaseModule {
3261
3479
  const inGrace = !!(chargingSince && lastActive && (now - lastActive) <= stopGraceMs);
3262
3480
  const isCharging = !!(online && enabled && (isChargingRaw || inGrace));
3263
3481
  const chargingSinceForState = isCharging ? chargingSince : 0;
3482
+ try {
3483
+ await this._queueState(`${ch}.phaseMode`, phaseMode, true);
3484
+ await this._queueState(`${ch}.currentPhaseCount`, currentPhaseCount, true);
3485
+ await this._queueState(`${ch}.targetPhaseCount`, currentPhaseCount, true);
3486
+ await this._queueState(`${ch}.phaseSwitchReason`, '', true);
3487
+ const cdUntil = this._chargingPhaseCooldownUntilMs && this._chargingPhaseCooldownUntilMs.has(safe) ? Number(this._chargingPhaseCooldownUntilMs.get(safe)) : 0;
3488
+ await this._queueState(`${ch}.phaseCooldownRemainingMs`, Math.max(0, cdUntil - now), true);
3489
+ } catch {
3490
+ // ignore phase diagnostics
3491
+ }
3264
3492
  // Determine effective control basis for this device
3265
3493
  const hasSetA = !!setCurrentAId;
3266
3494
  const hasSetW = !!setPowerWId;
@@ -3281,7 +3509,7 @@ class ChargingManagementModule extends BaseModule {
3281
3509
  }
3282
3510
 
3283
3511
  // Compute min/max power caps for distribution (W)
3284
- const vFactor = voltageV * phases;
3512
+ const vFactor = voltageV * effectiveRuntimePhaseCount;
3285
3513
 
3286
3514
  let minPW = 0;
3287
3515
  let maxPW = 0;
@@ -3318,7 +3546,7 @@ class ChargingManagementModule extends BaseModule {
3318
3546
  // When controlling by current (A), the wallbox already has a physical minimum current (typically 6 A).
3319
3547
  // Enforcing a power minimum here would lead to fractional currents (e.g. 6.1 A) which some chargers
3320
3548
  // or adapters do not accept and can cause start/stop behaviour.
3321
- if (controlBasis === 'powerW' && phases === 3 && acMinPower3pW > 0) {
3549
+ if (controlBasis === 'powerW' && effectiveRuntimePhaseCount === 3 && acMinPower3pW > 0) {
3322
3550
  minPW = Math.max(minPW, acMinPower3pW);
3323
3551
  }
3324
3552
 
@@ -3806,7 +4034,27 @@ class ChargingManagementModule extends BaseModule {
3806
4034
  priority,
3807
4035
  chargerType,
3808
4036
  controlBasis,
3809
- phases,
4037
+ phases: effectiveRuntimePhaseCount,
4038
+ configuredPhaseCount: phases,
4039
+ currentPhaseCount,
4040
+ targetPhaseCount: currentPhaseCount,
4041
+ allocationPhaseCount: effectiveRuntimePhaseCount,
4042
+ phaseMode,
4043
+ phaseSwitchKey: phaseSwitchId ? `cm.wb.${safe}.phaseSet` : '',
4044
+ phaseSwitchValue1p,
4045
+ phaseSwitchValue3p,
4046
+ stopBeforePhaseSwitch,
4047
+ phaseSwitchUpThresholdW: wbPhaseSwitchUpThresholdW,
4048
+ phaseSwitchDownThresholdW: wbPhaseSwitchDownThresholdW,
4049
+ phaseSwitchUpStableMs: wbPhaseSwitchUpStableMs,
4050
+ phaseSwitchDownStableMs: wbPhaseSwitchDownStableMs,
4051
+ phaseSwitchCooldownMs: wbPhaseSwitchCooldownMs,
4052
+ phaseSwitchSettleMs: wbPhaseSwitchSettleMs,
4053
+ phaseSwitchSafePowerW,
4054
+ highSinceMs: this._chargingPhaseHighSinceMs && this._chargingPhaseHighSinceMs.has(safe) ? this._chargingPhaseHighSinceMs.get(safe) : 0,
4055
+ lowSinceMs: this._chargingPhaseLowSinceMs && this._chargingPhaseLowSinceMs.has(safe) ? this._chargingPhaseLowSinceMs.get(safe) : 0,
4056
+ cooldownUntilMs: this._chargingPhaseCooldownUntilMs && this._chargingPhaseCooldownUntilMs.has(safe) ? this._chargingPhaseCooldownUntilMs.get(safe) : 0,
4057
+ settleUntilMs: this._chargingPhaseSettleUntilMs && this._chargingPhaseSettleUntilMs.has(safe) ? this._chargingPhaseSettleUntilMs.get(safe) : 0,
3810
4058
  voltageV,
3811
4059
  minA,
3812
4060
  maxA,
@@ -6824,6 +7072,7 @@ if (components.length) {
6824
7072
  }
6825
7073
 
6826
7074
 
7075
+ const tsWallboxesForAllocation = this._mapChargingWallboxesForTsAllocation(wbList);
6827
7076
  const tsAllocationState = await this._publishChargingAllocationTsShadow({
6828
7077
  mode,
6829
7078
  budgetMode: effectiveBudgetMode,
@@ -6850,9 +7099,31 @@ if (components.length) {
6850
7099
  preferTsNativeAllocation: true,
6851
7100
  tsNormalSourceLock: true,
6852
7101
  allowJsComparisonFallback: false,
6853
- wallboxes: this._mapChargingWallboxesForTsAllocation(wbList),
7102
+ wallboxes: tsWallboxesForAllocation,
6854
7103
  allocations: debugAlloc,
7104
+ phaseSelection: {
7105
+ now,
7106
+ mode,
7107
+ budgetMode: effectiveBudgetMode,
7108
+ pvAvailableW: pvCapW,
7109
+ stablePvAvailableW: (typeof pvSurplusNoEvAvg5mWState === 'number' && Number.isFinite(pvSurplusNoEvAvg5mWState)) ? pvSurplusNoEvAvg5mWState : pvCapW,
7110
+ budgetW,
7111
+ remainingW: Number.isFinite(budgetW) ? remainingW : pvCapW,
7112
+ staleMeter,
7113
+ staleBudget,
7114
+ phaseAutoEnabled,
7115
+ switchUpThresholdW: phaseSwitchUpThresholdW,
7116
+ switchDownThresholdW: phaseSwitchDownThresholdW,
7117
+ switchUpStableMs: phaseSwitchUpStableMs,
7118
+ switchDownStableMs: phaseSwitchDownStableMs,
7119
+ switchCooldownMs: phaseSwitchCooldownMs,
7120
+ switchSettleMs: phaseSwitchSettleMs,
7121
+ switchSafePowerW: phaseSwitchSafePowerW,
7122
+ wallboxes: tsWallboxesForAllocation,
7123
+ ts: now,
7124
+ },
6855
7125
  });
7126
+ await this._publishChargingPhaseSelectionRuntimeStates(tsAllocationState && tsAllocationState.phasePlan ? tsAllocationState.phasePlan : null, wbList);
6856
7127
 
6857
7128
  const tsWritePlanProductive = tsAllocationState && tsAllocationState.writePlanProductive ? tsAllocationState.writePlanProductive : null;
6858
7129
  const tsWritePlanUsed = await this._executeChargingTsSetpointPlan(
package/io-package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "common": {
3
3
  "name": "nexowatt-ui",
4
- "version": "0.8.7",
4
+ "version": "0.8.8",
5
5
  "news": {
6
+ "0.8.8": {
7
+ "de": "Version 0.8.8: EVCS AC-Phasenautomatik für PV-Überschussladen ergänzt. TypeScript plant sichere 1p/3p-Umschaltungen mit Hysterese, Cooldown, Stop-vor-Umschaltung, Write-Plan und Diagnosestates.",
8
+ "en": "Version 0.8.8: Adds EVCS AC phase automation for PV surplus charging. TypeScript now plans safe 1p/3p switching with hysteresis, cooldown, stop-before-switch, write plan and diagnostics."
9
+ },
6
10
  "0.8.7": {
7
11
  "de": "Version 0.8.7: Hotfix für die EOS-Freischaltung im App-Center. Der App-Center-Runtime-Build ist wieder synchron mit der TypeScript-Quelle und lädt Lizenzdaten über API-/State-Fallbacks, damit gültige EOS-Lizenzen alle Apps anzeigen.",
8
12
  "en": "Version 0.8.7: Hotfix for EOS activation in the App Center. The App Center runtime build is synchronized with the TypeScript source again and loads license data through API/state fallbacks so valid EOS licenses show all apps."
@@ -26,10 +30,6 @@
26
30
  "0.8.2": {
27
31
  "de": "Version 0.8.2: Windows-sicherer npm-Publish-Check. Der TypeScript-Compiler wird vor Publish-Checks robust aufgelöst oder DevDependencies werden automatisch nachinstalliert; App-Center-Statusfarben aus 0.8.1 bleiben erhalten.",
28
32
  "en": "Version 0.8.2: Windows-safe npm publish check. The TypeScript compiler is resolved robustly before publish checks or devDependencies are installed automatically; App Center status colors from 0.8.1 remain in place."
29
- },
30
- "0.8.1": {
31
- "de": "Version 0.8.1: App-Center zeigt nicht installierte Apps jetzt mit rotem Nein-Status; TypeScript ist weiterhin kanonische Runtime-Quelle. Publish-Fix: TypeScript ist wieder echte devDependency und package-lock nutzt öffentliche npm-Registry-URLs.",
32
- "en": "Version 0.8.1: The App Center now shows uninstalled apps with a red No state; TypeScript remains the canonical runtime source. Publish fix: TypeScript is restored as a real devDependency and package-lock uses public npm registry URLs."
33
33
  }
34
34
  },
35
35
  "title": "NexoWatt UI",