Turn it on for 5 Minutes Help on some customizations

(Justin) #1

Happy Thanksgiving.

I have been tinkering with the ‘Turn it On for 5 minutes app’ to enable a series of hue lights to come on at low dimmer level for 5 minutes when my wemo motion sensor is triggered.

I have all that working but here is the wrinkle. I only want the trigger to occur between 4:30 and 7:00 am.

Here is where I am thus far, but I don’t know how to write the statement to check the time and only activate the trigger where the time within the parameters.

Anyone able to lend a hand… and more importantly explain it?

 *  Turn It On For 5 Minutes
 *  Turn on a switch when a contact sensor opens and then turn it back off 5 minutes later.
 *  Author: SmartThings
    name: "Turn It On For 5 Minutes",
    namespace: "smartthings",
    author: "SmartThings",
    description: "When my closet motion sensor is triggered in between 4:30 and 5:45am, turn on the kitchen accent lights (on low) for 10 minutes.",
    category: "Safety & Security",
    iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_contact-outlet.png",
    iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_contact-outlet@2x.png"

preferences {
	section("When it opens..."){
		input "Motion", "capability.motionSensor"
	section("Turn dimmers on low for 5 minutes..."){
		input "dimmers", "capability.switchLevel", multiple: true, title: "Which Lights?", required: true
        input "level", "number", title: "How bright?, 0-99", required: true
    section("Before this time of day"){
    	input "timeOfDay1", "beforetime", title: "Time?"
    section("After this time of day"){
    	input "timeOfDay2", "aftertime", title: "Time?"

def installed() {
	log.debug "Installed with settings: ${settings}"
	subscribe(Motion, "motion.active", motionActiveHandler)

def updated(settings) {
	log.debug "Updated with settings: ${settings}"
	subscribe(Motion, "motion.inactive", motionInactiveHandler)

def motionActiveHandler(evt) {
  	def tenMinuteDelay = 60 * 10
	runIn(tenMinuteDelay, turnOffSwitch)

def turnOffSwitch() {


(Bruce) #2

If you put the device in Lights & Switches and use “Turn on when there is motion”, that will give you the opportunity to specify that it happen “Only during a certain time”. That’s where you put the 4:30 to 7:00 restriction. No need to put it in the code at all. You could also use “Turn off after a period of time”.

(Acastal) #3

There is also a “Smart Nightlight” ST stock app that supports motion as the trigger and a dimmer as well as a configureable time before turning back off. It also supports the times it should be active.

(Aaron) #4

. . . just ran into this in a search for something else. Looks like 2 good suggestions for how to do this without special code. If you are still interested in trying to do this in the code, let me know. I think I can help.