Skip to content

Instantly share code, notes, and snippets.

@vlaminck
Last active December 21, 2015 08:48
Show Gist options
  • Save vlaminck/6280411 to your computer and use it in GitHub Desktop.
Save vlaminck/6280411 to your computer and use it in GitHub Desktop.
/**
* Learning Lights
*
* Author: steve
* Date: 2013-08-20
*/
preferences {
section("Setup") {
input "luminosity", "capability.illuminanceMeasurement", title:"Luminosity Sensor"
input "switches", "capability.switch", title:"Switches to turn on", multiple:true
}
section("Optional") {
input "motion", "capability.motionSensor", title:"Motion Detector", required:false
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
subscribe(app, appTouch)
subscribe(luminosity, "illuminanceMeasurement.illuminance", a)
subscribe(luminosity, "illuminanceMeasurement", b)
subscribe(luminosity, "illuminance", c)
subscribe(motion, "motion.active", motionActiveHandler)
}
def appTouch(evt) {
log.debug "Learn"
on()
negate()
}
def motionActiveHandler(evt) {
log.debug "motion $evt"
on()
negate()
}
def a(evt) {
log.debug "a ${evt}"
}
def b(evt) {
log.debug "b ${evt}"
}
def c(evt) {
log.debug "c ${evt}"
}
def illuminanceHandler(evt) {
log.debug "luminosity $evt"
on()
negate()
}
private on() {
log.debug "on"
}
private negate() {
log.debug "negate"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment