-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Migrate from microDS18B20 to DallasTemperature 2. Refactoring of sensors: added an external temperature sensor inside the house, added an "offset" parameter for sensors 3. Fixed PID 4. New parameters added: - settings.heating.minTemp - settings.heating.maxTemp - settings.dhw.minTemp - settings.dhw.maxTemp - settings.pid.minTemp - settings.pid.maxTemp - settings.sensors.outdoor.type - settings.sensors.outdoor.pin - settings.sensors.outdoor.offset - settings.sensors.indoor.type - settings.sensors.indoor.pin - settings.sensors.indoor.offset 5. Fixed and updated HomeAssistantHelper 7. Added check for validity of settings. After some updates, the settings may be reset to default, but this will prevent the settings from being distorted.
- Loading branch information
Showing
12 changed files
with
913 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,149 @@ | ||
#include <microDS18B20.h> | ||
|
||
MicroDS18B20<DS18B20_PIN> outdoorSensor; | ||
#include <OneWire.h> | ||
#include <DallasTemperature.h> | ||
|
||
class SensorsTask: public LeanTask { | ||
public: | ||
SensorsTask(bool _enabled = false, unsigned long _interval = 0): LeanTask(_enabled, _interval) {} | ||
|
||
protected: | ||
OneWire* oneWireOutdoorSensor; | ||
OneWire* oneWireIndoorSensor; | ||
|
||
DallasTemperature* outdoorSensor; | ||
DallasTemperature* indoorSensor; | ||
|
||
bool initOutdoorSensor = false; | ||
unsigned long startConversionTime = 0; | ||
float filteredOutdoorTemp = 0; | ||
bool emptyOutdoorTemp = true; | ||
void setup() {} | ||
|
||
bool initIndoorSensor = false; | ||
float filteredIndoorTemp = 0; | ||
bool emptyIndoorTemp = true; | ||
|
||
|
||
void setup() {} | ||
void loop() { | ||
// DS18B20 sensor | ||
if (outdoorSensor.online()) { | ||
if (outdoorSensor.readTemp()) { | ||
float rawTemp = outdoorSensor.getTemp(); | ||
DEBUG_F("[SENSORS][DS18B20] Raw temp: %f \n", rawTemp); | ||
if ( settings.sensors.outdoor.type == 2 ) { | ||
outdoorTemperatureSensor(); | ||
} | ||
|
||
if ( settings.sensors.indoor.type == 2 ) { | ||
indoorTemperatureSensor(); | ||
} | ||
} | ||
|
||
if (emptyOutdoorTemp) { | ||
filteredOutdoorTemp = rawTemp; | ||
emptyOutdoorTemp = false; | ||
void outdoorTemperatureSensor() { | ||
if ( !initOutdoorSensor ) { | ||
oneWireOutdoorSensor = new OneWire(settings.sensors.outdoor.pin); | ||
outdoorSensor = new DallasTemperature(oneWireOutdoorSensor); | ||
outdoorSensor->begin(); | ||
outdoorSensor->setResolution(12); | ||
outdoorSensor->setWaitForConversion(false); | ||
outdoorSensor->requestTemperatures(); | ||
startConversionTime = millis(); | ||
initOutdoorSensor = true; | ||
} | ||
|
||
unsigned long estimateConversionTime = millis() - startConversionTime; | ||
if ( estimateConversionTime < outdoorSensor->millisToWaitForConversion() ) { | ||
return; | ||
} | ||
|
||
} else { | ||
filteredOutdoorTemp += (rawTemp - filteredOutdoorTemp) * OUTDOOR_SENSOR_FILTER_K; | ||
} | ||
bool completed = outdoorSensor->isConversionComplete(); | ||
if ( !completed && estimateConversionTime >= 1000 ) { | ||
// fail, retry | ||
outdoorSensor->requestTemperatures(); | ||
startConversionTime = millis(); | ||
|
||
filteredOutdoorTemp = floor(filteredOutdoorTemp * 100) / 100; | ||
ERROR("[SENSORS][OUTDOOR] Could not read temperature data (no response)"); | ||
} | ||
|
||
if ( !completed ) { | ||
return; | ||
} | ||
|
||
if (fabs(vars.temperatures.outdoor - filteredOutdoorTemp) > 0.099) { | ||
vars.temperatures.outdoor = filteredOutdoorTemp; | ||
INFO_F("[SENSORS][DS18B20] New temp: %f \n", filteredOutdoorTemp); | ||
} | ||
float rawTemp = outdoorSensor->getTempCByIndex(0); | ||
if (rawTemp == DEVICE_DISCONNECTED_C) { | ||
ERROR("[SENSORS][OUTDOOR] Could not read temperature data (not connected)"); | ||
|
||
} else { | ||
DEBUG_F("[SENSORS][OUTDOOR] Raw temp: %f \n", rawTemp); | ||
|
||
if (emptyOutdoorTemp) { | ||
filteredOutdoorTemp = rawTemp; | ||
emptyOutdoorTemp = false; | ||
|
||
} else { | ||
ERROR("[SENSORS][DS18B20] Invalid data from sensor"); | ||
filteredOutdoorTemp += (rawTemp - filteredOutdoorTemp) * EXT_SENSORS_FILTER_K; | ||
} | ||
|
||
filteredOutdoorTemp = floor(filteredOutdoorTemp * 100) / 100; | ||
|
||
if (fabs(vars.temperatures.outdoor - filteredOutdoorTemp) > 0.099) { | ||
vars.temperatures.outdoor = filteredOutdoorTemp + settings.sensors.outdoor.offset; | ||
INFO_F("[SENSORS][OUTDOOR] New temp: %f \n", filteredOutdoorTemp); | ||
} | ||
} | ||
|
||
outdoorSensor->requestTemperatures(); | ||
startConversionTime = millis(); | ||
} | ||
|
||
void indoorTemperatureSensor() { | ||
if ( !initIndoorSensor ) { | ||
oneWireIndoorSensor = new OneWire(settings.sensors.indoor.pin); | ||
indoorSensor = new DallasTemperature(oneWireIndoorSensor); | ||
indoorSensor->begin(); | ||
indoorSensor->setResolution(12); | ||
indoorSensor->setWaitForConversion(false); | ||
indoorSensor->requestTemperatures(); | ||
startConversionTime = millis(); | ||
initIndoorSensor = true; | ||
} | ||
|
||
unsigned long estimateConversionTime = millis() - startConversionTime; | ||
if ( estimateConversionTime < indoorSensor->millisToWaitForConversion() ) { | ||
return; | ||
} | ||
|
||
bool completed = indoorSensor->isConversionComplete(); | ||
if ( !completed && estimateConversionTime >= 1000 ) { | ||
// fail, retry | ||
indoorSensor->requestTemperatures(); | ||
startConversionTime = millis(); | ||
|
||
ERROR("[SENSORS][INDOOR] Could not read temperature data (no response)"); | ||
} | ||
|
||
if ( !completed ) { | ||
return; | ||
} | ||
|
||
float rawTemp = indoorSensor->getTempCByIndex(0); | ||
if (rawTemp == DEVICE_DISCONNECTED_C) { | ||
ERROR("[SENSORS][INDOOR] Could not read temperature data (not connected)"); | ||
|
||
outdoorSensor.requestTemp(); | ||
} else { | ||
ERROR("[SENSORS][DS18B20] Failed to connect to sensor"); | ||
DEBUG_F("[SENSORS][INDOOR] Raw temp: %f \n", rawTemp); | ||
|
||
if (emptyIndoorTemp) { | ||
filteredIndoorTemp = rawTemp; | ||
emptyIndoorTemp = false; | ||
|
||
} else { | ||
filteredIndoorTemp += (rawTemp - filteredIndoorTemp) * EXT_SENSORS_FILTER_K; | ||
} | ||
|
||
filteredIndoorTemp = floor(filteredIndoorTemp * 100) / 100; | ||
|
||
if (fabs(vars.temperatures.indoor - filteredIndoorTemp) > 0.099) { | ||
vars.temperatures.indoor = filteredIndoorTemp + settings.sensors.indoor.offset; | ||
INFO_F("[SENSORS][INDOOR] New temp: %f \n", filteredIndoorTemp); | ||
} | ||
} | ||
|
||
indoorSensor->requestTemperatures(); | ||
startConversionTime = millis(); | ||
} | ||
}; |
Oops, something went wrong.