-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathroofcoilcontroler.groovy
233 lines (203 loc) · 9.72 KB
/
roofcoilcontroler.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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
/**
* Copyright 2015 SmartThings
*
* 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.
*
* lg kahn smart app to turn device on when temp is between two values
* and off otherwise. Also has to be between 2 date ranges.
* also give alerts when turning on off.
* I use for a roof heater wire/coil.
* v2 add disable/enable option
*
* Author: LGKahn [email protected]
*/
definition(
name: "Roof Coil Controller",
namespace: "smartthings",
author: "lgkahn",
description: "Control a roof coil or othe device(s) when temperature is between two values turns on and also has to be within a date range. Automatically turns off if one of the conditions is not met. Alerting option also.",
category: "Green Living",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Meta/temp_thermo-switch.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Meta/[email protected]"
)
preferences {
section("Choose a temperature sensor... "){
input "sensor", "capability.temperatureMeasurement", title: "Sensor"
}
section("Select the outlet(s)... "){
input "outlets", "capability.switch", title: "Outlets", multiple: true
}
section("Turn on when temp is above ..."){
input "onSetPoint", "decimal", title: "Set On Temp"
}
section("Turn off when temp is above ..."){
input "offSetPoint", "decimal", title: "Set Off Temp"
}
section("Start after Date format (yyyymmdd)..."){
input "startDate", "number", title: "Date?"
}
section("End after Date format (yyyymmdd)..."){
input "endDate", "number", title: "Date?"
}
section("Time Zone Offset ie -5 etc...."){
input "tzOffset", "number", title: "Offset?", range: "-12..12"
}
section("Disabled?"){
input "disabled", "bool", title: "Disabled?", defaultValue: false
}
section( "Notifications" ) {
// input("recipients", "contact", title: "Send notifications to") {
input "sendPushMessage", "capability.notification", title: "Notification Devices: Hubitat PhoneApp or Pushover", multiple: true, required: false
// input "sendPushMessage", "enum", title: "Send a push notification?", options: ["Yes", "No"], required: false
// input "alsoSendTextMessage", "enum", title: "Also Send a text message?", options: ["Yes", "No"], required: false
// input "phone1", "phone", title: "Send a Text Message?", required: false
// }
}
}
def installed()
{
log.debug "in coil controller installed ... currenttemp = $sensor.currentTemperature"
subscribe(sensor, "temperature", temperatureHandler)
}
def updated()
{
log.debug "in coil controller updated ... currenttemp = $sensor.currentTemperature"
unsubscribe()
subscribe(sensor, "temperature", temperatureHandler)
if (disabled == null)
disabled = false
// turn off if on
if (disabled == true)
{
log.debug "Disabled!"
outlets.off()
}
// for debugging and testing uncomment temperatureHandlerTest()
}
def temperatureHandler(evt)
{
def currenttemp = sensor.currentTemperature
log.debug "in temp handler"
log.debug "current temp = $currenttemp"
log.debug "onSetPoint = $onSetPoint"
log.debug "offSetPoint = $offSetPoint"
log.debug "set offset = $tzOffset"
log.debug "disabled = $disabled"
def today = new Date();
def ltf = new java.text.SimpleDateFormat("yyyyMMdd")
ltf.setTimeZone(TimeZone.getTimeZone("GMT${tzOffset}"))
String date1 = ltf.format(today);
int intdate = Integer.parseInt(date1)
// log.debug "int date = $intdate"
//log.debug "enddate = $endDate"
// log.debug "startdate = $startDate"
def currSwitches = outlets.currentSwitch
def onOutlets = currSwitches.findAll { switchVal -> switchVal == "on" ? true : false }
def onsize = onOutlets.size()
def allsize = outlets.size()
if (disabled == true)
{
log.debug "Currently Disabled!"
// turn off just in case
if (onsize > 0)
{
log.debug "Is Disabled, but some are on...Turning them off!"
outlets.off()
}
}
else
{
if (((intdate >= startDate) && (intdate <= endDate))
&& ((currenttemp > onSetPoint) && (currenttemp < offSetPoint)))
{
// dont do anything if already on
log.debug "In try turn on, number of outlets on = $onsize, total outlets = $allsize."
if (onsize != allsize)
{
log.debug "turning outlets On as $sensor.displayName is reporting $currenttemp which is between $onSetPoint and $offSetPoint, and we are within the date range ($startDate - $endDate)!"
mysend("Turning device(s) On as $sensor.displayName is reporting a temperature of $currenttemp which is between $onSetPoint and $offSetPoint, and we are within the date range ($startDate - $endDate)!")
outlets.on()
}
else log.debug "Not turning on again, all already on!"
}
else
{
// dont do anything if already off
log.debug "In try turn off, number of outlets On = $onsize."
if (onsize != 0)
{
log.debug "turning outlets Off! as $sensor.displayName is reporting $currenttemp which is Not between $onSetPoint and $offSetPoint, or we are no longer within the date range ($startDate - $endDate)!"
mysend("Turning device(s) Off as $sensor.displayName is reporting a temperature of $currenttemp which is not between $onSetPoint and $offSetPoint, or we are no longer within the date range ($startDate - $endDate)!")
outlets.off()
}
else log.debug "All outlets already off!"
}
}
}
def temperatureHandlerTest()
{
//log.trace "temperature: $evt.value, $evt"
// this routine is only for testing and debugging. to test or make changes uncomment the call in update.
// this is so we dont have to wait 15 minutes till a half an hour for the event to fire for testing.
def currenttemp = sensor.currentTemperature
log.debug "in temp handler test"
log.debug "current temp = $currenttemp"
log.debug "onSetPoint = $onSetPoint"
log.debug "offSetPoint = $offSetPoint"
log.debug "set offset = $tzOffset"
def today = new Date();
def ltf = new java.text.SimpleDateFormat("yyyyMMdd")
ltf.setTimeZone(TimeZone.getTimeZone("GMT${tzOffset}"))
String date1 = ltf.format(today);
int intdate = Integer.parseInt(date1)
log.debug "int date = $intdate"
log.debug "enddate = $endDate"
log.debug "startdate = $startDate"
def currSwitches = outlets.currentSwitch
def onOutlets = currSwitches.findAll { switchVal ->
switchVal == "on" ? true : false }
log.debug "how many on = ${onOutlets.size()} "
if (((intdate >= startDate) && (intdate <= endDate))
&& ((currenttemp > onSetPoint) && (currenttemp < offSetPoint)))
{
// dont do anything if already on
if (onOutlets.size() != outlets.size())
{
log.debug "turning outlets On as $sensor.displayName is reporting $currenttemp which is between $onSetPoint and $offSetPoint, and we are within the date range ($startDate - $endDate)!"
//mysend("Turning device(s) On as $sensor.displayName is reporting a temperature of $currenttemp which is between $onSetPoint and $offSetPoint, and we are within the date range ($startDate - $endDate)!")
outlets.on()
}
else log.debug "Not turning on again, all already on!"
}
else
{
// dont do anything if already off
if (onOutlets.size() != 0)
{
log.debug "turning outlets Off! as $sensor.displayName is reporting $currenttemp which is Not between $onSetPoint and $offSetPoint, or we are no longer within the date range ($startDate - $endDate)!"
//mysend("Turning device(s) Off as $sensor.displayName is reporting a temperature of $currenttemp which is not between $onSetPoint and $offSetPoint, or we are no longer within the date range ($startDate - $endDate)!")
outlets.off()
}
else log.debug "All outlets already off!"
}
}
private mysend(msg) {
if (location.contactBookEnabled) {
log.debug("sending notifications to: ${recipients?.size()}")
sendNotificationToContacts(msg, recipients)
}
else {
if (sendPushMessage) {
// log.debug("sending push message")
sendPushMessage.deviceNotification(msg)
}
}
// log.debug msg
}