2 * My Living Room Lighting
4 * Copyright 2015 SmartThings
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 * in compliance with the License. You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
12 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
13 * for the specific language governing permissions and limitations under the License.
17 name: "My Living Room Lighting",
18 namespace: "smartthings",
19 author: "smartthings",
20 description: "allow a button controller to control my hue lamps, tv lights, and floor lamp",
22 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
23 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
24 iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
28 section("Control which hue lamps?") {
29 input "hueLamps", "capability.colorControl", required: true, multiple: true
31 section("Control which TV lights?") {
32 input "tvLights", "capability.colorControl", required: false
34 section("Control other (non-hue) lamps?") {
35 input "otherLights", "capability.switch", required: false, multiple: true
37 section("Which button controller?") {
38 input "buttonDevice", "capability.button", required: true
43 log.debug "Installed with settings: ${settings}"
48 log.debug "Updated with settings: ${settings}"
54 subscribe(buttonDevice, "button", buttonEvent)
56 log.debug "lamp ${it.displayName} hue: ${it.currentHue}"
57 log.debug "lamp ${it.displayName} saturation: ${it.currentSaturation}"
58 log.debug "lamp ${it.displayName} color ${it.currentColor}"
59 log.debug "lamp ${it.displayName} level ${it.currentLevel}"
62 log.debug "tv hue: ${tvLights?.currentHue}"
63 log.debug "tv saturation: ${tvLights?.currentSaturation}"
64 log.debug "tv color ${tvLights?.currentColor}"
65 log.debug "tv level ${tvLights?.currentLevel}"
68 def buttonEvent(evt) {
69 def buttonState = evt.value // "pushed" or "held"
70 def buttonNumber = parseJson(evt.data)?.buttonNumber
72 log.debug "buttonState: $buttonState"
73 log.debug "buttonNumber: $buttonNumber"
75 if (!(1..4).contains(buttonNumber)) {
76 log.error "This app only supports four buttons. Invalid buttonNumber: $buttonNumber"
77 } else if (!(buttonState == "pushed" || buttonState == "held")) {
78 log.error "This app only supports button pushed and held values. Invalid button state: $buttonState"
80 def meth = "handleButton" + buttonNumber + buttonState.capitalize()
81 log.debug "meth: $meth"
86 // normal "white" lighting
87 def handleButton1Pushed() {
88 log.debug "handle1Pushed"
90 hueLamps.setColor(level: 100, hue: 20, saturation: 80)
92 // notice the "?." operator - tvLights may not be set (required: false).
93 tvLights?.setColor(level: 100, hue: 100, saturation: 100)
97 // turn everything off
98 def handleButton1Held() {
99 log.debug "handleButton1Held"
106 // soft, dim white light
107 def handleButton2Pushed() {
108 log.debug "handleButton2Pushed"
110 hueLamps.setColor(level: 50, hue: 20, saturation: 80)
111 tvLights.setColor(level: 30, hue: 70, saturation: 70)
115 // set to what you want!
116 def handleButton2Held() {
117 log.debug "handleButton2Held"
121 def handleButton3Pushed() {
122 hueLamps.setColor(level: 40, hue: 100, saturation: 100)
123 tvLights?.setColor(level: 30, hue: 100, saturation: 100)
127 // set to what you want!
128 def handleButton3Held() {
129 log.debug "handleButton3Held"
133 def handleButton4Pushed() {
134 log.debug "handleButton4Pushed"
136 hueLamps.setColor(level: 10, hue: 70, saturation: 100)
137 tvLights?.setColor(level: 10, hue: 70, saturation: 100)
142 def handleButton4Held() {
144 log.debug "lamp ${it.displayName} hue: ${it.currentHue}"
145 log.debug "lamp ${it.displayName} saturation: ${it.currentSaturation}"
146 log.debug "lamp ${it.displayName} level ${it.currentLevel}"
149 log.debug "tv hue: ${tvLights?.currentHue}"
150 log.debug "tv saturation: ${tvLights?.currentSaturation}"
151 log.debug "tv color ${tvLights?.currentColor}"
152 log.debug "tv level ${tvLights?.currentLevel}"