Update the-big-switch.groovy
[smartapps.git] / official / my-light-toggle.groovy
1 /**
2  *  My Light Toggle
3  *
4  *  Copyright 2015 Jesse Silverberg
5  *
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:
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
14  *
15  */
16 definition(
17     name: "My Light Toggle",
18     namespace: "JLS",
19     author: "Jesse Silverberg",
20     description: "Toggle lights on/off with a motion sensor",
21     category: "Convenience",
22     iconUrl: "https://www.dropbox.com/s/6kxtd2v5reggonq/lightswitch.gif?raw=1",
23     iconX2Url: "https://www.dropbox.com/s/6kxtd2v5reggonq/lightswitch.gif?raw=1",
24     iconX3Url: "https://www.dropbox.com/s/6kxtd2v5reggonq/lightswitch.gif?raw=1")
25
26
27 preferences {
28         section("When this sensor detects motion...") {
29                 input "motionToggler", "capability.motionSensor", title: "Motion Here", required: true, multiple: false
30     }
31     
32     section("Master switch for the toggle reference...") {
33         input "masterToggle", "capability.switch", title: "Reference switch", required: true, multiple: false
34     }
35     
36     section("Toggle lights...") {
37             input "switchesToToggle", "capability.switch", title: "These go on/off", required: true, multiple: true
38         }
39 }
40
41 def installed() {
42         log.debug "Installed with settings: ${settings}"
43
44         initialize()
45 }
46
47 def updated() {
48         log.debug "Updated with settings: ${settings}"
49
50         unsubscribe()
51         initialize()
52 }
53
54 def initialize() {
55         subscribe(motionToggler, "motion", toggleSwitches)
56 }
57
58
59 def toggleSwitches(evt) {
60         log.debug "$evt.value"
61   
62         if (evt.value == "active" && masterToggle.currentSwitch == "off") {
63 //      for (thisSwitch in switchesToToggle) {
64 //              log.debug "$thisSwitch.label"
65 //                      thisSwitch.on()
66                 switchesToToggle.on()
67         masterToggle.on()
68     } else if (evt.value == "active" && masterToggle.currentSwitch == "on") {
69 //      for (thisSwitch in switchesToToggle) {
70 //              log.debug "$thisSwitch.label"
71 //              thisSwitch.off()
72                 switchesToToggle.off()
73         masterToggle.off()
74         }
75
76 }