Could someone check this rule. It’s causing my light do go on all the time when there’s motion, when its supposed to just work between 10pm-5am.
rule “LateNightMotionLightsOn”
when
Item FoyerMotion changed from CLOSED to OPEN
then
if ((hour >= 22) || (hour <= 5 )) {
counter = counter + 1 {
sendCommand(DenLamp, 15)
sendCommand(LivingRoomLights, 15)
sendCommand(KitchenSinkLight, 15)
}}
end
I do have this command at the top of my file:
var Number hour = now.getHourOfDay
Just to explain why moving the hour var down into the rule worked, your global vars and vals are only evaluated once when the rule is first loaded. So when it is at the top of the file, hour gets set to whatever hour it was when the rules file was loaded and it never changes. When you move it into the rule hour gets reset to the whatever hour it is when the rule executes, which is the behavior you want.
Thanks for the explanation Rich. I just started using OpenHAB a few weeks ago. I’m trying to get it up and fully running to replace my vera home automation device. I appreciate trying to understand
the OpenHAB language instead of just cutting a pasting various rules.