From 546fb366db0b28bf576b5d4c5d8f3d6f73217a3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Thu, 19 Feb 2026 16:17:18 +0100 Subject: [PATCH] Update phaseCount handling if charging has not been started yet --- pcelectric/integrationpluginpcelectric.cpp | 111 +++++++++++---------- 1 file changed, 59 insertions(+), 52 deletions(-) diff --git a/pcelectric/integrationpluginpcelectric.cpp b/pcelectric/integrationpluginpcelectric.cpp index 4f082c0..57235fc 100644 --- a/pcelectric/integrationpluginpcelectric.cpp +++ b/pcelectric/integrationpluginpcelectric.cpp @@ -356,30 +356,31 @@ void IntegrationPluginPcElectric::setupConnection(ThingSetupInfo *info) qCDebug(dcPcElectric()) << "Update finished for" << thing; qCDebug(dcPcElectric()) << connection; - if (!connection->phaseAutoSwitch()) { + if (connection->phaseAutoSwitch()) { + thing->setStatePossibleValues("desiredPhaseCount", {1, 3}); // Enable phase switching + + switch (connection->chargingRelayState()) { + case EV11ModbusTcpConnection::ChargingRelayStateNoCharging: + // Not charging, assuming phase count matches the desired phase count... + thing->setStateValue("phaseCount", thing->stateValue("desiredPhaseCount")); + break; + case EV11ModbusTcpConnection::ChargingRelayStateSinglePhase: + thing->setStateValue("phaseCount", 1); + break; + case EV11ModbusTcpConnection::ChargingRelayStateTheePhase: + thing->setStateValue("phaseCount", 3); + break; + } + } else { // Note: if auto phase switching is disabled, the wallbox forces 3 phase charging thing->setStatePossibleValues("desiredPhaseCount", {3}); // Disable phase switching (default 3) thing->setStateValue("desiredPhaseCount", 3); thing->setStateValue("phaseCount", 3); - } else { - thing->setStatePossibleValues("desiredPhaseCount", {1, 3}); // Enable phase switching - } - - if (connection->chargingRelayState() != EV11ModbusTcpConnection::ChargingRelayStateNoCharging) { - if (connection->chargingRelayState() == EV11ModbusTcpConnection::ChargingRelayStateSinglePhase) { - thing->setStateValue("phaseCount", 1); - } else if (connection->chargingRelayState() == EV11ModbusTcpConnection::ChargingRelayStateTheePhase) { - thing->setStateValue("phaseCount", 3); - } } thing->setStateMaxValue("maxChargingCurrent", connection->maxChargingCurrentDip() / 1000); thing->setStateValue("pluggedIn", connection->chargingState() >= PceWallbox::ChargingStateB1 && connection->chargingState() < PceWallbox::ChargingStateError); - thing->setStateValue("charging", connection->chargingState() == PceWallbox::ChargingStateC2); - if (connection->chargingRelayState() != EV11ModbusTcpConnection::ChargingRelayStateNoCharging) { - thing->setStateValue("phaseCount", connection->chargingRelayState() == EV11ModbusTcpConnection::ChargingRelayStateSinglePhase ? 1 : 3); - } switch (connection->chargingState()) { case PceWallbox::ChargingStateInitializing: @@ -447,6 +448,49 @@ void IntegrationPluginPcElectric::setupConnection(ThingSetupInfo *info) break; } + if (connection->firmwareRevision() >= "0025") { + thing->setStateValue("digitalInputFlag", QString("0b%1").arg(connection->digitalInputFlag(), 16, 2, QLatin1Char('0'))); + thing->setStateValue("modeR37", connection->modeR37()); + + // Energy information only available with meter and 0025 + if (thing->thingClassId() == ev11ThingClassId) { + thing->setStateValue("currentPower", connection->currentPower()); + thing->setStateValue("sessionEnergy", connection->powerMeter0()); + thing->setStateValue("totalEnergyConsumed", connection->totalEnergyConsumed()); + thing->setStateValue("currentPowerPhaseA", connection->activePowerL1()); + thing->setStateValue("currentPowerPhaseB", connection->activePowerL2()); + thing->setStateValue("currentPowerPhaseC", connection->activePowerL3()); + thing->setStateValue("voltagePhaseA", connection->voltageL1()); + thing->setStateValue("voltagePhaseB", connection->voltageL2()); + thing->setStateValue("voltagePhaseC", connection->voltageL3()); + thing->setStateValue("currentPhaseA", connection->currentL1()); + thing->setStateValue("currentPhaseB", connection->currentL2()); + thing->setStateValue("currentPhaseC", connection->currentL3()); + } + + } else { + // In firmware 0019 there is no current power register, depending on the CP state we can assume the car is consuming the amount + // we adjusted, if the car is full, the CP state will change back to B2 + if (thing->thingClassId() == ev11ThingClassId) { + thing->setStateValue("sessionEnergy", connection->powerMeter0()); + if (connection->chargingState() == PceWallbox::ChargingStateC2 && connection->currentPower() == 0) { + // We are currently chargin, but the wallbox reports 0 W (which is expected), let's calculate the theoretical power... + double assumedCurrentPower = thing->stateValue("phaseCount").toInt() * 230 * thing->stateValue("maxChargingCurrent").toDouble(); + qCDebug(dcPcElectric()) + << "Assuming current power" + << assumedCurrentPower + << "W (" + << thing->stateValue("phaseCount").toInt() + << "phases * 230 V *" + << thing->stateValue("maxChargingCurrent").toDouble() + << "A )"; + thing->setStateValue("currentPower", assumedCurrentPower); + } else { + thing->setStateValue("currentPower", 0); + } + } + } + if (m_initialUpdate.value(thing)) { m_initialUpdate[thing] = false; @@ -488,43 +532,6 @@ void IntegrationPluginPcElectric::setupConnection(ThingSetupInfo *info) thing->setSettingValue("forceChargingResume", connection->forceChargingResume() == 1 ? true : false); } } - - if (connection->firmwareRevision() >= "0025") { - thing->setStateValue("digitalInputFlag", QString("0b%1").arg(connection->digitalInputFlag(), 16, 2, QLatin1Char('0'))); - thing->setStateValue("modeR37", connection->modeR37()); - - // Energy information only available with meter and 0025 - if (thing->thingClassId() == ev11ThingClassId) { - thing->setStateValue("currentPower", connection->currentPower()); - thing->setStateValue("sessionEnergy", connection->powerMeter0()); - thing->setStateValue("totalEnergyConsumed", connection->totalEnergyConsumed()); - thing->setStateValue("currentPowerPhaseA", connection->activePowerL1()); - thing->setStateValue("currentPowerPhaseB", connection->activePowerL2()); - thing->setStateValue("currentPowerPhaseC", connection->activePowerL3()); - thing->setStateValue("voltagePhaseA", connection->voltageL1()); - thing->setStateValue("voltagePhaseB", connection->voltageL2()); - thing->setStateValue("voltagePhaseC", connection->voltageL3()); - thing->setStateValue("currentPhaseA", connection->currentL1()); - thing->setStateValue("currentPhaseB", connection->currentL2()); - thing->setStateValue("currentPhaseC", connection->currentL3()); - } - - } else { - // In firmware 0019 there is no current power register, depending on the CP state we can assume the car is consuming the amount - // we adjusted, if the car is full, the CP state will change back to B2 - if (thing->thingClassId() == ev11ThingClassId) { - thing->setStateValue("sessionEnergy", connection->powerMeter0()); - if (connection->chargingState() == PceWallbox::ChargingStateC2 && connection->currentPower() == 0) { - // We are currently chargin, but the wallbox reports 0 W (which is expected), let's calculate the theoretical power... - double assumedCurrentPower = thing->stateValue("phaseCount").toInt() * 230 * thing->stateValue("maxChargingCurrent").toDouble(); - qCDebug(dcPcElectric()) << "Assuming current power" << assumedCurrentPower << "W (" << thing->stateValue("phaseCount").toInt() << "phases * 230 V *" - << thing->stateValue("maxChargingCurrent").toDouble() << "A )"; - thing->setStateValue("currentPower", assumedCurrentPower); - } else { - thing->setStateValue("currentPower", 0); - } - } - } }); connect(thing, &Thing::settingChanged, connection, [thing, connection](const ParamTypeId ¶mTypeId, const QVariant &value) {