Hi,
I have been using OH for a while (since OH 2.x) and up until now I have found all answers to my questions in this community without the need to register.
Until now…
I have installed a Philips Hue Motion Sensor which I want to use, to trigger my kitchen lights.
I could of course, just use the Hue app, but I want to use OH for (almost) everything.
What do I want to achieve ?
I want the motion sensor to trigger a rule (this is easy).
What should this rule do ?
The rule needs to check
a) if group gPresence is ON (easy)
b) if the illuminance (reported by the motion sensor) is below a certain value (kind of easy)
- if a) and b) are true, I want to switch on my lights and leave them on for 120s.
If within these 120s the motion sensor triggers again, I want the lights to stay on and the timer re-run.
This is my rule
var Timer KitchenTimer = null
var Number HUE_LIGHT_LVL_LIMIT = 18|" lx"
rule "HUE - KITCHEN: LIGHTS ON WHEN DETECTION IS REGISTERED"
when
Item HUE_KITCHEN_MD received update ON
then
var corLightLevel = (HUE_KITCHEN_MD_LIGHT_LVL.state as Number).floatValue - (HUE_LIGHT_LVL_LIMIT as Number).floatValue
logInfo("hue.rules","MOTION DETECTED ; CORRECTED LIGHT LEVEL " +corLightLevel.toString+"lx")
if (gPresence.state == ON)
{
if (corLightLevel < 1 )
{
if (KitchenTimer === null || KitchenTimer.hasTerminated())
{
gHUE_KITCHEN.sendCommand(ON)
logInfo("hue.rules","KITCHEN: MOTION DETECTED - LIGHTS ON")
KitchenTimer = createTimer(now.plusSeconds(120), [|
gHUE_KITCHEN.sendCommand(OFF)
logInfo("hue.rules","SWITCHING KITCHEN LIGHTS OFF")
//KitchenTimer = null
])
}
else
{
logInfo("hue.rules","RESCHEDULING KITCHEN LIGHT TIMEOUT")
KitchenTimer.reschedule(now.plusSeconds(120))
}
}
}
end
The reason for the “corLightLevel” is: the kitchen lights themselves can illuminate the sensor too much, so the rule does not trigger (as OH4 assumes its too bright already).
If anyone can think of an easier/simpler/better way to solve this, please feel free to comment.
The rescheduling seems not to work.
I think has something to do with my timer, but I cannot for the life of me figure out what’s wrong.
If I
KitchenTimer = null
as last part of my timer, the else-branch of my IF-check will never be reached.
Can anybody help me / point me in the right direction, as it is annoying to be standing in the dark.
Thanks