mirror of
https://github.com/Laxilef/OTGateway.git
synced 2025-12-11 02:34:29 +05:00
feature: added settings.pid.dt, editable via mqtt
This commit is contained in:
@@ -585,7 +585,7 @@ public:
|
||||
}
|
||||
|
||||
|
||||
bool publishSwitchPID(bool enabledByDefault = true) {
|
||||
bool publishSwitchPid(bool enabledByDefault = true) {
|
||||
JsonDocument doc;
|
||||
doc[FPSTR(HA_ENABLED_BY_DEFAULT)] = enabledByDefault;
|
||||
doc[FPSTR(HA_UNIQUE_ID)] = this->getObjectId("pid");
|
||||
@@ -606,7 +606,7 @@ public:
|
||||
return this->publish(this->getTopic("switch", "pid").c_str(), doc);
|
||||
}
|
||||
|
||||
bool publishNumberPIDFactorP(bool enabledByDefault = true) {
|
||||
bool publishNumberPidFactorP(bool enabledByDefault = true) {
|
||||
JsonDocument doc;
|
||||
doc[FPSTR(HA_UNIQUE_ID)] = this->getObjectId("pid_p");
|
||||
doc[FPSTR(HA_OBJECT_ID)] = this->getObjectId("pid_p");
|
||||
@@ -627,7 +627,7 @@ public:
|
||||
return this->publish(this->getTopic("number", "pid_p_factor").c_str(), doc);
|
||||
}
|
||||
|
||||
bool publishNumberPIDFactorI(bool enabledByDefault = true) {
|
||||
bool publishNumberPidFactorI(bool enabledByDefault = true) {
|
||||
JsonDocument doc;
|
||||
doc[FPSTR(HA_UNIQUE_ID)] = this->getObjectId("pid_i");
|
||||
doc[FPSTR(HA_OBJECT_ID)] = this->getObjectId("pid_i");
|
||||
@@ -648,7 +648,7 @@ public:
|
||||
return this->publish(this->getTopic("number", "pid_i_factor").c_str(), doc);
|
||||
}
|
||||
|
||||
bool publishNumberPIDFactorD(bool enabledByDefault = true) {
|
||||
bool publishNumberPidFactorD(bool enabledByDefault = true) {
|
||||
JsonDocument doc;
|
||||
doc[FPSTR(HA_UNIQUE_ID)] = this->getObjectId("pid_d");
|
||||
doc[FPSTR(HA_OBJECT_ID)] = this->getObjectId("pid_d");
|
||||
@@ -669,7 +669,28 @@ public:
|
||||
return this->publish(this->getTopic("number", "pid_d_factor").c_str(), doc);
|
||||
}
|
||||
|
||||
bool publishNumberPIDMinTemp(bool enabledByDefault = true) {
|
||||
bool publishNumberPidDt(bool enabledByDefault = true) {
|
||||
JsonDocument doc;
|
||||
doc[FPSTR(HA_UNIQUE_ID)] = this->getObjectId("pid_dt");
|
||||
doc[FPSTR(HA_OBJECT_ID)] = this->getObjectId("pid_dt");
|
||||
doc[FPSTR(HA_ENTITY_CATEGORY)] = F("config");
|
||||
doc[FPSTR(HA_NAME)] = F("PID DT");
|
||||
doc[FPSTR(HA_ICON)] = F("mdi:timer-cog-outline");
|
||||
doc[FPSTR(HA_STATE_TOPIC)] = this->getDeviceTopic("settings");
|
||||
doc[FPSTR(HA_VALUE_TEMPLATE)] = F("{{ value_json.pid.dt|int(0) }}");
|
||||
doc[FPSTR(HA_COMMAND_TOPIC)] = this->getDeviceTopic("settings/set");
|
||||
doc[FPSTR(HA_COMMAND_TEMPLATE)] = F("{\"pid\": {\"dt\" : {{ value }}}}");
|
||||
doc[FPSTR(HA_MIN)] = 30;
|
||||
doc[FPSTR(HA_MAX)] = 600;
|
||||
doc[FPSTR(HA_STEP)] = 1;
|
||||
doc[FPSTR(HA_MODE)] = "box";
|
||||
doc[FPSTR(HA_EXPIRE_AFTER)] = 120;
|
||||
doc.shrinkToFit();
|
||||
|
||||
return this->publish(this->getTopic("number", "pid_dt").c_str(), doc);
|
||||
}
|
||||
|
||||
bool publishNumberPidMinTemp(bool enabledByDefault = true) {
|
||||
JsonDocument doc;
|
||||
doc[FPSTR(HA_ENABLED_BY_DEFAULT)] = enabledByDefault;
|
||||
doc[FPSTR(HA_UNIQUE_ID)] = this->getObjectId("pid_min_temp");
|
||||
@@ -693,7 +714,7 @@ public:
|
||||
return this->publish(this->getTopic("number", "pid_min_temp").c_str(), doc);
|
||||
}
|
||||
|
||||
bool publishNumberPIDMaxTemp(bool enabledByDefault = true) {
|
||||
bool publishNumberPidMaxTemp(bool enabledByDefault = true) {
|
||||
JsonDocument doc;
|
||||
doc[FPSTR(HA_ENABLED_BY_DEFAULT)] = enabledByDefault;
|
||||
doc[FPSTR(HA_UNIQUE_ID)] = this->getObjectId("pid_max_temp");
|
||||
|
||||
@@ -423,6 +423,13 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
if (!doc["pid"]["dt"].isNull() && doc["pid"]["dt"].is<float>()) {
|
||||
if (doc["pid"]["dt"].as<unsigned short>() >= 30 && doc["pid"]["dt"].as<unsigned short>() <= 600) {
|
||||
settings.pid.dt = doc["pid"]["dt"].as<unsigned short>();
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!doc["pid"]["maxTemp"].isNull() && doc["pid"]["maxTemp"].is<unsigned char>()) {
|
||||
if (doc["pid"]["maxTemp"].as<unsigned char>() > 0 && doc["pid"]["maxTemp"].as<unsigned char>() <= 100 && doc["pid"]["maxTemp"].as<unsigned char>() > settings.pid.minTemp) {
|
||||
settings.pid.maxTemp = doc["pid"]["maxTemp"].as<unsigned char>();
|
||||
@@ -598,12 +605,13 @@ protected:
|
||||
this->haHelper->publishNumberHeatingMaxModulation(false);
|
||||
|
||||
// pid
|
||||
this->haHelper->publishSwitchPID();
|
||||
this->haHelper->publishNumberPIDFactorP();
|
||||
this->haHelper->publishNumberPIDFactorI();
|
||||
this->haHelper->publishNumberPIDFactorD();
|
||||
this->haHelper->publishNumberPIDMinTemp(false);
|
||||
this->haHelper->publishNumberPIDMaxTemp(false);
|
||||
this->haHelper->publishSwitchPid();
|
||||
this->haHelper->publishNumberPidFactorP();
|
||||
this->haHelper->publishNumberPidFactorI();
|
||||
this->haHelper->publishNumberPidFactorD();
|
||||
this->haHelper->publishNumberPidDt(false);
|
||||
this->haHelper->publishNumberPidMinTemp(false);
|
||||
this->haHelper->publishNumberPidMaxTemp(false);
|
||||
|
||||
// equitherm
|
||||
this->haHelper->publishSwitchEquitherm();
|
||||
@@ -776,6 +784,7 @@ protected:
|
||||
doc["pid"]["p_factor"] = settings.pid.p_factor;
|
||||
doc["pid"]["i_factor"] = settings.pid.i_factor;
|
||||
doc["pid"]["d_factor"] = settings.pid.d_factor;
|
||||
doc["pid"]["dt"] = settings.pid.dt;
|
||||
doc["pid"]["minTemp"] = settings.pid.minTemp;
|
||||
doc["pid"]["maxTemp"] = settings.pid.maxTemp;
|
||||
|
||||
|
||||
@@ -308,7 +308,7 @@ protected:
|
||||
pidRegulator.Kd = settings.pid.d_factor;
|
||||
|
||||
pidRegulator.setLimits(minTemp, maxTemp);
|
||||
pidRegulator.setDt(180000);
|
||||
pidRegulator.setDt((unsigned long) settings.pid.dt * 1000);
|
||||
pidRegulator.input = vars.temperatures.indoor;
|
||||
pidRegulator.setpoint = settings.heating.target;
|
||||
|
||||
|
||||
@@ -50,9 +50,10 @@ struct Settings {
|
||||
|
||||
struct {
|
||||
bool enable = false;
|
||||
float p_factor = 3;
|
||||
float i_factor = 0.2f;
|
||||
float d_factor = 0;
|
||||
float p_factor = 50;
|
||||
float i_factor = 0.006f;
|
||||
float d_factor = 10000;
|
||||
unsigned short dt = 180;
|
||||
byte minTemp = 0;
|
||||
byte maxTemp = DEFAULT_HEATING_MAX_TEMP;
|
||||
} pid;
|
||||
|
||||
Reference in New Issue
Block a user