I have created a rule to turn on my outside light when the side door of my garage is opened and stay on for 10 minutes. I only want this to occur between certain hours such as 5pm and 7am.
This is the current version of my rule but it doesn’t seem to be functioning correctly.
//Turn on Outside Light for 10 mins when Access Door is opened
rule "Outside Light Auto On/Off Access Door"
when
Item GarageAccessDoorStatus received update OPEN
then
if ((hour <=7) || (hour >= 17))
Sonoffth16.sendCommand(ON)
timer = createTimer(now.plusMinutes(10)) [|
Sonoffth16.sendCommand(OFF)
timer = null
]
end
In that case, the variable hour will only be evaluated once the rules file gets parsed, so you should put the variable inside the rule to make it work.
if ((hour <=7) || (hour >= 17))
{
Sonoffth16.sendCommand(ON)
timer = createTimer(now.plusMinutes(10)) [|
Sonoffth16.sendCommand(OFF)
timer = null
]
}
I think the syntax of if was used wrong. If no {} are used only the first line after the if is in the if.
In your version the timer is running even if the time is out of range if the if clause.