Creating a Schedule (Based on Porch Project by Kris)


(Casey) #1

For reference this is the project i am trying to edit a bit. http://build.smartthings.com/projects/frontdoormotiondetector/

 

I wasn’t sure if posting (I didn’t see forum thread already) or commenting was more appropriate but this seemed better for discussion.  Anyhow my question is how to incorporate a schedule mechanism.

What i would like to do is set my porch to turn on at sunset +user picked variable in minutes from 0 and up.  Then i would like the lights to stay on until 2nd user picked variable (Time to switch to motion control IE Original program).

So to boil it down i want to add 2 time user variables.

a +Sunset  and a Stop Constant on time.

I think this would allow more flexibility in the app and provide security into the night as desired.

 

Below is a sample of my code additions i was working on but I have gotten stumped, still new to Groovy and ST platform.  Any help would be appreciated.  On adding the +time to Kris’s Sunset code, and fixing / adding the on constant until motion mode.

 

 

 

|||||||||||||

//Time Delay to set lights to constant on state after sunset.  Could be Set 0 to whatever in minutes

 

section(“Time Delay After Sunset to Turn on Lights…”){

input “timeondelay”, “time”, title: “Time?”

}

//Time At Which constant state ceases and lights go into Motion Sensor Mode

section(“Time to turn lights Off and switch to motion…”){

input “timeoff”, “time”, title: “Time?”

}

 

|||||||||||||

def nightTime() {

if (light.currentSwitch == “off”){

(checkNighttime()) {

light.on()

}              light.off(time, ${timeoff})

}

 


(Gray) #2

I’m trying to understand the goal here–let me try an example.

 

If I put 0 in for +Sunset, and 120 for the stop constant, then:

At sunset (according to the data pulled), the light turns on.
After two hours, the light switches over to motion sensing mode, so would turn off if there's no motion detected.
After sunset+2 hours, any motion detected would turn on the light, and this would continue until sunset the next day, at which point the light would come on for two solid hours.

Is that correct?


(Casey) #3

Thanks for the reply Gray,

 

The goal would be Enter in an Integer for + Sunset time.  So instead of current program going to motion sensing at sunset it would go to an on state at sunset + Integer (minutes)  Which could be 30 for this example.

So if you enter 30 for the first variable (Really the code above should have read TimeLength, Text, Minutes  instead of Time which is a time picker.)

and 9pm for the 2nd using Time picker the behavior would be as follows.

 

At Sunset + 30 minutes (first user variable) lights turn on, they stay on until 9pm (2nd user variable).  At 9pm lights only turn off and only turn on for XX TimeLength (already a user variable) based on motion detection until Sunrise at which time they turn off and stay off until sunset +UserVariable of the next day.

 


(Casey) #4

I cleaned up my preferences a bit and have this. If someone can look over that I am trying to build the scheduling into that. I haven’t found too much help in the manual (Page 53 and 57). My goal is to have the app turn on lights based on a schedule then switch to motion sensor mode until sunrise. My goal is not just make it work but learn how that process works so i can incorporate similar thinking into automation apps based on simple user set parameters.

What is the best method for pasting code? The code tags just made it white.

preferences { section("When motion is detected by..."){ input "motion", "capability.motionSensor", title: "Motion Here", required: true, multiple: false }

section(“Turn on this light…”) {
input “light”, “capability.switch”, multiple: false, required: true
}
section(“For this many seconds…”) {
input “timelength”, “text”, title: “Seconds?”
}
//Time Delay to set lights to constant on state after sunset. Could be Set 0 to whatever in minutes
section(“After Sunset to Turn on Lights”){
input “timeondelay”, “text”, title: “Minutes?”
}

//Sunset Time
section(“Set Approx Sunset Time”){
input “timeon”, “time”, title: “Time to Turn on?”
}
//Time At Which constant state ceases and lights go into Motion Sensor Mode
section(“Time to turn lights Off and switch to motion”){
input “timeoff”, “time”, title: “Switch to Motion when?”
}

}

def installed()
{
log.debug "Installed with settings: ${settings}"
subscribeToEvents()
}

def updated()
{
log.debug "Updated with settings: ${settings}"
unsubscribe()
subscribeToEvents()
}

def subscribeToEvents()
{
subscribe(motion, “motion.active”, motionDetected)
schedule(timeon, “scheduleCheck”)
schedule(timeoff, “scheduleCheck”)
}

def scheduleCheck()
{
log.debug “This method will be called at ${timeon}”
}


(Dan Lieberman) #5

@caseyknauss - We just pushed a fix to the code tag issue, so now text in a code block can actually be read…