mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-28 13:23:07 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* Let There Be Dark!
|
||||
* Turn your lights off when a Contact Sensor is opened and turn them back on when it is closed, ONLY if the Lights were previouly on.
|
||||
*
|
||||
* Author: SmartThings modified by Douglas Rich
|
||||
*/
|
||||
definition(
|
||||
name: "Let There Be Dark!",
|
||||
namespace: "Dooglave",
|
||||
author: "Dooglave",
|
||||
description: "Turn your lights off when a Contact Sensor is opened and turn them back on when it is closed, ONLY if the Lights were previouly on",
|
||||
category: "Convenience",
|
||||
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 the door opens") {
|
||||
input "contact1", "capability.contactSensor", title: "Where?"
|
||||
}
|
||||
section("Turn off a light") {
|
||||
input "switch1", "capability.switch"
|
||||
}
|
||||
}
|
||||
|
||||
def installed() {
|
||||
subscribe(contact1, "contact", contactHandler)
|
||||
subscribe(switch1, "switch.on", switchOnHandler)
|
||||
subscribe(switch1, "switch.off", switchOffHandler)
|
||||
}
|
||||
|
||||
def updated() {
|
||||
unsubscribe()
|
||||
subscribe(contact1, "contact", contactHandler)
|
||||
subscribe(switch1, "switch.on", switchOnHandler)
|
||||
subscribe(switch1, "switch.off", switchOffHandler)
|
||||
}
|
||||
|
||||
def contactHandler(evt) {
|
||||
log.debug "$evt.value"
|
||||
if (evt.value == "open") {
|
||||
state.wasOn = switch1.currentValue("switch") == "on"
|
||||
switch1.off()
|
||||
}
|
||||
|
||||
if (evt.value == "closed") {
|
||||
if(state.wasOn)switch1.on()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user