Update notify-me-with-hue.groovy
[smartapps.git] / official / dry-the-wetspot.groovy
1 /**
2  *  Dry the Wetspot
3  *
4  *  Copyright 2014 Scottin Pollock
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: "Dry the Wetspot",
18     namespace: "smartthings",
19     author: "Scottin Pollock",
20     description: "Turns switch on and off based on moisture sensor input.",
21     category: "Safety & Security",
22     iconUrl: "https://s3.amazonaws.com/smartapp-icons/Developers/dry-the-wet-spot.png",
23     iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Developers/dry-the-wet-spot@2x.png"
24 )
25
26
27 preferences {
28         section("When water is sensed...") {
29                 input "sensor", "capability.waterSensor", title: "Where?", required: true
30         }
31         section("Turn on a pump...") {
32                 input "pump", "capability.switch", title: "Which?", required: true
33         }
34 }
35
36 def installed() {
37         subscribe(sensor, "water.dry", waterHandler)
38         subscribe(sensor, "water.wet", waterHandler)
39 }
40
41 def updated() {
42         unsubscribe()
43         subscribe(sensor, "water.dry", waterHandler)
44         subscribe(sensor, "water.wet", waterHandler)
45 }
46
47 def waterHandler(evt) {
48         log.debug "Sensor says ${evt.value}"
49         if (evt.value == "wet") {
50                 pump.on()
51         } else if (evt.value == "dry") {
52                 pump.off()
53         }
54 }
55