2 * Copyright 2015 SmartThings
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
10 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
11 * for the specific language governing permissions and limitations under the License.
19 name: "Notify Me With Hue",
20 namespace: "smartthings",
21 author: "SmartThings",
22 description: "Changes the color and brightness of Philips Hue bulbs when any of a variety of SmartThings is activated. Supports motion, contact, acceleration, moisture and presence sensors as well as switches.",
23 category: "SmartThings Labs",
24 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/hue.png",
25 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/hue@2x.png"
30 section("Control these bulbs...") {
31 input "hues", "capability.colorControl", title: "Which Hue Bulbs?", required:true, multiple:true
34 section("Choose one or more, when..."){
35 input "motion", "capability.motionSensor", title: "Motion Here", required: false, multiple: true
36 input "contact", "capability.contactSensor", title: "Contact Opens", required: false, multiple: true
37 input "contactClosed", "capability.contactSensor", title: "Contact Closes", required: false, multiple: true
38 input "acceleration", "capability.accelerationSensor", title: "Acceleration Detected", required: false, multiple: true
39 input "mySwitch", "capability.switch", title: "Switch Turned On", required: false, multiple: true
40 input "mySwitchOff", "capability.switch", title: "Switch Turned Off", required: false, multiple: true
41 input "arrivalPresence", "capability.presenceSensor", title: "Arrival Of", required: false, multiple: true
42 input "departurePresence", "capability.presenceSensor", title: "Departure Of", required: false, multiple: true
43 input "smoke", "capability.smokeDetector", title: "Smoke Detected", required: false, multiple: true
44 input "water", "capability.waterSensor", title: "Water Sensor Wet", required: false, multiple: true
45 input "button1", "capability.button", title: "Button Press", required:false, multiple:true //remove from production
46 input "triggerModes", "mode", title: "System Changes Mode", description: "Select mode(s)", required: false, multiple: true
47 input "timeOfDay", "time", title: "At a Scheduled Time", required: false
50 section("Choose light effects...")
52 input "color", "enum", title: "Hue Color?", required: false, multiple:false, options: ["Red","Green","Blue","Yellow","Orange","Purple","Pink"]
53 input "lightLevel", "enum", title: "Light Level?", required: false, options: [10,20,30,40,50,60,70,80,90,100]
54 input "duration", "number", title: "Duration Seconds?", required: false
55 //input "turnOn", "enum", title: "Turn On when Off?", required: false, options: ["Yes","No"]
58 section("Minimum time between messages (optional, defaults to every message)") {
59 input "frequency", "decimal", title: "Minutes", required: false
64 log.debug "Installed with settings: ${settings}"
66 // Initialize input value
71 log.debug "Updated with settings: ${settings}"
77 def subscribeToEvents() {
78 subscribe(app, appTouchHandler)
79 subscribe(contact, "contact.open", eventHandler1)
80 subscribe(contactClosed, "contact.closed", eventHandler1)
81 subscribe(acceleration, "acceleration.active", eventHandler1)
82 subscribe(motion, "motion.active", eventHandler1)
83 subscribe(mySwitch, "switch.on", eventHandler1)
84 subscribe(mySwitchOff, "switch.off", eventHandler1)
85 subscribe(arrivalPresence, "presence.present", eventHandler1)
86 subscribe(departurePresence, "presence.not present", eventHandler1)
87 subscribe(smoke, "smoke.detected", eventHandler1)
88 subscribe(smoke, "smoke.tested", eventHandler1)
89 subscribe(smoke, "carbonMonoxide.detected", eventHandler1)
90 subscribe(water, "water.wet", eventHandler1)
91 subscribe(button1, "button.pushed", eventHandler1)
94 subscribe(location, modeChangeHandler)
98 schedule(timeOfDay, scheduledTimeHandler)
102 def eventHandler1(evt) {
104 def lastTime = state[evt.deviceId]
105 if (lastTime == null || now() - lastTime >= frequency * 60000) {
114 def modeChangeHandler(evt) {
115 log.trace "modeChangeHandler $evt.name: $evt.value ($triggerModes)"
116 if (evt.value in triggerModes) {
121 def scheduledTimeHandler() {
122 //eventHandler1(null)
125 def appTouchHandler(evt) {
129 private takeAction(evt) {
132 state[evt.deviceId] = now()
138 else if(color == "Green")
140 else if(color == "Yellow")
142 else if(color == "Orange")
144 else if(color == "Purple")
146 else if(color == "Pink")
153 state.previous[it.id] = [
154 "switch": it.currentValue("switch"),
155 "level" : it.currentValue("level"),
156 "hue": it.currentValue("hue"),
157 "saturation": it.currentValue("saturation"),
158 "color": it.currentValue("color")
162 log.debug "current values = $state.previous"
164 def newValue = [hue: hueColor, saturation: 100, level: (lightLevel as Integer) ?: 100]
165 log.debug "new value = $newValue"
167 hues*.setColor(newValue)
173 if(!duration) //default to 10 seconds
177 log.debug "reset hue"
180 else if(duration < 10)
182 log.debug "pause $duration"
183 pause(duration * 1000)
189 log.debug "runIn $duration, resetHue"
190 runIn(duration,"resetHue", [overwrite: false])
198 it.setColor(state.previous[it.id])