Update groveStreams.groovy
[smartapps.git] / third-party / RemindToCloseDoggyDoor.groovy
1 /**
2  *  Remind to close doggy door
3  *
4  *  Copyright 2014 George Sudarkoff
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: "Remind to close doggy door",
18     namespace: "com.sudarkoff",
19     author: "George Sudarkoff",
20     description: "Check that the doggy door is closed after the specified time and send a message if it's not.",
21     category: "Convenience",
22     iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
23     iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png"
24 )
25
26
27 preferences {
28     section ("When this door") {
29         input "door", "capability.contactSensor", title: "Which door?", multiple: false, required: true
30     }
31     section ("Still open past") {
32         input "timeOfDay", "time", title: "What time?", required: true
33     }
34     section (title: "Notify") {
35         input "sendPushMessage", "bool", title: "Send a push notification?"
36         input "phone", "phone", title: "Send a Text Message?", required: false
37     }
38
39 }
40
41 def installed() {
42     initialize()
43 }
44
45 def updated() {
46     unschedule()
47     initialize()
48 }
49
50 def initialize() {
51     schedule(timeToday(timeOfDay, location.timeZone), "checkDoor")
52 }
53
54 def checkDoor() {
55     if (door.latestValue("contact") == "open") {
56         log.debug "${door} is open, sending notification."
57         def message = "Remember to close the ${door}!"
58         send(message)
59     }
60 }
61
62 private send(msg) {
63     if (sendPushMessage != "No") {
64         sendPush(msg)
65     }
66
67     if (phone) {
68         sendSms(phone, msg)
69     }
70
71     log.debug msg
72 }
73