As a matter of fact, a timer can’t fire twice, but it’s likely that a timer maybe would fire immediately if set to a datetime which has passed right now. (as you calculate the time always with 00 as seconds…)
The difference between != and !== is explained here by @rlkoshak : Trrying to turn a device off after a certain amount of time - #6 by rlkoshak
You do not need to use this, as it should only create a warn in your logs for now, and you should only use it when comparing to null (yes, there is a difference, but it should not interfere here).
I think you should try to simplify the rule. For example:
if(Timer1start!=null)
{
Timer1start.cancel()
Timer1start = null
}
As you set Timer1start (and every other timer) right after killing an old one, there is no need to set the var to null, so you can just use
if (Timer1start !== null) Timer1start.cancel
In question of this part:
if ((Irrigation_Master.state == ON) &&
(((day == 1) && (IrrigationMonday.state == ON)) ||
((day == 2) && (IrrigationTuesday.state == ON)) ||
((day == 3) && (IrrigationWensday.state == ON)) ||
((day == 4) && (IrrigationThursday.state == ON)) ||
((day == 5) && (IrrigationFriday.state == ON)) ||
((day == 6) && (IrrigationSaturday.state == ON)) ||
((day == 7) && (IrrigationSunday.state == ON))))
I would use another rule and an additional item:
Switch IrrigationDo
rule "set IrrigationDo"
when
Time cron "1 0 0 * * ?" or
Item Irrigation_Master changed or
Item IrrigationMonday changed or
Item IrrigationTuesday changed or
Item IrrigationWednesday changed or
Item IrrigationThursday changed or
Item IrrigationFriday changed or
Item IrrigationSaturday changed or
Item IrrigationSunday changed
then
val day = now.getDayOfWeek()
IrrigationDo.postUpdate(
if (Irrigation_Master.state == ON && (
(day == 1 && IrrigationMonday.state == ON) ||
(day == 2 && IrrigationTuesday.state == ON) ||
(day == 3 && IrrigationWensday.state == ON) ||
(day == 4 && IrrigationThursday.state == ON) ||
(day == 5 && IrrigationFriday.state == ON) ||
(day == 6 && IrrigationSaturday.state == ON) ||
(day == 7 && IrrigationSunday.state == ON) ) )
ON else OFF)
end
Keep in mind that you could use a way more elegant way to solve this if using a group and other names for the Irrigation items (Irrigation_1 to Irrigation_7, IrrigationDays would be a group with all Irrigation_n Items as members):
if (Irrigation_Master.state == ON)
IrrigationDays.filter(Day|
Day.name.contains(now.getDayOfWeek.toString)
).first(today|
IrrigationDo.postUpdate(today.state)
)
else
IrrigationDo.postUpdate(OFF)
then you only have to use
if (IrrigationDo.state == ON)
in all timers. Of course you should ensure this rule is executed before the other one (set the Seconds a bit higher)