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}"
69 log.debug "Updated with settings: ${settings}"
75 def subscribeToEvents() {
76 subscribe(app, appTouchHandler)
77 subscribe(contact, "contact.open", eventHandler1)
78 subscribe(contactClosed, "contact.closed", eventHandler1)
79 subscribe(acceleration, "acceleration.active", eventHandler1)
80 subscribe(motion, "motion.active", eventHandler1)
81 subscribe(mySwitch, "switch.on", eventHandler1)
82 subscribe(mySwitchOff, "switch.off", eventHandler1)
83 subscribe(arrivalPresence, "presence.present", eventHandler1)
84 subscribe(departurePresence, "presence.not present", eventHandler1)
85 subscribe(smoke, "smoke.detected", eventHandler1)
86 subscribe(smoke, "smoke.tested", eventHandler1)
87 subscribe(smoke, "carbonMonoxide.detected", eventHandler1)
88 subscribe(water, "water.wet", eventHandler1)
89 subscribe(button1, "button.pushed", eventHandler1)
92 subscribe(location, modeChangeHandler)
96 schedule(timeOfDay, scheduledTimeHandler)
100 def eventHandler1(evt) {
102 def lastTime = state[evt.deviceId]
103 if (lastTime == null || now() - lastTime >= frequency * 60000) {
112 def modeChangeHandler(evt) {
113 log.trace "modeChangeHandler $evt.name: $evt.value ($triggerModes)"
114 if (evt.value in triggerModes) {
119 def scheduledTimeHandler() {
120 //eventHandler1(null)
123 def appTouchHandler(evt) {
127 private takeAction(evt) {
130 state[evt.deviceId] = now()
136 else if(color == "Green")
138 else if(color == "Yellow")
140 else if(color == "Orange")
142 else if(color == "Purple")
144 else if(color == "Pink")
151 state.previous[it.id] = [
152 "switch": it.currentValue("switch"),
153 "level" : it.currentValue("level"),
154 "hue": it.currentValue("hue"),
155 "saturation": it.currentValue("saturation"),
156 "color": it.currentValue("color")
160 log.debug "current values = $state.previous"
162 def newValue = [hue: hueColor, saturation: 100, level: (lightLevel as Integer) ?: 100]
163 log.debug "new value = $newValue"
165 hues*.setColor(newValue)
171 if(!duration) //default to 10 seconds
175 log.debug "reset hue"
178 else if(duration < 10)
180 log.debug "pause $duration"
181 pause(duration * 1000)
187 log.debug "runIn $duration, resetHue"
188 runIn(duration,"resetHue", [overwrite: false])
196 it.setColor(state.previous[it.id])