Update hue-mood-lighting.groovy
[smartapps.git] / official / light-up-the-night.groovy
1 /**
2  *  Copyright 2015 SmartThings
3  *
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:
6  *
7  *      http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
12  *
13  *  Light Up The Night
14  *
15  *  Author: SmartThings
16  */
17 definition(
18     name: "Light Up the Night",
19     namespace: "smartthings",
20     author: "SmartThings",
21     description: "Turn your lights on when it gets dark and off when it becomes light again.",
22     category: "Convenience",
23     iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet-luminance.png",
24     iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/light_outlet-luminance@2x.png"
25 )
26
27 preferences {
28         section("Monitor the luminosity...") {
29                 input "lightSensor", "capability.illuminanceMeasurement"
30         }
31         section("Turn on a light...") {
32                 input "lights", "capability.switch", multiple: true
33         }
34 }
35
36 def installed() {
37         subscribe(lightSensor, "illuminance", illuminanceHandler)
38 }
39
40 def updated() {
41         unsubscribe()
42         subscribe(lightSensor, "illuminance", illuminanceHandler)
43 }
44
45 // New aeon implementation
46 def illuminanceHandler(evt) {
47         def lastStatus = state.lastStatus
48         if (lastStatus != "on" && evt.integerValue < 30) {
49                 lights.on()
50                 state.lastStatus = "on"
51         }
52         else if (lastStatus != "off" && evt.integerValue > 50) {
53                 lights.off()
54                 state.lastStatus = "off"
55         }
56 }