Created
November 11, 2014 18:31
-
-
Save mrnohr/4e1603d0bfac7619e2e5 to your computer and use it in GitHub Desktop.
SDC Demo 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Turn It On When There Is Motion | |
* | |
* Author: SmartThings | |
*/ | |
definition( | |
name: "D2 - Turn It On Advanced", | |
namespace: "mrnohr", | |
author: "SmartThings", | |
description: "Turn something on when motion is detected.", | |
category: "Convenience", | |
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_contact-outlet.png", | |
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/[email protected]" | |
) | |
preferences { | |
section("When there is motion..."){ | |
input "motion1", "capability.motionSensor", title: "Where?" | |
} | |
section("Turn on a light..."){ | |
input "switches", "capability.switch", multiple: true | |
} | |
} | |
def installed() | |
{ | |
initialize() | |
} | |
def updated() | |
{ | |
unsubscribe() | |
initialize() | |
} | |
def initialize() { | |
subscribe(motion1, "motion.active", motionActiveHandler) | |
} | |
def motionActiveHandler(evt) { | |
log.debug "$evt.value: $evt, $settings" | |
// Schedule this to turn in on 60 seconds | |
log.debug "scheduling for 1 minute" | |
runIn(60, "scheduledDelay") | |
} | |
def scheduledDelay() { | |
log.debug "scheduledDelay" | |
log.debug "sending push" | |
sendPush("Turning on your lights") | |
log.trace "Turning on switches: $switches" | |
switches.on() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment