2 * Close a valve if moisture is detected
4 * Copyright 2014 SmartThings
8 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the License at:
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
14 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
15 * for the specific language governing permissions and limitations under the License.
19 name: "Close The Valve",
20 namespace: "smartthings",
21 author: "SmartThings",
22 description: "Close a selected valve if moisture is detected, and get notified by SMS and push notification.",
23 category: "Safety & Security",
24 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Developers/dry-the-wet-spot.png",
25 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Developers/dry-the-wet-spot@2x.png"
29 section("When water is sensed...") {
30 input "sensor", "capability.waterSensor", title: "Where?", required: true, multiple: true
32 section("Close the valve...") {
33 input "valve", "capability.valve", title: "Which?", required: true, multiple: false
35 section("Send this message (optional, sends standard status message if not specified)"){
36 input "messageText", "text", title: "Message Text", required: false
38 section("Via a push notification and/or an SMS message"){
39 input "phone", "phone", title: "Phone Number (for SMS, optional)", required: false
40 input "pushAndPhone", "enum", title: "Both Push and SMS?", required: false, options: ["Yes","No"]
42 section("Minimum time between messages (optional)") {
43 input "frequency", "decimal", title: "Minutes", required: false
48 subscribe(sensor, "water", waterHandler)
53 subscribe(sensor, "water", waterHandler)
56 def waterHandler(evt) {
57 log.debug "Sensor says ${evt.value}"
58 if (evt.value == "wet") {
62 def lastTime = state[evt.deviceId]
63 if (lastTime == null || now() - lastTime >= frequency * 60000) {
72 private sendMessage(evt) {
73 def msg = messageText ?: "We closed the valve because moisture was detected"
74 log.debug "$evt.name:$evt.value, pushAndPhone:$pushAndPhone, '$msg'"
76 if (!phone || pushAndPhone != "No") {
77 log.debug "sending push"
81 log.debug "sending SMS"
85 state[evt.deviceId] = now()