Update laundry-monitor.groovy
[smartapps.git] / official / door-state-to-color-light-hue-bulb.groovy
1 /**
2  *  CoopBoss Door Status to color
3  *
4  *  Copyright 2015 John Rucker
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  
17 definition(
18     name: "Door State to Color Light (Hue Bulb)",
19     namespace: "JohnRucker",
20     author: "John Rucker",
21     description: "Change the color of your Hue bulbs based on your coop's door status.",
22     category: "My Apps",
23     iconUrl: "http://coopboss.com/images/SmartThingsIcons/coopbossLogo.png",
24     iconX2Url: "http://coopboss.com/images/SmartThingsIcons/coopbossLogo2x.png",
25     iconX3Url: "http://coopboss.com/images/SmartThingsIcons/coopbossLogo3x.png")
26
27
28 preferences {
29         section("When the door opens/closese...") {
30         paragraph "Sets a Hue bulb or bulbs to a color based on your coop's door status:\r  unknown = white\r  open = blue\r  opening = purple\r  closed = green\r  closing = pink\r  jammed = red\r  forced close = orange."
31                 input "doorSensor", "capability.doorControl", title: "Select CoopBoss", required: true, multiple: false
32                 input "bulbs", "capability.colorControl", title: "pick a bulb", required: true, multiple: true
33         }
34 }
35
36 def installed() {
37         log.debug "Installed with settings: ${settings}"
38         initialize()
39 }
40
41 def updated() {
42         log.debug "Updated with settings: ${settings}"
43         unsubscribe()
44         initialize()
45 }
46
47 def initialize() {
48         subscribe(doorSensor, "doorState", coopDoorStateHandler)
49 }
50
51 def coopDoorStateHandler(evt) {
52     log.debug "${evt.descriptionText}, $evt.value"
53         def color = "White"
54     def hueColor = 100
55     def saturation = 100
56     Map hClr = [:]
57     hClr.hex = "#FFFFFF"
58
59         switch(evt.value) {
60         case "open":
61                 color = "Blue"
62             break;
63         case "opening":
64                 color = "Purple"
65             break;
66         case "closed":
67                 color = "Green"
68             break;
69         case "closing":
70                 color = "Pink"
71             break;
72         case "jammed":
73                 color = "Red"
74             break;
75         case "forced close":
76                 color = "Orange"
77             break;
78         case "unknown":
79                 color = "White"
80             break;        
81     }   
82        
83         switch(color) {
84                 case "White":
85                         hueColor = 52
86                         saturation = 19
87                         break;
88                 case "Daylight":
89                         hueColor = 53
90                         saturation = 91
91                         break;
92                 case "Soft White":
93                         hueColor = 23
94                         saturation = 56
95                         break;
96                 case "Warm White":
97                         hueColor = 20
98                         saturation = 80 //83
99                         break;
100                 case "Blue":
101                         hueColor = 70
102             hClr.hex = "#0000FF"
103                         break;
104                 case "Green":
105                         hueColor = 39
106             hClr.hex = "#00FF00"
107                         break;
108                 case "Yellow":
109                         hueColor = 25
110             hClr.hex = "#FFFF00"            
111                         break;
112                 case "Orange":
113                         hueColor = 10
114             hClr.hex = "#FF6000"
115                         break;
116                 case "Purple":
117                         hueColor = 75
118             hClr.hex = "#BF7FBF"
119                         break;
120                 case "Pink":
121                         hueColor = 83
122             hClr.hex = "#FF5F5F"
123                         break;
124                 case "Red":
125                         hueColor = 100
126             hClr.hex = "#FF0000"
127                         break;
128         }    
129     
130     //bulbs*.on()
131     bulbs*.setHue(hueColor)
132         bulbs*.setSaturation(saturation)   
133     bulbs*.setColor(hClr)
134     
135     //bulbs.each{
136         //it.on()  // Turn the bulb on when open (this method does not come directly from the colorControl capability)
137         //it.setLevel(100)  // Make sure the light brightness is 100%       
138         //it.setHue(hueColor)
139                 //it.setSaturation(saturation) 
140         //}        
141 }