Skip to content

Commit

Permalink
Feature: Set/obtain DPL target power consumption via MQTT
Browse files Browse the repository at this point in the history
  • Loading branch information
cerise21 authored Jun 20, 2024
1 parent 95e560b commit ccbaf55
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/MqttHandlePowerLimiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions src/MqttHandlePowerLimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ccbaf55

Please sign in to comment.