Barcors:
OK guys I am totally confused. If I have simple values of time from RTC (from 00.00 to 23.59) I expect an option to trigger on something at the specific time and switch it of also at the specific time. And now you are telling me that this is not possible...
No, they are telling you that your code cannot work, and why it will not work. To be more specific, here's why...
(hours >= LightStartHr && minutes >= LightStartMin)
This will be true between 7:30 and 7:59
It will be false between 8:00 and 8:29
It will be true again between 8:30 and 8:59
That pattern will continue until 23:59
(hours <= LightEndHr && minutes < LightEndMin)
This will be true between 0:00 and 0:29
It will be false between 0:30 and 8:59
It will be true again between 1:00 and 1:29
That pattern will continue until 21:59
So, look at the entire statement.
If it's 7:30, the first part will be true, and the second part will be false
so:
true && false gives you false, so your lights will never come on.
Then look at 21:30
The first part will be false and the second part will be true
false && true gives you false, so the lights, if on, will never turn off.
You should make one time variable, and set it to the minutes since midnight, then check to see that your time is during the desired ON time.
int timeSinceMidnight;
int onTime = 450; // 7 * 60 + 30
int offTime = 1290; // 21 * 60 + 30
Then, in loop()
//read the time.
timeSinceMidnight = (hours * 60) + minutes;
if ( (timeSinceMidnight >= onTime) && (timeSinceMidnight < offTime) ) {
//turn lights on
}
else {
//turn lights off
}
This also fits your requirement that the lights come on after the power is restored, if it's during the ON lime.