Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement: expose full solar passsthrough active via MQTT #1136

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/MqttHandlePowerLimiterHass.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class MqttHandlePowerLimiterHassClass {
void publish(const String& subtopic, const String& payload);
void publishNumber(const char* caption, const char* icon, const char* category, const char* commandTopic, const char* stateTopic, const char* unitOfMeasure, const int16_t min, const int16_t max, const float step);
void publishSelect(const char* caption, const char* icon, const char* category, const char* commandTopic, const char* stateTopic);
void publishBinarySensor(const char* caption, const char* icon, const char* stateTopic, const char* payload_on, const char* payload_off);
void createDeviceInfo(JsonDocument& root);

Task _loopTask;
Expand Down
1 change: 1 addition & 0 deletions include/PowerLimiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class PowerLimiterClass {
uint8_t getInverterUpdateTimeouts() const { return _inverterUpdateTimeouts; }
uint8_t getPowerLimiterState();
int32_t getLastRequestedPowerLimit() { return _lastRequestedPowerLimit; }
bool getFullSolarPassThroughEnabled() const { return _fullSolarPassThroughEnabled; }

enum class Mode : unsigned {
Normal = 0,
Expand Down
1 change: 1 addition & 0 deletions src/MqttHandlePowerLimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ void MqttHandlePowerLimiterClass::loop()
MqttSettings.publish("powerlimiter/status/threshold/voltage/stop", String(config.PowerLimiter.VoltageStopThreshold));

if (config.Vedirect.Enabled) {
MqttSettings.publish("powerlimiter/status/full_solar_passthrough_active", String(PowerLimiter.getFullSolarPassThroughEnabled()));
MqttSettings.publish("powerlimiter/status/threshold/voltage/full_solar_passthrough_start", String(config.PowerLimiter.FullSolarPassThroughStartVoltage));
MqttSettings.publish("powerlimiter/status/threshold/voltage/full_solar_passthrough_stop", String(config.PowerLimiter.FullSolarPassThroughStopVoltage));
}
Expand Down
45 changes: 45 additions & 0 deletions src/MqttHandlePowerLimiterHass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ void MqttHandlePowerLimiterHassClass::publishConfig()
"config", "threshold/voltage/stop", "threshold/voltage/stop", "V", 16, 60, 0.1);

if (config.Vedirect.Enabled) {
publishBinarySensor("full solar passthrough active",
"mdi:transmission-tower-import",
"full_solar_passthrough_active", "1", "0");

publishNumber("DPL full solar passthrough start voltage",
"mdi:transmission-tower-import", "config",
"threshold/voltage/full_solar_passthrough_start",
Expand Down Expand Up @@ -187,6 +191,47 @@ void MqttHandlePowerLimiterHassClass::publishNumber(
publish(configTopic, buffer);
}

void MqttHandlePowerLimiterHassClass::publishBinarySensor(
const char* caption, const char* icon,
const char* stateTopic, const char* payload_on, const char* payload_off)
{

String numberId = caption;
numberId.replace(" ", "_");
numberId.toLowerCase();

const String configTopic = "binary_sensor/" + MqttHandleHass.getDtuUniqueId() + "/" + numberId + "/config";

const String statTopic = MqttSettings.getPrefix() + "powerlimiter/status/" + stateTopic;

JsonDocument root;

root["name"] = caption;
root["uniq_id"] = MqttHandleHass.getDtuUniqueId() + "_" + numberId;
if (strcmp(icon, "")) {
root["ic"] = icon;
}
root["stat_t"] = statTopic;
root["pl_on"] = payload_on;
root["pl_off"] = payload_off;

auto const& config = Configuration.get();
if (config.Mqtt.Hass.Expire) {
root["exp_aft"] = config.Mqtt.PublishInterval * 3;
}

createDeviceInfo(root);

if (!Utils::checkJsonAlloc(root, __FUNCTION__, __LINE__)) {
return;
}

String buffer;
serializeJson(root, buffer);
publish(configTopic, buffer);
}


void MqttHandlePowerLimiterHassClass::createDeviceInfo(JsonDocument& root)
{
JsonObject object = root["dev"].to<JsonObject>();
Expand Down
Loading