Skip to content

Commit

Permalink
fix: Make sure limit values sre consistent and not above 100%
Browse files Browse the repository at this point in the history
Ref: #25
  • Loading branch information
mathieucarbou committed Jan 24, 2025
1 parent 7d4d56f commit e99b0cf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
6 changes: 5 additions & 1 deletion lib/Hoymiles/src/parser/SystemConfigParaParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ float SystemConfigParaParser::getLimitPercent() const
HOY_SEMAPHORE_TAKE();
const float ret = ((static_cast<uint16_t>(_payload[2]) << 8) | _payload[3]) / 10.0;
HOY_SEMAPHORE_GIVE();
return ret;

// don't pretend the inverter could produce more than its rated power,
// even though it does process, accept, and even save limit values beyond
// its rated power.
return min<float>(100, ret);
}

void SystemConfigParaParser::setLimitPercent(const float value)
Expand Down
7 changes: 2 additions & 5 deletions src/MqttHandleHass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ void MqttHandleHassClass::publishConfig()
publishInverterButton(inv, "Restart Inverter", "cmd/restart", "1", "", DEVICE_CLS_RESTART, STATE_CLS_NONE, CATEGORY_CONFIG);
publishInverterButton(inv, "Reset Radio Statistics", "cmd/reset_rf_stats", "1", "", DEVICE_CLS_NONE, STATE_CLS_NONE, CATEGORY_CONFIG);

publishInverterNumber(inv, "Limit NonPersistent Relative", "status/limit_relative", "cmd/limit_nonpersistent_relative", 0, 200, 0.1, "%", "mdi:speedometer", STATE_CLS_NONE, CATEGORY_CONFIG);
publishInverterNumber(inv, "Limit Persistent Relative", "status/limit_relative", "cmd/limit_persistent_relative", 0, 200, 0.1, "%", "mdi:speedometer", STATE_CLS_NONE, CATEGORY_CONFIG);
publishInverterNumber(inv, "Limit NonPersistent Relative", "status/limit_relative", "cmd/limit_nonpersistent_relative", 0, 100, 0.1, "%", "mdi:speedometer", STATE_CLS_NONE, CATEGORY_CONFIG);
publishInverterNumber(inv, "Limit Persistent Relative", "status/limit_relative", "cmd/limit_persistent_relative", 0, 100, 0.1, "%", "mdi:speedometer", STATE_CLS_NONE, CATEGORY_CONFIG);

publishInverterNumber(inv, "Limit NonPersistent Absolute", "status/limit_absolute", "cmd/limit_nonpersistent_absolute", 0, MAX_INVERTER_LIMIT, 1, "W", "mdi:speedometer", STATE_CLS_NONE, CATEGORY_CONFIG);
publishInverterNumber(inv, "Limit Persistent Absolute", "status/limit_absolute", "cmd/limit_persistent_absolute", 0, MAX_INVERTER_LIMIT, 1, "W", "mdi:speedometer", STATE_CLS_NONE, CATEGORY_CONFIG);
Expand Down Expand Up @@ -232,9 +232,6 @@ void MqttHandleHassClass::publishInverterNumber(
root["min"] = min;
root["max"] = max;
root["step"] = step;
if (max > 100 && unit_of_measure == "%") {
root["mode"] = "box"; // do not show a slider for possible % going more than 100%
}

publish(configTopic, root);
}
Expand Down

0 comments on commit e99b0cf

Please sign in to comment.