diff --git a/schrack/cion-registers.json b/schrack/cion-registers.json index f7e9350..1acffe7 100644 --- a/schrack/cion-registers.json +++ b/schrack/cion-registers.json @@ -109,7 +109,7 @@ "type": "uint16", "registerType": "holdingRegister", "readSchedule": "update", - "description": "Mode3-State A, B, C, D, U", + "description": "Status bits", "defaultValue": 85, "access": "R" }, @@ -120,7 +120,7 @@ "type": "uint16", "registerType": "holdingRegister", "readSchedule": "update", - "description": "Status bits", + "description": "CP Status bits", "defaultValue": 0, "access": "R" }, diff --git a/schrack/integrationpluginschrack.cpp b/schrack/integrationpluginschrack.cpp index 8ba80ca..9e4e647 100644 --- a/schrack/integrationpluginschrack.cpp +++ b/schrack/integrationpluginschrack.cpp @@ -107,7 +107,7 @@ void IntegrationPluginSchrack::setupThing(ThingSetupInfo *info) // Note: This register really only tells us if we can control anything... i.e. if the wallbox is unlocked via RFID connect(cionConnection, &CionModbusRtuConnection::chargingEnabledChanged, thing, [=](quint16 charging){ - qCDebug(dcSchrack()) << "Charging enabled changed:" << charging; + qCDebug(dcSchrack()) << "Charge control enabled changed:" << charging; }); // We can write chargingCurrentSetpoint to the preferred charging we want, and the wallbox will take it, @@ -139,13 +139,20 @@ void IntegrationPluginSchrack::setupThing(ThingSetupInfo *info) } }); - connect(cionConnection, &CionModbusRtuConnection::statusBitsChanged, thing, [=](quint16 /*statusBits*/){ + connect(cionConnection, &CionModbusRtuConnection::statusBitsChanged, thing, [=](quint16 statusBits){ thing->setStateValue(cionConnectedStateTypeId, true); -// qCDebug(dcSchrack()) << "Status bits changed:" << statusBits; + StatusBits status = static_cast(statusBits); + // TODO: Verify if the statusBit for PluggedIn is reliable and if so, use that instead of the plugged in time for the plugged in state. + qCDebug(dcSchrack()) << "Status bits changed:" << status; }); connect(cionConnection, &CionModbusRtuConnection::minChargingCurrentChanged, thing, [=](quint16 minChargingCurrent){ qCDebug(dcSchrack()) << "Minimum charging current changed:" << minChargingCurrent; + if (minChargingCurrent > 32) { + // Apparently this register occationally holds random values... As a quick'n dirty workaround we'll ignore everything > 32 + qCWarning(dcSchrack()) << "Detected a bogus min charging current register value (reg. 507) of" << minChargingCurrent << ". Ignoring it..."; + return; + } thing->setStateMinValue(cionMaxChargingCurrentStateTypeId, minChargingCurrent); }); @@ -239,11 +246,27 @@ void IntegrationPluginSchrack::executeAction(ThingActionInfo *info) if (info->action().actionTypeId() == cionPowerActionTypeId) { qCDebug(dcSchrack()) << "Setting charging enabled:" << (info->action().paramValue(cionPowerActionPowerParamTypeId).toBool() ? 1 : 0); int maxSetPoint = info->thing()->stateValue(cionMaxChargingCurrentStateTypeId).toUInt(); - // If user enables it, we'll write the maxChargingPower value + + // Note: If the wallbox has an RFID reader connected, writing register 100 (chargingEnabled) won't work as the RFID + // reader takes control over it. However, if there's no RFID reader connected, we'll have to set it ourselves. + // So summarizing: + // * In setups with RFID reader, we can only control this with register 101 (maxChargingCurrent) by setting it to 0 + // to stop charging, or something >= 6 to allow charging. + // * In setups without RFID reader, we set 100 to true/false. Note that DIP switches 1 & 2 need to be OFF for register + // 100 to be writable. + if (info->action().paramValue(cionPowerActionPowerParamTypeId).toBool()) { + // In case there's no RFID reader + cionConnection->setChargingEnabled(1); + + // And restore the charging current in case setting the above fails ModbusRtuReply *reply = cionConnection->setChargingCurrentSetpoint(maxSetPoint); waitForActionFinish(info, reply, cionPowerStateTypeId, true); - } else { // we'll write 0 to the max charging power + } else { + // In case there's no RFID reader + cionConnection->setChargingEnabled(0); + + // And set the maxChargingCurrent to 0 in case the above fails ModbusRtuReply *reply = cionConnection->setChargingCurrentSetpoint(0); waitForActionFinish(info, reply, cionPowerStateTypeId, false); } diff --git a/schrack/integrationpluginschrack.h b/schrack/integrationpluginschrack.h index 0a5ba02..0ec6053 100644 --- a/schrack/integrationpluginschrack.h +++ b/schrack/integrationpluginschrack.h @@ -50,6 +50,22 @@ class IntegrationPluginSchrack : public IntegrationPlugin Q_INTERFACES(IntegrationPlugin) public: + enum StatusBit { + StatusBitPluggedIn = 0x0001, + StatusBitChargeContactor1Active = 0x0002, + StatusBitChargeContactor2Active = 0x0004, + StatusBitVentilationRequired = 0x0008, + StatusBitPlugLockController = 0x0010, + StatusBitPlugLockReturn = 0x0020, + StatusBitCollectiveDisorder = 0x0040, + StatusBitDisorderFiLs = 0x0080, + StatusBitCableDisorder = 0x0100, + StatusBitCableRejected = 0x0200, + StatusBitContactorError = 0x0400 + }; + Q_ENUM(StatusBit); + Q_DECLARE_FLAGS(StatusBits, StatusBit) + explicit IntegrationPluginSchrack(); void init() override; void discoverThings(ThingDiscoveryInfo *info) override;