Turning a lamp off after a period of time
Posted: Fri Dec 19, 2003 9:57 am
A common configuration need is to turn a lamp (or any device) off after a specified time out. For example, many times a motion detector will be used to trigger turning a lamp on. The lamp is then to remain on until a specified time has elapsed. If additional motion is detected while the lamp is on, the timeout timer should be reset.
While it would be easy to create a Task that turns the lamp on, waits for a specified time, and then turns the lamp off, it is not the recommended method. Using this method will not allow the timer/delay to be reset if more motion is detected while the timer is running. This is due to the fact that the Task is currently busy waiting and can not be executed again.
A common way to tackle this configuration is by using a Sleep Timer Device and two Tasks. Here’s a step-by-step describing the configuration.
While it would be easy to create a Task that turns the lamp on, waits for a specified time, and then turns the lamp off, it is not the recommended method. Using this method will not allow the timer/delay to be reset if more motion is detected while the timer is running. This is due to the fact that the Task is currently busy waiting and can not be executed again.
A common way to tackle this configuration is by using a Sleep Timer Device and two Tasks. Here’s a step-by-step describing the configuration.
- Create a Sleep Timer Device.
- Enable the Device
- Set the Sleep Time property to the amount of time that the lamp should remain on before switching off.
- Create a Task (Turns the lamp on and starts the timer)
- Enable it Task and set the Execution Mode to “When Conditions Are Met”.
- Add a condition to test for the motion detector. (Any condition can be tested.)
- Add an action to turn on the lamp.
- Add another action to change the value of the Sleep Timer Running Property to Yes.
- Create another Task (Turns the lamp off when the timer has expired)
- Enable it Task and set the Execution Mode to “When Conditions Are Met”.
- Add a condition to test the Sleep Timer Running Property to equal No.
- Add an action to turn the lamp Off.