Handle cooldown time for watering; add start and end time when pumping is allowed

This commit is contained in:
Ollo
2021-04-07 21:26:11 +02:00
parent 3932e82593
commit 47aba5387b
3 changed files with 52 additions and 33 deletions

View File

@@ -91,7 +91,7 @@ HomieSetting<const char *> ntpServer("ntpServer", "NTP server (pool.ntp.org as d
HomieSetting<long> mSensorDry##plant = HomieSetting<long>("moistdry" strplant, "Plant " strplant "- Moist sensor dry threshold"); \
HomieSetting<long> mPumpAllowedHourRangeStart##plant = HomieSetting<long>("rangehourstart" strplant, "Plant" strplant " - Range pump allowed hour start (0-23)"); \
HomieSetting<long> mPumpAllowedHourRangeEnd##plant = HomieSetting<long>("rangehourend" strplant, "Plant" strplant " - Range pump allowed hour end (0-23)"); \
HomieSetting<bool> mPumpOnlyWhenLowLight##plant = HomieSetting<bool>("onlyWhenLowLightZ" strplant, "Plant" strplant " - Enable the Pump only, when there is light but not enought to charge battery"); \
HomieSetting<bool> mPumpOnlyWhenLowLight##plant = HomieSetting<bool>("onlyWhenLowLightZ" strplant, "Plant" strplant " - Enable the Pump only, when there is no sunlight"); \
HomieSetting<long> mPumpCooldownInHours##plant = HomieSetting<long>("cooldownpump" strplant, "Plant" strplant " - How long to wait until the pump is activated again (minutes)"); \
PlantSettings_t mSetting##plant = {&mSensorDry##plant, &mPumpAllowedHourRangeStart##plant, &mPumpAllowedHourRangeEnd##plant, &mPumpOnlyWhenLowLight##plant, &mPumpCooldownInHours##plant}; \
/**< Generate all settings for one plant \

View File

@@ -98,23 +98,26 @@ public:
void init(void);
/** @fn bool isInCooldown(long sinceLastActivation)
* @brief determine, if the plant was recently casted
* @param sinceLastActivation timestamp of last time
*/
bool isInCooldown(long sinceLastActivation)
{
/* if the time difference is greater than one month, we know these are initial values */
if (sinceLastActivation > (60 * 60 * 24 * 30))
{
return false;
}
return (getCooldownInSeconds() > sinceLastActivation);
long getCooldownInSeconds() {
return this->mSetting->pPumpCooldownInHours->get()*60*60;
}
long getCooldownInSeconds(){
return this->mSetting->pPumpCooldownInHours->get()*60*60;
/**
* @brief Get the Hours when pumping should start
*
* @return hour
*/
int getHoursStart() {
return this->mSetting->pPumpAllowedHourRangeStart->get();
}
/**
* @brief Get the Hours when pumping should end
*
* @return hour
*/
int getHoursEnd() {
return this->mSetting->pPumpAllowedHourRangeEnd->get();
}
bool isAllowedOnlyAtLowLight(void)