From 0de737407f6e7cd87f2686bb080e3744ddb4e3cb Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Wed, 7 Jun 2023 11:15:53 +0200 Subject: [PATCH] Mennekes: Add solarChargingMode state to Compact20s --- mennekes/README.md | 2 +- mennekes/integrationpluginmennekes.cpp | 27 ++++++++++++++++++++++++- mennekes/integrationpluginmennekes.json | 15 ++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/mennekes/README.md b/mennekes/README.md index afb5f94..f84d982 100644 --- a/mennekes/README.md +++ b/mennekes/README.md @@ -18,7 +18,7 @@ nymea uses the Modbus RTU (AMTRON Compact 2.0s) or Modbus TCP (all other models) For the Amtron Charge Control and Premium models, log in to the wallbox's web interface as operator. The login credentials can be obtained from the user manual of the wallbox. Once logged in, navigate to the Load Management tab and set the Modbus TCP Server to On. -For the AMTRON Compact 2.0s, DIP switch 4 and 5 on Bank 51 must be set to ON in order to allow nymea controlling the wallbox. +For the AMTRON Compact 2.0s, DIP switch 4 and 5 on Bank 51 must be set to ON in order to allow nymea controlling the wallbox. With this DIP switch configuration, the solar charging mode will merely control the LED display of the wallbox. ## More diff --git a/mennekes/integrationpluginmennekes.cpp b/mennekes/integrationpluginmennekes.cpp index 2a136a0..7a1a048 100644 --- a/mennekes/integrationpluginmennekes.cpp +++ b/mennekes/integrationpluginmennekes.cpp @@ -37,6 +37,14 @@ #include #include +QHash solarChargingModeMap { + {AmtronCompact20ModbusRtuConnection::SolarChargingModeOff, "Off"}, + {AmtronCompact20ModbusRtuConnection::SolarChargingModeStandard, "Standard"}, + {AmtronCompact20ModbusRtuConnection::SolarChargingModeSunshine, "Sunshine"}, + {AmtronCompact20ModbusRtuConnection::SolarChargingModeSunshinePlus, "Sunshine+"} +}; + + IntegrationPluginMennekes::IntegrationPluginMennekes() { @@ -425,6 +433,18 @@ void IntegrationPluginMennekes::executeAction(ThingActionInfo *info) } }); } + if (info->action().actionTypeId() == amtronCompact20SolarChargingModeActionTypeId) { + QString solarChargingMode = info->action().paramValue(amtronCompact20SolarChargingModeActionSolarChargingModeParamTypeId).toString(); + ModbusRtuReply *reply = amtronCompact20Connection->setSolarChargingMode(solarChargingModeMap.key(solarChargingMode)); + connect(reply, &ModbusRtuReply::finished, info, [info, reply, solarChargingMode](){ + if (reply->error() == ModbusRtuReply::NoError) { + info->thing()->setStateValue(amtronCompact20SolarChargingModeStateTypeId, solarChargingMode); + info->finish(Thing::ThingErrorNoError); + } else { + info->finish(Thing::ThingErrorHardwareFailure); + } + }); + } } } @@ -803,6 +823,7 @@ void IntegrationPluginMennekes::setupAmtronCompact20Connection(ThingSetupInfo *i info->thing()->setStateValue(amtronCompact20CurrentVersionStateTypeId, compact20Connection->firmwareVersion()); info->thing()->setStateValue(amtronCompact20PowerStateTypeId, compact20Connection->chargingReleaseEnergyManager() == 1); info->thing()->setStateValue(amtronCompact20MaxChargingCurrentStateTypeId, qRound(compact20Connection->chargingCurrentEnergyManager())); + info->thing()->setStateValue(amtronCompact20SolarChargingModeStateTypeId, solarChargingModeMap.value(compact20Connection->solarChargingMode())); } }); @@ -914,10 +935,14 @@ void IntegrationPluginMennekes::setupAmtronCompact20Connection(ThingSetupInfo *i thing->setStateValue(amtronCompact20SessionEnergyStateTypeId, chargedEnergySession); }); - connect(compact20Connection, &AmtronCompact20ModbusRtuConnection::chargingReleaseEnergyManagerChanged, this, [thing](quint16 chargingReleaseEnergyManager){ + connect(compact20Connection, &AmtronCompact20ModbusRtuConnection::chargingReleaseEnergyManagerChanged, thing, [thing](quint16 chargingReleaseEnergyManager){ thing->setStateValue(amtronCompact20PowerStateTypeId, chargingReleaseEnergyManager == 1); }); + connect(compact20Connection, &AmtronCompact20ModbusRtuConnection::solarChargingModeChanged, thing, [thing](AmtronCompact20ModbusRtuConnection::SolarChargingMode solarChargingMode){ + thing->setStateValue(amtronCompact20SolarChargingModeStateTypeId, solarChargingModeMap.value(solarChargingMode)); + }); + } bool IntegrationPluginMennekes::ensureAmtronECUVersion(AmtronECUModbusTcpConnection *connection, const QString &version) diff --git a/mennekes/integrationpluginmennekes.json b/mennekes/integrationpluginmennekes.json index 8d164f2..ef7cca8 100644 --- a/mennekes/integrationpluginmennekes.json +++ b/mennekes/integrationpluginmennekes.json @@ -332,6 +332,21 @@ "type": "double", "unit": "KiloWattHour", "defaultValue": 0 + }, + { + "id": "572e45f1-1146-497a-8b00-704e0db50379", + "name": "solarChargingMode", + "displayName": "Solar charging mode", + "displayNameAction": "Set solar charging mode", + "type": "QString", + "possibleValues": [ + "Off", + "Standard", + "Sunshine", + "Sunshine+" + ], + "defaultValue": "Off", + "writable": true } ] }