Skip to content

Commit

Permalink
Feature: Set/obtain DPL upper power limit via MQTT
Browse files Browse the repository at this point in the history
  • Loading branch information
cerise21 authored Jun 15, 2024
1 parent 5a007e5 commit 1f6fdb7
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 @@ -23,7 +23,8 @@ class MqttHandlePowerLimiterClass {
VoltageStartThreshold,
VoltageStopThreshold,
FullSolarPassThroughStartVoltage,
FullSolarPassThroughStopVoltage
FullSolarPassThroughStopVoltage,
UpperPowerLimit
};

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 @@ -44,6 +44,7 @@ void MqttHandlePowerLimiterClass::init(Scheduler& scheduler)
subscribe("threshold/voltage/full_solar_passthrough_start", MqttPowerLimiterCommand::FullSolarPassThroughStartVoltage);
subscribe("threshold/voltage/full_solar_passthrough_stop", MqttPowerLimiterCommand::FullSolarPassThroughStopVoltage);
subscribe("mode", MqttPowerLimiterCommand::Mode);
subscribe("upper_power_limit", MqttPowerLimiterCommand::UpperPowerLimit);

_lastPublish = millis();
}
Expand Down Expand Up @@ -75,6 +76,8 @@ void MqttHandlePowerLimiterClass::loop()

auto val = static_cast<unsigned>(PowerLimiter.getMode());
MqttSettings.publish("powerlimiter/status/mode", String(val));

MqttSettings.publish("powerlimiter/status/upper_power_limit", String(config.PowerLimiter.UpperPowerLimit));

MqttSettings.publish("powerlimiter/status/inverter_update_timeouts", String(PowerLimiter.getInverterUpdateTimeouts()));

Expand Down Expand Up @@ -174,6 +177,11 @@ void MqttHandlePowerLimiterClass::onMqttCmd(MqttPowerLimiterCommand command, con
MessageOutput.printf("Setting full solar passthrough stop voltage to: %.2f V\r\n", payload_val);
config.PowerLimiter.FullSolarPassThroughStopVoltage = payload_val;
break;
case MqttPowerLimiterCommand::UpperPowerLimit:
if (config.PowerLimiter.UpperPowerLimit == intValue) { return; }
MessageOutput.printf("Setting upper power limit to: %d W\r\n", intValue);
config.PowerLimiter.UpperPowerLimit = intValue;
break;
}

// not reached if the value did not change
Expand Down

3 comments on commit 1f6fdb7

@ButterBetzi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @cerise21,
I saw this commit/change in the changelog of the newest release and directly wanted to use it.
Should this be automatically discovered by HomeAssistant?
Im not knowledgeable enough regarding the code, but I dont see any UpperPowerLimit in my MQTT devices in HomeAssistant.

@schlimmchen
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ButterBetzi You are correct, we forgot to add the HASS auto-discovery for these new values. Please create a new issue (feature request) so we can track this.

@ButterBetzi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

created a very basic issue: #1178

Please sign in to comment.