I don’t have time to stay here for longer to read and understand this thread, but I’ve experienced long time ago some thing similar to this.
This is a snippet of code, can you look at it to see if there anything similar to what you’re looking for.
int isTimeInputActivated(const unsigned int scheduleNo, int &lastAction, const TimeInputParam t)
{
int startseconds = (t.getStartHour() * 3600) + (t.getStartMinute() * 60) + t.getStartSecond();
int stopseconds = (t.getStopHour() * 3600) + (t.getStopMinute() * 60) + t.getStopSecond();
//In case of inactive timer
if (startseconds == stopseconds)
return DO_NOTHING;
int retVal = DO_NOTHING;
int nowseconds = ((hour() * 3600) + (minute() * 60) + second());
int blynkWeekDay = weekday();
if(blynkWeekDay == 1)
blynkWeekDay = 7; // needed for Sunday Time library is day 1 and Blynk is day 7
else
blynkWeekDay--;
if (t.isWeekdaySelected(blynkWeekDay))
{
//Time library starts week on Sunday, Blynk on Monday
//Schedule is ACTIVE today
if ((lastAction != TURN_ON) && (nowseconds >= (startseconds - (BLYNK_SCHEDULE_ACCURACY + 1)) && nowseconds <= (startseconds + BLYNK_SCHEDULE_ACCURACY)))
{
#if (DEBUG_BLYNK_RTC > 0)
sprintf(activatedTime, "%s %02d/%02d/%04d", dayOfWeek[weekday()-1], day(), month(), year());
Serial.printf("Schedule %d started at %s on %s\n", scheduleNo, currentTimeAM_PM(currentTime), activatedTime);
#endif
retVal = TURN_ON;
#if (DEBUG_BLYNK_RTC > 1)
Serial.printf("Last Action = %s, Action = %s, Now = %d, startsec = %d, stopsec = %d\n",
lastActionStr[lastAction], lastActionStr[retVal], nowseconds, startseconds, stopseconds);
#endif
}
if ((lastAction != TURN_OFF) && (nowseconds >= (stopseconds - (BLYNK_SCHEDULE_ACCURACY + 1)) && nowseconds <= (stopseconds + BLYNK_SCHEDULE_ACCURACY)))
{
#if (DEBUG_BLYNK_RTC > 0)
sprintf(activatedTime, "%s %02d/%02d/%04d", dayOfWeek[weekday()-1], day(), month(), year());
Serial.printf("Schedule %d stopped at %s on %s\n", scheduleNo, currentTimeAM_PM(currentTime), activatedTime);
#endif
//If both startSeconds and stopSeconds falls in the same 2 * (BLYNK_SCHEDULE_ACCURACY) range, DO_NOTHING
if (retVal == TURN_ON)
retVal = DO_NOTHING;
else
retVal = TURN_OFF;
#if (DEBUG_BLYNK_RTC > 1)
Serial.printf("Last Action = %s, Action = %s, Now = %d, startsec = %d, stopsec = %d\n",
lastActionStr[lastAction], lastActionStr[retVal], nowseconds, startseconds, stopseconds);
#endif
}
if (retVal != DO_NOTHING)
lastAction = retVal;
}
return retVal;
}
If necessary, I’ll put the full code on GitHub later.