diff --git a/src/OpenThermTask.h b/src/OpenThermTask.h index b51fa97..1ea18ee 100644 --- a/src/OpenThermTask.h +++ b/src/OpenThermTask.h @@ -254,7 +254,7 @@ protected: // These parameters will be updated every minute if (millis() - this->prevUpdateNonEssentialVars > 60000) { if (!heatingEnabled && settings.opentherm.modulationSyncWithHeating) { - if (setMaxModulationLevel(0)) { + if (this->setMaxModulationLevel(0)) { Log.snoticeln(FPSTR(L_OT_HEATING), F("Set max modulation 0% (off)")); } else { @@ -262,7 +262,7 @@ protected: } } else { - if (setMaxModulationLevel(settings.heating.maxModulation)) { + if (this->setMaxModulationLevel(settings.heating.maxModulation)) { Log.snoticeln(FPSTR(L_OT_HEATING), F("Set max modulation %hhu%%"), settings.heating.maxModulation); } else { @@ -273,7 +273,7 @@ protected: // Get DHW min/max temp (if necessary) if (settings.opentherm.dhwPresent && settings.opentherm.getMinMaxTemp) { - if (updateMinMaxDhwTemp()) { + if (this->updateMinMaxDhwTemp()) { if (settings.dhw.minTemp < vars.parameters.dhwMinTemp) { settings.dhw.minTemp = vars.parameters.dhwMinTemp; fsSettings.update(); @@ -303,7 +303,7 @@ protected: // Get heating min/max temp if (settings.opentherm.getMinMaxTemp) { - if (updateMinMaxHeatingTemp()) { + if (this->updateMinMaxHeatingTemp()) { if (settings.heating.minTemp < vars.parameters.heatingMinTemp) { settings.heating.minTemp = vars.parameters.heatingMinTemp; fsSettings.update(); @@ -330,14 +330,9 @@ protected: fsSettings.update(); } - // Get outdoor temp (if necessary) - if (settings.sensors.outdoor.type == SensorType::BOILER) { - updateOutsideTemp(); - } - // Get fault code (if necessary) if (vars.states.fault) { - updateFaultCode(); + this->updateFaultCode(); } else if (vars.sensors.faultCode != 0) { vars.sensors.faultCode = 0; @@ -345,13 +340,23 @@ protected: // Get diagnostic code (if necessary) if (vars.states.fault || vars.states.diagnostic) { - updateDiagCode(); + this->updateDiagCode(); } else if (vars.sensors.diagnosticCode != 0) { vars.sensors.diagnosticCode = 0; } - updatePressure(); + // If filtering is disabled, then it is enough to + // update these parameters once a minute + if (!settings.opentherm.filterNumValues.enable) { + // Get outdoor temp (if necessary) + if (settings.sensors.outdoor.type == SensorType::BOILER) { + this->updateOutdoorTemp(); + } + + // Get pressure + this->updatePressure(); + } this->prevUpdateNonEssentialVars = millis(); } @@ -359,7 +364,7 @@ protected: // Get current modulation level (if necessary) if (vars.states.flame) { - updateModulationLevel(); + this->updateModulationLevel(); } else { vars.sensors.modulation = 0; @@ -367,8 +372,8 @@ protected: // Update DHW sensors (if necessary) if (settings.opentherm.dhwPresent) { - updateDhwTemp(); - updateDhwFlowRate(); + this->updateDhwTemp(); + this->updateDhwFlowRate(); } else { vars.temperatures.dhw = 0.0f; @@ -376,13 +381,25 @@ protected: } // Get current heating temp - updateHeatingTemp(); + this->updateHeatingTemp(); // Get heating return temp - updateHeatingReturnTemp(); + this->updateHeatingReturnTemp(); // Get exhaust temp - updateExhaustTemp(); + this->updateExhaustTemp(); + + // If filtering is enabled, these parameters + // must be updated every time. + if (settings.opentherm.filterNumValues.enable) { + // Get outdoor temp (if necessary) + if (settings.sensors.outdoor.type == SensorType::BOILER) { + this->updateOutdoorTemp(); + } + + // Get pressure + this->updatePressure(); + } // Fault reset action @@ -795,7 +812,7 @@ protected: return CustomOpenTherm::isValidResponse(response); } - bool updateOutsideTemp() { + bool updateOutdoorTemp() { unsigned long response = this->instance->sendRequest(CustomOpenTherm::buildRequest( OpenThermRequestType::READ_DATA, OpenThermMessageID::Toutside, @@ -812,8 +829,8 @@ protected: settings.system.unitSystem ); - if (settings.opentherm.filteringNumValues && fabs(vars.temperatures.outdoor) >= 0.1f) { - vars.temperatures.outdoor += (value - vars.temperatures.outdoor) * OT_NUM_VALUES_FILTER_K; + if (settings.opentherm.filterNumValues.enable && fabs(vars.temperatures.outdoor) >= 0.1f) { + vars.temperatures.outdoor += (value - vars.temperatures.outdoor) * settings.opentherm.filterNumValues.factor; } else { vars.temperatures.outdoor = value; @@ -844,8 +861,8 @@ protected: settings.system.unitSystem ); - if (settings.opentherm.filteringNumValues && fabs(vars.temperatures.exhaust) >= 0.1f) { - vars.temperatures.exhaust += (value - vars.temperatures.exhaust) * OT_NUM_VALUES_FILTER_K; + if (settings.opentherm.filterNumValues.enable && fabs(vars.temperatures.exhaust) >= 0.1f) { + vars.temperatures.exhaust += (value - vars.temperatures.exhaust) * settings.opentherm.filterNumValues.factor; } else { vars.temperatures.exhaust = value; @@ -876,8 +893,8 @@ protected: settings.system.unitSystem ); - if (settings.opentherm.filteringNumValues && fabs(vars.temperatures.heating) >= 0.1f) { - vars.temperatures.heating += (value - vars.temperatures.heating) * OT_NUM_VALUES_FILTER_K; + if (settings.opentherm.filterNumValues.enable && fabs(vars.temperatures.heating) >= 0.1f) { + vars.temperatures.heating += (value - vars.temperatures.heating) * settings.opentherm.filterNumValues.factor; } else { vars.temperatures.heating = value; @@ -903,8 +920,8 @@ protected: settings.system.unitSystem ); - if (settings.opentherm.filteringNumValues && fabs(vars.temperatures.heatingReturn) >= 0.1f) { - vars.temperatures.heatingReturn += (value - vars.temperatures.heatingReturn) * OT_NUM_VALUES_FILTER_K; + if (settings.opentherm.filterNumValues.enable && fabs(vars.temperatures.heatingReturn) >= 0.1f) { + vars.temperatures.heatingReturn += (value - vars.temperatures.heatingReturn) * settings.opentherm.filterNumValues.factor; } else { vars.temperatures.heatingReturn = value; @@ -937,8 +954,8 @@ protected: settings.system.unitSystem ); - if (settings.opentherm.filteringNumValues && fabs(vars.temperatures.dhw) >= 0.1f) { - vars.temperatures.dhw += (value - vars.temperatures.dhw) * OT_NUM_VALUES_FILTER_K; + if (settings.opentherm.filterNumValues.enable && fabs(vars.temperatures.dhw) >= 0.1f) { + vars.temperatures.dhw += (value - vars.temperatures.dhw) * settings.opentherm.filterNumValues.factor; } else { vars.temperatures.dhw = value; @@ -964,7 +981,7 @@ protected: } value = convertVolume( - value / settings.opentherm.dhwFlowRateMultiplier, + value * settings.opentherm.dhwFlowRateFactor, settings.opentherm.unitSystem, settings.system.unitSystem ); @@ -1018,8 +1035,8 @@ protected: } float value = CustomOpenTherm::getFloat(response); - if (settings.opentherm.filteringNumValues && fabs(vars.sensors.modulation) >= 0.1f) { - vars.sensors.modulation += (value - vars.sensors.modulation) * OT_NUM_VALUES_FILTER_K; + if (settings.opentherm.filterNumValues.enable && fabs(vars.sensors.modulation) >= 0.1f) { + vars.sensors.modulation += (value - vars.sensors.modulation) * settings.opentherm.filterNumValues.factor; } else { vars.sensors.modulation = value; @@ -1045,13 +1062,13 @@ protected: } value = convertPressure( - value / settings.opentherm.pressureMultiplier, + value * settings.opentherm.pressureFactor, settings.opentherm.unitSystem, settings.system.unitSystem ); - if (settings.opentherm.filteringNumValues && fabs(vars.sensors.pressure) >= 0.1f) { - vars.sensors.pressure += (value - vars.sensors.pressure) * OT_NUM_VALUES_FILTER_K; + if (settings.opentherm.filterNumValues.enable && fabs(vars.sensors.pressure) >= 0.1f) { + vars.sensors.pressure += (value - vars.sensors.pressure) * settings.opentherm.filterNumValues.factor; } else { vars.sensors.pressure = value; diff --git a/src/RegulatorTask.h b/src/RegulatorTask.h index ea32b67..5b4d65d 100644 --- a/src/RegulatorTask.h +++ b/src/RegulatorTask.h @@ -139,7 +139,8 @@ protected: // if use pid if (settings.pid.enable) { - if (vars.parameters.heatingEnabled) { + //if (vars.parameters.heatingEnabled) { + if (settings.heating.enable) { float pidResult = getPidTemp( settings.equitherm.enable ? (settings.pid.maxTemp * -1) : settings.pid.minTemp, settings.pid.maxTemp @@ -160,8 +161,8 @@ protected: } } else if (fabs(pidRegulator.integral) > 0.0001f) { - pidRegulator.integral = 0; - Log.sinfoln(FPSTR(L_REGULATOR_PID), F("Integral sum has been reset")); + pidRegulator.integral = 0; + Log.sinfoln(FPSTR(L_REGULATOR_PID), F("Integral sum has been reset")); } // default temp, manual mode @@ -259,7 +260,7 @@ protected: pidRegulator.setLimits(minTemp, maxTemp); pidRegulator.setDt(settings.pid.dt * 1000u); pidRegulator.input = vars.temperatures.indoor; - pidRegulator.setpoint = settings.heating.target; + pidRegulator.setpoint = vars.states.emergency ? settings.emergency.target : settings.heating.target; return pidRegulator.getResultTimer(); } diff --git a/src/Settings.h b/src/Settings.h index 62396be..16bea24 100644 --- a/src/Settings.h +++ b/src/Settings.h @@ -54,8 +54,8 @@ struct Settings { byte faultStateGpio = DEFAULT_OT_FAULT_STATE_GPIO; byte invertFaultState = false; unsigned int memberIdCode = 0; - float pressureMultiplier = 1.0f; - float dhwFlowRateMultiplier = 1.0f; + float pressureFactor = 1.0f; + float dhwFlowRateFactor = 1.0f; bool dhwPresent = true; bool summerWinterMode = false; bool heatingCh2Enabled = true; @@ -66,7 +66,11 @@ struct Settings { bool getMinMaxTemp = true; bool nativeHeatingControl = false; bool immergasFix = false; - bool filteringNumValues = false; + + struct { + bool enable = false; + float factor = 0.1f; + } filterNumValues; } opentherm; struct { diff --git a/src/defines.h b/src/defines.h index 40f37a1..0c8d158 100644 --- a/src/defines.h +++ b/src/defines.h @@ -5,7 +5,6 @@ #define EXT_SENSORS_INTERVAL 5000 #define EXT_SENSORS_FILTER_K 0.15 -#define OT_NUM_VALUES_FILTER_K 0.1 #define CONFIG_URL "http://%s/" #define SETTINGS_VALID_VALUE "stvalid" // only 8 chars! diff --git a/src/utils.h b/src/utils.h index 9dee8f8..9076af6 100644 --- a/src/utils.h +++ b/src/utils.h @@ -345,8 +345,8 @@ void settingsToJson(const Settings& src, JsonVariant dst, bool safe = false) { dst["opentherm"]["faultStateGpio"] = src.opentherm.faultStateGpio; dst["opentherm"]["invertFaultState"] = src.opentherm.invertFaultState; dst["opentherm"]["memberIdCode"] = src.opentherm.memberIdCode; - dst["opentherm"]["pressureMultiplier"] = roundd(src.opentherm.pressureMultiplier, 2); - dst["opentherm"]["dhwFlowRateMultiplier"] = roundd(src.opentherm.dhwFlowRateMultiplier, 2); + dst["opentherm"]["pressureFactor"] = roundd(src.opentherm.pressureFactor, 2); + dst["opentherm"]["dhwFlowRateFactor"] = roundd(src.opentherm.dhwFlowRateFactor, 2); dst["opentherm"]["dhwPresent"] = src.opentherm.dhwPresent; dst["opentherm"]["summerWinterMode"] = src.opentherm.summerWinterMode; dst["opentherm"]["heatingCh2Enabled"] = src.opentherm.heatingCh2Enabled; @@ -357,7 +357,8 @@ void settingsToJson(const Settings& src, JsonVariant dst, bool safe = false) { dst["opentherm"]["getMinMaxTemp"] = src.opentherm.getMinMaxTemp; dst["opentherm"]["nativeHeatingControl"] = src.opentherm.nativeHeatingControl; dst["opentherm"]["immergasFix"] = src.opentherm.immergasFix; - dst["opentherm"]["filteringNumValues"] = src.opentherm.filteringNumValues; + dst["opentherm"]["filterNumValues"]["enable"] = src.opentherm.filterNumValues.enable; + dst["opentherm"]["filterNumValues"]["factor"] = roundd(src.opentherm.filterNumValues.factor, 2); dst["mqtt"]["enable"] = src.mqtt.enable; dst["mqtt"]["server"] = src.mqtt.server; @@ -697,20 +698,38 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false } } - if (!src["opentherm"]["pressureMultiplier"].isNull()) { - float value = src["opentherm"]["pressureMultiplier"].as(); + if (!src["opentherm"]["pressureFactor"].isNull()) { + float value = src["opentherm"]["pressureFactor"].as(); - if (value > 0 && value <= 100 && fabs(value - dst.opentherm.pressureMultiplier) > 0.0001f) { - dst.opentherm.pressureMultiplier = roundd(value, 2); + if (value > 0 && value <= 100 && fabs(value - dst.opentherm.pressureFactor) > 0.0001f) { + dst.opentherm.pressureFactor = roundd(value, 2); changed = true; } } - if (!src["opentherm"]["dhwFlowRateMultiplier"].isNull()) { - float value = src["opentherm"]["dhwFlowRateMultiplier"].as(); + if (!src["opentherm"]["dhwFlowRateFactor"].isNull()) { + float value = src["opentherm"]["dhwFlowRateFactor"].as(); - if (value > 0 && value <= 100 && fabs(value - dst.opentherm.dhwFlowRateMultiplier) > 0.0001f) { - dst.opentherm.dhwFlowRateMultiplier = roundd(value, 2); + if (value > 0 && value <= 100 && fabs(value - dst.opentherm.dhwFlowRateFactor) > 0.0001f) { + dst.opentherm.dhwFlowRateFactor = roundd(value, 2); + changed = true; + } + } + + if (src["opentherm"]["filterNumValues"]["enable"].is()) { + bool value = src["opentherm"]["filterNumValues"]["enable"].as(); + + if (value != dst.opentherm.filterNumValues.enable) { + dst.opentherm.filterNumValues.enable = value; + changed = true; + } + } + + if (!src["opentherm"]["filterNumValues"]["factor"].isNull()) { + float value = src["opentherm"]["filterNumValues"]["factor"].as(); + + if (value > 0 && value <= 1 && fabs(value - dst.opentherm.filterNumValues.factor) > 0.0001f) { + dst.opentherm.filterNumValues.factor = roundd(value, 2); changed = true; } } @@ -831,15 +850,6 @@ bool jsonToSettings(const JsonVariantConst src, Settings& dst, bool safe = false } } - if (src["opentherm"]["filteringNumValues"].is()) { - bool value = src["opentherm"]["filteringNumValues"].as(); - - if (value != dst.opentherm.filteringNumValues) { - dst.opentherm.filteringNumValues = value; - changed = true; - } - } - // mqtt if (src["mqtt"]["enable"].is()) { diff --git a/src_data/locales/en.json b/src_data/locales/en.json index 0f754fe..d96d5a5 100644 --- a/src_data/locales/en.json +++ b/src_data/locales/en.json @@ -261,13 +261,24 @@ "outGpio": "Out GPIO", "ledGpio": "RX LED GPIO", "memberIdCode": "Master MemberID code", - "pressureMultiplier": { + "pressureFactor": { "title": "Coeff. pressure correction", - "note": "If the pressure displayed is X10 from the real one, set the 10." + "note": "If the pressure displayed is X10 from the real one, set the 0.1." }, - "dhwFlowRateMultiplier": { + "dhwFlowRateFactor": { "title": "Coeff. DHW flow rate correction", - "note": "If the DHW flow rate displayed is X10 from the real one, set the 10." + "note": "If the DHW flow rate displayed is X10 from the real one, set the 0.1." + }, + "fnv": { + "title": "Filtering numeric values", + "enable": { + "title": "Enable filtering", + "note": "It can be useful if there is a lot of sharp noise on the charts. The filter used is \"Running Average\"." + }, + "factor": { + "title": "Filtration coeff.", + "note": "The lower the value, the smoother and longer the change in numeric values." + } }, "options": { @@ -279,8 +290,7 @@ "dhwBlocking": "DHW blocking", "modulationSyncWithHeating": "Sync modulation with heating", "getMinMaxTemp": "Get min/max temp from boiler", - "immergasFix": "Fix for Immergas boilers", - "filteringNumValues": "Use filtering for numeric values" + "immergasFix": "Fix for Immergas boilers" }, "faultState": { diff --git a/src_data/locales/ru.json b/src_data/locales/ru.json index ba7a578..6ab08de 100644 --- a/src_data/locales/ru.json +++ b/src_data/locales/ru.json @@ -261,13 +261,24 @@ "outGpio": "Выход GPIO", "ledGpio": "RX LED GPIO", "memberIdCode": "Master MemberID код", - "pressureMultiplier": { + "pressureFactor": { "title": "Коэфф. коррекции давления", - "note": "Если давление отображается Х10 от реального, установите значение 10." + "note": "Если давление отображается Х10 от реального, установите значение 0.1." }, - "dhwFlowRateMultiplier": { + "dhwFlowRateFactor": { "title": "Коэфф. коррекции потока ГВС", - "note": "Если поток ГВС отображается Х10 от реального, установите значение 10." + "note": "Если поток ГВС отображается Х10 от реального, установите значение 0.1." + }, + "fnv": { + "title": "Фильтрация числовых значений", + "enable": { + "title": "Включить фильтрацию", + "note": "Может быть полезно, если на графиках много резкого шума. В качестве фильтра используется \"бегущее среднее\"." + }, + "factor": { + "title": "Коэфф. фильтрации", + "note": "Чем меньше коэф., тем плавнее и дольше изменение числовых значений." + } }, "options": { @@ -279,8 +290,7 @@ "dhwBlocking": "DHW blocking", "modulationSyncWithHeating": "Синхронизировать модуляцию с отоплением", "getMinMaxTemp": "Получать мин. и макс. температуру от котла", - "immergasFix": "Фикс для котлов Immergas", - "filteringNumValues": "Использовать фильтрацию для числовых значений" + "immergasFix": "Фикс для котлов Immergas" }, "faultState": { diff --git a/src_data/pages/settings.html b/src_data/pages/settings.html index 4cb1cd9..d228a7b 100644 --- a/src_data/pages/settings.html +++ b/src_data/pages/settings.html @@ -402,16 +402,16 @@
-
@@ -462,10 +462,25 @@ settings.ot.options.immergasFix - +
+
+ + settings.ot.fnv.title + + + + + +

@@ -751,8 +766,8 @@ setInputValue('#opentherm-fault-state-gpio', data.opentherm.faultStateGpio < 255 ? data.opentherm.faultStateGpio : ''); setCheckboxValue('#opentherm-invert-fault-state', data.opentherm.invertFaultState); setInputValue('#opentherm-member-id-code', data.opentherm.memberIdCode); - setInputValue('#opentherm-pressure-multiplier', data.opentherm.pressureMultiplier); - setInputValue('#opentherm-dhw-fr-multiplier', data.opentherm.dhwFlowRateMultiplier); + setInputValue('#opentherm-pressure-factor', data.opentherm.pressureFactor); + setInputValue('#opentherm-dhw-fr-factor', data.opentherm.dhwFlowRateFactor); setCheckboxValue('#opentherm-dhw-present', data.opentherm.dhwPresent); setCheckboxValue('#opentherm-sw-mode', data.opentherm.summerWinterMode); setCheckboxValue('#opentherm-heating-ch2-enabled', data.opentherm.heatingCh2Enabled); @@ -763,7 +778,8 @@ setCheckboxValue('#opentherm-get-min-max-temp', data.opentherm.getMinMaxTemp); setCheckboxValue('#opentherm-native-heating-control', data.opentherm.nativeHeatingControl); setCheckboxValue('#opentherm-immergas-fix', data.opentherm.immergasFix); - setCheckboxValue('#opentherm-filtering-num-values', data.opentherm.filteringNumValues); + setCheckboxValue('#opentherm-fnv-enable', data.opentherm.filterNumValues.enable); + setInputValue('#opentherm-fnv-factor', data.opentherm.filterNumValues.factor); setBusy('#opentherm-settings-busy', '#opentherm-settings', false); // MQTT