From 70019075c2c6a1229bd86dc7788ce238757492cf Mon Sep 17 00:00:00 2001 From: JANG JAEWON Date: Thu, 2 Feb 2017 09:45:47 -0800 Subject: [PATCH] MSA-1759: To use a motion sensor light only when the place is dark, normally we need an additional luminosity sensor. This app activate motion sensor and light when designated lights are off. --- .../smart-motion-light.groovy | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 smartapps/ipse/smart-motion-light.src/smart-motion-light.groovy diff --git a/smartapps/ipse/smart-motion-light.src/smart-motion-light.groovy b/smartapps/ipse/smart-motion-light.src/smart-motion-light.groovy new file mode 100644 index 0000000..1cd81b5 --- /dev/null +++ b/smartapps/ipse/smart-motion-light.src/smart-motion-light.groovy @@ -0,0 +1,61 @@ +/** + * Smart Motion Light + * + * Copyright 2017 JANG JAEWON + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License + * for the specific language governing permissions and limitations under the License. + * + */ +definition( + name: "Smart Motion Light", + namespace: "ipse", + author: "JANG JAEWON", + description: "Activate motion sensor light only when specific lights are off. Light turns off in 1 minute.", + category: "Convenience", + 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 ("Where") { + input "motion1", "capability.motionSensor", title: "Which Motion Sensor?",required:true + } + section ("When these lights are off...") { + input "darkSwitches", "capability.switch", title: "Which?",required:true,multiple:true + } + section ("Turn on this light...") { + input "onSwitch", "capability.switch", title: "Which?",required:true + } +} + +def installed() +{ + subscribe(motion1, "motion.active", motionActiveHandler) +} + +def updated() +{ + unsubscribe() + subscribe(motion1, "motion.active", motionActiveHandler) +} + +def motionActiveHandler(evt) { + def currSwitches = darkSwitches.currentSwitch + def countSwitches = currSwitches.findAll{it == "off"?true:false} + if (darkSwitches.size() == countSwitches.size()) { + onSwitch.on() + runIn(60,turnOff) + } +} + +def turnOff(){ + onSwitch.off() +} \ No newline at end of file