forked from sidjohn1/smartthings
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlantLinkMonitor2.groovy
145 lines (135 loc) · 4.83 KB
/
PlantLinkMonitor2.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/**
* PlantLink Monitor 2
*
* Copyright 2015 Sidney Johnson
* Inspired by notoriousbdg's BatteryMonitor
*
* If you like this app, please support the developer via PayPal: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XKDRYZ3RUNR9Y
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
* Version: 2.0 - Initial Version
* Version: 2.1 - Better grammar and plant status detection
*/
definition(
name: "PlantLink Monitor 2",
namespace: "sidjohn1",
author: "Sidney Johnson",
description: "Monitors plantlink senors, and sends notifacations when your plants need water",
category: "Green Living",
iconUrl: "http://cdn.device-icons.smartthings.com/Home/home10-icn.png",
iconX2Url: "http://cdn.device-icons.smartthings.com/Home/[email protected]",
iconX3Url: "http://cdn.device-icons.smartthings.com/Home/[email protected]")
preferences {
page name:"pageInfo"
}
def pageInfo() {
return dynamicPage(name: "pageInfo", install: true, uninstall: true) {
section("About") {
paragraph "PlantLink Monitor 2, Monitors your Plantlinks and sends notifacations when your plants need water."
paragraph "If you like this smartapp, please support the developer via PayPal and click on the Paypal link below "
href url: "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=XKDRYZ3RUNR9Y",
title:"Paypal donation..."
paragraph "${textVersion()}\n${textCopyright()}"
}
def plantlist = ""
def verb = ""
settings.senors.each() {
try {
if (it.currentPlantStatus.contains("Needs")) {
verb = " "
}
else {
verb = " is "
}
plantlist += "$it.displayName$verb${it.currentPlantStatus.toLowerCase()}\n"
} catch (e) {
log.trace "Error checking status."
log.trace e
}
}
if (plantlist) {
section("Your Plants...") {
paragraph plantlist.trim()
}
}
section("Select PlantLinks...") {
input "senors", "device.Plantlink", title: "PlantLink", multiple: true, required: true, submitOnChange: true
}
section("Event Notifications..."){
input "sendPush", "bool", title: "Send as Push?", required: false, defaultValue: true
input "sendSMS", "phone", title: "Send as SMS?", required: false, defaultValue: null
input "sendTooDry", "bool", title: "Notify when too dry?", required: false, defaultValue: true
input "sendTooWet", "bool", title: "Notify when too wet?", required: false, defaultValue: false
}
}
}
def installed() {
log.trace "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.trace "Updated with settings: ${settings}"
unschedule()
unsubscribe()
initialize()
}
def initialize() {
log.info "PlantLink-Direct Monitor ${textVersion()} ${textCopyright()}"
subscribe(app, onAppTouch)
subscribe(location, "sunset", updated)
subscribe(location, "sunrise", updated)
schedule("22 32 6,19 1/1 * ?", sendStatus)
}
def onAppTouch(event) {
log.info "onAppTouch(${event.value})"
sendStatus()
}
def sendStatus() {
log.trace "Checking Plants"
def verb = ""
sendEvent(linkText:app.label, name:"sendStatus", value:"Checking Plants", descriptionText:"Checking Plants", eventType:"SOLUTION_EVENT", displayed: true)
settings.senors.each() {
try {
if (it.currentPlantStatus.contains("Needs")) {
verb = " "
}
else {
verb = " is "
}
log.trace "${it.displayName}$verb${it.currentPlantStatus.toLowerCase()}"
sendEvent(linkText:app.label, name:"${it.displayName}", value:"${it.currentPlantStatus}", descriptionText:"${it.displayName}$verb${it.currentPlantStatus.toLowerCase()}", eventType:"SOLUTION_EVENT", displayed: true)
if (it.currentPlantStatus == "Too Wet" && settings.sendTooWet == true) {
send("${it.displayName}$verb${it.currentPlantStatus.toLowerCase()}")
}
if ((it.currentPlantStatus == "Too Dry" || it.currentPlantStatus == "Needs Water") && settings.sendTooDry == true) {
send("${it.displayName}$verb${it.currentPlantStatus.toLowerCase()}")
}
}
catch (e) {
log.trace "Error checking status"
log.trace e
}
}
}
def send(msg) {
if (settings.sendPush == true) {
sendPush(msg)
}
if (settings.sendSMS != null) {
sendSms(phoneNumber, msg)
}
}
private def textVersion() {
def text = "Version 2.1"
}
private def textCopyright() {
def text = "Copyright © 2016 Sidjohn1"
}