I want to turn on a light for 5 minutes when motion is detected while it’s dark.
Items:
Switch Presence "Presence" {channel="deconz:presencesensor:36ac81a5:00158d0003059074010406:presence"}
Switch Dark "Dark" {channel="deconz:lightsensor:36ac81a5:00158d0003059074010400:dark"}
Number Brightness "Brightness" {channel="yeelight:stripe:0x0000000007c19a07:color"}
Rule:
var Timer motiontimer = null
rule "Motion sensor triggered"
when
Item Presence changed to ON
then
if (Dark === ON) {
Brightness.sendCommand(75)
motiontimer = createTimer(now.plusMinutes(5)) [|
Brightness.sendCommand(0)]
}
end
The rules file is loaded without any errors:
2019-08-28 23:11:20.939 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'BathroomLight.rules'
Dark is ON:
and Presence changes to ON:
2019-08-28 23:13:52.769 [vent.ItemStateChangedEvent] - Presence changed from ON to OFF
but the rule is not executed. What am I missing here?
if(a == b) --> If a is the same value as b
if(a === b) --> If a is identical to b
a and b are pointers to memory, so if the pointers point to the same memory cell, it will be identical. For example null is a special value (“no value”, to be exact). On the other hand, ON (and OFF, OPEN, CLOSED…) is a state in openHAB. So the === is not correct in this context.