fabfarm/E-SPlash

relay flickering on, off, on, off...

Closed this issue · 1 comments

lpgn commented

When setting more than one schedule in the same zone with one enabled at x time and other not enabled relay turns on and then off rapidly, this is due to the current logic at the function scheduleMode() the loop has no logic to verify that another schedule is set and ends up turning off. @jknight

Bad code
this will cause checks for different schedules to "compete" with each other and turn on and off over top of one another (flicker) :

for each relay
    for each schedule
         if we are within this scheduled time then 
                turn on
         else
              turn off

Good code
instead, we want to check them all first, then make an on/off decision after evaluating all options:

for each relay
   enableRelay = false 
   for each schedule  
       if we are within the scheduled time then
            enableRelay = true
   // done checking all the schedules - do any say we should be on? we only need one ! :)
   if enableRelay then turn on
   else turn off