PREAMBLE
I need to be able to turn on a light in my kitchen if someone enters the room, and it is not light enough. The method for determining and saving whether it is light or dark can be found here. This page describes how to use the switch that stores whether it is light or dark.
OVERVIEW
A switch (vGood_Daylight) is set to ON if it is light enough in the kitchen, and OFF otherwise. If the switch is OFF when a motion sensor detects a person in the room, the light is turned on. After 5′ of non-movement, the light is turned off.
If the switch (vGood_Daylight) is OFF, the kitchen light will not turn on.
ASSUMPTIONS
- The switch vGood_Daylight has been set to ON or OFF depending on the brightness of the day. How this is done can be seen here.
- the Expire binding (which turns the kitchen light off after 5′ of non-movement),
- a configured power plug and motion sensor. [Mine are a TPlink power plug, and a Dlink motion sensor.]
DETAILS
- When the motion sensor detects movement, and only if the vGood_Daylight is OFF, will the light turn ON.
- Note that I still allow the timer to be reset even in good daylight. This allows for the light being turned on manually, or near the cusp points of dusk and dawn.
Create a switch for the smart power plug:
Switch Kitchen_Power "Light"{ channel="tplinksmarthome:hs100:7AE84C:switch" }
Create a switch for the Motion Sensor:
Switch Kitchen_Motion "Motion Sensor" { channel="dlinksmarthome:DCH-S150:3c1e043853d9:motion" }
Create a virtual switch to time the 5′ before the kitchen light is turned off:
Switch KitchenLightTimer { expire="5m,command=OFF" }
The rule also contains an item to store the last time that the kitchen light was on. This is not really necessary.
The following rules are pretty self explanatory. The “Kitchen Light Timer expired” rule relies on the Expire binding which is attached to the KitchenLightTimer item. When the KitchenLightTimer expires, the rule turns the Kitchen Light off.
rule "Start Kitchen Light on movement" when Channel "dlinksmarthome:DCH-S150:3c1e043853d9:motion" triggered then // If there is not good light, then turn the kitchen light on if (vGood_Dayight.state == OFF) { Kitchen_Power.sendCommand(ON) }// cancel Timer
KitchenLightTimer.postUpdate(OFF)
// start Timer
KitchenLightTimer.sendCommand(ON)
// Record time of last sighting
Kitchen_Motion_Last_Motion.postUpdate(new DateTimeType)
end rule "Kitchen Light Timer expired" when Item KitchenLightTimer received command OFF then // Timer body Kitchen_Power.sendCommand(OFF) end