From 3c50b730cf12ee52e91d330ef192e2284d7ff1e7 Mon Sep 17 00:00:00 2001 From: Raymond Date: Tue, 24 May 2016 14:48:59 -0500 Subject: [PATCH] MSA-1294: test --- .../open-on-closed-off.groovy | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 smartapps/vancouver/open-on-closed-off.src/open-on-closed-off.groovy diff --git a/smartapps/vancouver/open-on-closed-off.src/open-on-closed-off.groovy b/smartapps/vancouver/open-on-closed-off.src/open-on-closed-off.groovy new file mode 100644 index 0000000..7d3bf6f --- /dev/null +++ b/smartapps/vancouver/open-on-closed-off.src/open-on-closed-off.groovy @@ -0,0 +1,46 @@ +/** + * Turn on when it opens, off when closed + */ +definition( + name: "Open on Closed off", + namespace: "vancouver", + author: "SmartThings Samsung", + description: "Turn on things when the contact opens and off when it closes", + iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png", + iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png", + iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png") +preferences { + section("When the contact opens..."){ + input "contact1", "capability.contactSensor", title: "Pick a sensor:" + } + section("Pick a Light To Control..."){ + input "colorLights", "capability.colorControl", multiple: true + } +} +def installed() { + log.debug "Installed with settings: ${settings}" + initialize() +} +def updated() { + log.debug "Updated with settings: ${settings}" + unsubscribe() + initialize() +} +def initialize() { + subscribe(contact, "contact.open", contactOpenHandler) + subscribe(contact, "contact.close", contactCloseHandler) + log.info( "contact is currently ->: ${contact1}" ) +} +/** + * contact handler, subscribed for "open" events + */ +def contactOpenHandler(evt) { + colorLights.each { + it.on() + } +} +def contactCloseHandler(evt) { + colorLights.each { + it.off() + } +} \ No newline at end of file