-
Notifications
You must be signed in to change notification settings - Fork 8
/
CrockPot.v010.app.groovy
188 lines (157 loc) · 5.22 KB
/
CrockPot.v010.app.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/*****************************************************************************
Device: CrockPot.v010.app.groovy
Author: [email protected]
Version: 1.0
Date: 2013-04-06
Purpose: To control a crockpot using a switch. This app was written using
GE outdoor lighting controller so there is functionality to see if
the controller or power strip is running/plugged in. Typically the
user will have a Zwave outlet. You need to use a dumb crockpot that
only has a off/low/med/high physical switch. Set the crockpot to the
desired level and plug into the switch.
Use License: Non-Profit Open Software License version 3.0 (NPOSL-3.0)
http://opensource.org/licenses/NPOSL-3.0
******************************************************************************
Change Log
Version: 1.0
Date: 20130406
Change1: Initial Release
******************************************************************************
Device Types Supported: Switch
To-Do's: Create a customer companion device that has tile with minutes
left to cook.
Other Info: This written to demo at San Francisco with SmartThings.
******************************************************************************/
// Automatically generated. Make future change here.
definition(
name: "SmartThings CrockPot Controller 1.0",
namespace: "wackware",
author: "[email protected]",
description: "CrockPots Will Win the Machine -v- Man Wars!",
category: "My Apps",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience%402x.png")
preferences {
section("Crockpot Cooking Info..."){
input "startTime", "time", title: "Start time...", required: true
input "onDuration", "decimal", title: "For how long...", required: true
input "meal", "text", title: "Meal name (optional)...", required: false
}
section("CrockPot Notifications") {
input "phone", "phone", title: "Text me at (optional)...", multiple: false, required: false
}
section("CrockPot Controller Switch") {
input "switch1", "capability.switch", multiple: false, required: true
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
startUp()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unschedule()
unsubscribe()
startUp()
}
def startUp() {
def usrMilliTime = timeToday(startTime)
if(now() > usrMilliTime.time) {
log.debug "start time is not ok ${startTime}"
communicateError("CROCKPOT ERROR: Your Starting Time is in the Past. Please update Starting Time")
return
} else {
log.debug "start time is ok ${startTime}"
}
state.onTimer = onDuration?.toDouble() * 60
state.errorCount = 0
log.debug "The user running time is: ${state.onTimer}"
schedule(startTime, "turnOnDevice")
subscribe(switch1, "switch.on", communicateOn)
subscribe(switch1, "switch.off", communicateOff)
}
def shutdown(){
unschedule()
unsubscribe()
switch1.off()
}
def checkStatus() {
if (state.onTimer > 0) {
log.debug "Timer = ${state.onTimer}"
if (switchOK("on") == true) {
state.onTimer = state.onTimer - 1
state.errorCount = 0
//here's where someday we'll update the display on the app/device for minutes left
} else {
state.errorCount = state.errorCount + 1
switch1.on()
}
} else {
// we should not get here as the off event handler will kill this schedule
log.debug "Timer = ${state.onTimer}"
switch1.off()
}
log.debug "We had ${state.errorCount - 1} errors calling device on"
if(state.errorCount > 3) {
communicateCantStart()
shutdown()
}
}
def switchOK(value)
{
def result = false
for (it in (switch1 ?: [])) {
log.debug "SwitchState = ${it.currentSwitch}"
if (it.currentSwitch == value) {
result = true
break
}
}
result
}
def turnOnDevice() {
schedule("0 * * * * ?", "checkStatus") // used to verify on and stay on for duration
checkStatus()
}
def communicateError(msg) {
if (phone != "") {
sendSms(phone, msg)
}
def push = true
if(push == true) {
sendPush(msg)
}
}
def communicate(msg){
log.debug "COMMUNICATING"
if (phone != "") {
sendSms(phone, msg)
}
def push = true //code like this so we can toggle it on or off during testing in program
if(push == true) {
sendPush(msg)
}
}
def communicateOn(evt){
if (settings['meal'] == '""') {
settings['meal'] = "Meal"
}
def msg = "A Smart CrockPot Says: I have started cooking the ${meal}. "
msg+= "I will be finished in ${onDuration} hours."
communicate(msg)
}
def communicateOff(evt) {
if (settings['meal'] == '""') {
settings['meal'] = "Meal"
}
def msg = "A Smart CrockPot Says: I have finished cooking the ${meal}. "
msg+= "Bon Appetit!"
communicate(msg)
shutdown()
}
def communicateCantStart() {
def msg = "Unable to talk to the Cloud. "
msg+= "Please contact your CrockPot System Administrator. "
msg+= "Or, check that I am plugged in."
communicate(msg)
}