diff --git a/esp32/include/HomieTypes.h b/esp32/include/HomieTypes.h index f3d5cc9..d39cd3b 100644 --- a/esp32/include/HomieTypes.h +++ b/esp32/include/HomieTypes.h @@ -45,6 +45,8 @@ static const char *SENSOR_STRING[] = { #define MISSING_SENSOR -2 //plant uses only cooldown and duration, moisture is measured but ignored, allowedHours is ignored (eg. make a 30min on 30min off cycle) #define HYDROPONIC_MODE -3 +//plant uses cooldown and duration and workhours, moisture is measured but ignored +#define TIMER_ONLY -4 typedef struct PlantSettings_t { diff --git a/esp32/include/PlantCtrl.h b/esp32/include/PlantCtrl.h index ed211e4..332b1a7 100644 --- a/esp32/include/PlantCtrl.h +++ b/esp32/include/PlantCtrl.h @@ -75,6 +75,12 @@ public: return SENSOR_STRING[mode]; } + bool isTimerOnly() + { + long current = this->mSetting->pSensorDry->get(); + return equalish(current, TIMER_ONLY); + } + bool isHydroponic() { long current = this->mSetting->pSensorDry->get(); @@ -94,7 +100,7 @@ public: */ bool isPumpRequired() { - if (isHydroponic()) + if (isHydroponic() || isTimerOnly()) { // hydroponic only uses timer based controll return true; diff --git a/esp32/platformio.ini b/esp32/platformio.ini index 060c0c3..eaa7c40 100644 --- a/esp32/platformio.ini +++ b/esp32/platformio.ini @@ -15,11 +15,11 @@ framework = arduino build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY -DPLANT0_SENSORTYPE=ANALOG_RESISTANCE_PROBE -DPLANT1_SENSORTYPE=ANALOG_RESISTANCE_PROBE - -DPLANT2_SENSORTYPE=CAPACITIVE_FREQUENCY - -DPLANT3_SENSORTYPE=CAPACITIVE_FREQUENCY - -DPLANT4_SENSORTYPE=CAPACITIVE_FREQUENCY - -DPLANT5_SENSORTYPE=CAPACITIVE_FREQUENCY - -DPLANT6_SENSORTYPE=CAPACITIVE_FREQUENCY + -DPLANT2_SENSORTYPE=ANALOG_RESISTANCE_PROBE + -DPLANT3_SENSORTYPE=ANALOG_RESISTANCE_PROBE + -DPLANT4_SENSORTYPE=ANALOG_RESISTANCE_PROBE + -DPLANT5_SENSORTYPE=ANALOG_RESISTANCE_PROBE + -DPLANT6_SENSORTYPE=ANALOG_RESISTANCE_PROBE board_build.partitions = defaultWithSmallerSpiffs.csv diff --git a/esp32/src/PlantCtrl.cpp b/esp32/src/PlantCtrl.cpp index cf33de6..246d880 100644 --- a/esp32/src/PlantCtrl.cpp +++ b/esp32/src/PlantCtrl.cpp @@ -31,7 +31,7 @@ void Plant::init(void) /* Initialize Home Settings validator */ this->mSetting->pSensorDry->setDefaultValue(DEACTIVATED_PLANT); this->mSetting->pSensorDry->setValidator([](long candidate) - { return (((candidate >= 0.0) && (candidate <= 100.0)) || equalish(candidate, DEACTIVATED_PLANT) || equalish(candidate, HYDROPONIC_MODE)); }); + { return (((candidate >= 0.0) && (candidate <= 100.0)) || equalish(candidate, DEACTIVATED_PLANT) || equalish(candidate, HYDROPONIC_MODE) || equalish(candidate, TIMER_ONLY)); }); this->mSetting->pPumpAllowedHourRangeStart->setDefaultValue(8); // start at 8:00 this->mSetting->pPumpAllowedHourRangeStart->setValidator([](long candidate) diff --git a/esp32/src/main.cpp b/esp32/src/main.cpp index 5dfc947..369cbc5 100644 --- a/esp32/src/main.cpp +++ b/esp32/src/main.cpp @@ -460,7 +460,7 @@ int determineNextPump(bool isLowLight) log(LOG_LEVEL_DEBUG, String(String(i) + " No pump required: due to light"), LOG_DEBUG_CODE); continue; } - if (!plant.isHydroponic()) + if (! (plant.isHydroponic() || plant.isTimerOnly())) { if (equalish(plant.getCurrentMoistureRaw(), MISSING_SENSOR)) { @@ -497,7 +497,7 @@ int determineNextPump(bool isLowLight) } } - if (!plant.isHydroponic()) + if (! (plant.isHydroponic() || plant.isTimerOnly())) { consecutiveWateringPlant[i]++; } @@ -1137,9 +1137,11 @@ bool determineTimedLightState(bool lowLight) } int curHour = getCurrentHour(); + bool condition1 = ((hoursStart > hoursEnd) && (curHour >= hoursStart || curHour <= hoursEnd)); bool condition2 = /* Handle e.g. start = 8, end = 21 */ + ((hoursStart < hoursEnd) && (curHour >= hoursStart && curHour <= hoursEnd)); timedLightNode.setProperty("debug").send(String(curHour) + " " + String(hoursStart) + " " + String(hoursEnd) + " " + String(condition1) + " " + String(condition2));