From ccbaf558087d2c481e148b9f9b1bce125d3ba07c Mon Sep 17 00:00:00 2001 From: cerise21 <40767429+cerise21@users.noreply.github.com> Date: Thu, 20 Jun 2024 13:25:41 +0200 Subject: [PATCH] Feature: Set/obtain DPL target power consumption via MQTT --- include/MqttHandlePowerLimiter.h | 3 ++- src/MqttHandlePowerLimiter.cpp | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/MqttHandlePowerLimiter.h b/include/MqttHandlePowerLimiter.h index fd35b5798..a3e78ab73 100644 --- a/include/MqttHandlePowerLimiter.h +++ b/include/MqttHandlePowerLimiter.h @@ -24,7 +24,8 @@ class MqttHandlePowerLimiterClass { VoltageStopThreshold, FullSolarPassThroughStartVoltage, FullSolarPassThroughStopVoltage, - UpperPowerLimit + UpperPowerLimit, + TargetPowerConsumption }; void onMqttCmd(MqttPowerLimiterCommand command, const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total); diff --git a/src/MqttHandlePowerLimiter.cpp b/src/MqttHandlePowerLimiter.cpp index dd1c96dd3..ab35fff97 100644 --- a/src/MqttHandlePowerLimiter.cpp +++ b/src/MqttHandlePowerLimiter.cpp @@ -45,6 +45,7 @@ void MqttHandlePowerLimiterClass::init(Scheduler& scheduler) subscribe("threshold/voltage/full_solar_passthrough_stop", MqttPowerLimiterCommand::FullSolarPassThroughStopVoltage); subscribe("mode", MqttPowerLimiterCommand::Mode); subscribe("upper_power_limit", MqttPowerLimiterCommand::UpperPowerLimit); + subscribe("target_power_consumption", MqttPowerLimiterCommand::TargetPowerConsumption); _lastPublish = millis(); } @@ -79,6 +80,8 @@ void MqttHandlePowerLimiterClass::loop() MqttSettings.publish("powerlimiter/status/upper_power_limit", String(config.PowerLimiter.UpperPowerLimit)); + MqttSettings.publish("powerlimiter/status/target_power_consumption", String(config.PowerLimiter.TargetPowerConsumption)); + MqttSettings.publish("powerlimiter/status/inverter_update_timeouts", String(PowerLimiter.getInverterUpdateTimeouts())); // no thresholds are relevant for setups without a battery @@ -182,6 +185,11 @@ void MqttHandlePowerLimiterClass::onMqttCmd(MqttPowerLimiterCommand command, con MessageOutput.printf("Setting upper power limit to: %d W\r\n", intValue); config.PowerLimiter.UpperPowerLimit = intValue; break; + case MqttPowerLimiterCommand::TargetPowerConsumption: + if (config.PowerLimiter.TargetPowerConsumption == intValue) { return; } + MessageOutput.printf("Setting target power consumption to: %d W\r\n", intValue); + config.PowerLimiter.TargetPowerConsumption = intValue; + break; } // not reached if the value did not change