Preamble
I have a light in the kitchen which turns on if someone enters the kitchen, and turns off 5 minutes after there is no movement in the kitchen..
Assumptions
The following details assume that already installed is the Expire binding.
Overview
A virtual item of type ‘switch’ is used as a 5 minute timer. When the time expires, the light is turned off.
Details
- Create a virtual item of type ‘Switch’, whose binding is to send an OFF command to itself when it expires after 5 minutes.
Switch KitchenLightTimer { expire="5m,command=OFF" }
- Create a rule which sets the timer.
- When the Motion Sensor senses movement, it turns on the kitchen light, but also sets the virtual KitchenLightTimer to ON.
- If the Motion Sensor senses movement again before the 5 minutes has expired. it resets the virtual KitchenLightTimer to start timing the 5 minutes again.
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) end
- Create a rule to turn the light off when the virtual KitchenLightTimer expires
rule "Kitchen Light Timer expired" when Item KitchenLightTimer received command OFF then // Timer body Kitchen_Power.sendCommand(OFF) end
Note that I also only turn the light on if it is dark in the kitchen (not shown above). This is explained and elucidated in Time of Day Dependency.