-
Notifications
You must be signed in to change notification settings - Fork 0
/
Programmable_thermo.app.groovy
159 lines (134 loc) · 5.92 KB
/
Programmable_thermo.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
/**
* Programmable Thermostat Settings
* Allows you to set single/multiple thermostats to different temp during different days of the week unlimited number of times (one app instance for each change)
*
* Taken from : Samer Theodossy. modified by jscgs350 to add fan mode changes.
* Update - 2014-11-20
*/
// Automatically generated. Make future change here.
definition(
name: "Programmable Thermostat Settings",
namespace: "jscgs350",
author: "Ramit Bhalla",
description: "Program thermostat(s) from withing SmartThings",
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("Set these thermostats") {
input "thermostat", "capability.thermostat", title: "Which?", multiple:true
}
section("To these temperatures") {
input "heatingSetpoint", "decimal", title: "When Heating"
input "coolingSetpoint", "decimal", title: "When Cooling"
}
section("To this Fan setting") {
input "fanSetpoint", "enum", title: "Which setting?", multiple:false,
metadata:[values:["on","auto","circulate"]]
}
section("Configuration") {
input "dayOfWeek", "enum",
title: "Which day of the week?",
multiple: false,
metadata: [
values: [
'All Week',
'Monday to Friday',
'Saturday & Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday'
]
]
input "time", "time", title: "At this time"
}
section( "Notifications" ) {
input "sendPushMessage", "enum", title: "Send a push notification?", metadata:[values:["No", "Yes"]]
input "phoneNumber", "phone", title: "Send a text message?", required: false
}
}
def installed() {
// subscribe to these events
initialize()
}
def updated() {
// we have had an update
// remove everything and reinstall
initialize()
}
def initialize() {
unschedule()
def scheduleTime = timeToday(time, location.timeZone)
def timeNow = now() + (2*1000) // ST platform has resolution of 1 minutes, so be safe and check for 2 minutes)
log.debug "Current time is ${(new Date(timeNow)).format("EEE MMM dd yyyy HH:mm z", location.timeZone)}, scheduled check time is ${scheduleTime.format("EEE MMM dd yyyy HH:mm z", location.timeZone)}"
if (scheduleTime.time < timeNow) { // If we have passed current time we're scheduled for next day
log.debug "Current scheduling check time $scheduleTime has passed, scheduling check for tomorrow"
scheduleTime = scheduleTime + 1 // Next day schedule
}
log.debug "Temp change schedule set for $dayOfWeek at time ${scheduleTime.format("HH:mm z", location.timeZone)} to $heatingSetpoint in heat and $coolingSetpoint in cool and the fan to $fanSetpoint"
log.debug "Scheduling next temp check at ${scheduleTime.format("EEE MMM dd yyyy HH:mm z", location.timeZone)}"
schedule(scheduleTime, setTheTemp)
}
def setTheTemp() {
def doChange = false
Calendar localCalendar = Calendar.getInstance(TimeZone.getDefault());
int currentDayOfWeek = localCalendar.get(Calendar.DAY_OF_WEEK);
// some debugging in order to make sure things are working correclty
log.debug "Calendar DOW: " + currentDayOfWeek
log.debug "SET DOW: " + dayOfWeek
// Check the condition under which we want this to run now
// This set allows the most flexibility.
if(dayOfWeek == 'All Week'){
doChange = true
}
else if((dayOfWeek == 'Monday' || dayOfWeek == 'Monday to Friday') && currentDayOfWeek == Calendar.instance.MONDAY){
doChange = true
}
else if((dayOfWeek == 'Tuesday' || dayOfWeek == 'Monday to Friday') && currentDayOfWeek == Calendar.instance.TUESDAY){
doChange = true
}
else if((dayOfWeek == 'Wednesday' || dayOfWeek == 'Monday to Friday') && currentDayOfWeek == Calendar.instance.WEDNESDAY){
doChange = true
}
else if((dayOfWeek == 'Thursday' || dayOfWeek == 'Monday to Friday') && currentDayOfWeek == Calendar.instance.THURSDAY){
doChange = true
}
else if((dayOfWeek == 'Friday' || dayOfWeek == 'Monday to Friday') && currentDayOfWeek == Calendar.instance.FRIDAY){
doChange = true
}
else if((dayOfWeek == 'Saturday' || dayOfWeek == 'Saturday & Sunday') && currentDayOfWeek == Calendar.instance.SATURDAY){
doChange = true
}
else if((dayOfWeek == 'Sunday' || dayOfWeek == 'Saturday & Sunday') && currentDayOfWeek == Calendar.instance.SUNDAY){
doChange = true
}
// If we have hit the condition to schedule this then lets do it
if(doChange == true){
log.debug "Setting temperature in $thermostat to $heatingSetpoint in heat and $coolingSetpoint in cool and the fan to $fanSetpoint"
thermostat.setHeatingSetpoint(heatingSetpoint)
thermostat.setCoolingSetpoint(coolingSetpoint)
thermostat.setThermostatFanMode(fanSetpoint)
send "$thermostat heat set to '${heatingSetpoint}' and cool to '${coolingSetpoint}' and the fan to '${fanSetpoint}'"
}
else {
log.debug "Temp change not scheduled for today."
}
log.debug "Scheduling next check"
initialize() // Setup the next check schedule
}
private send(msg) {
if ( sendPushMessage != "No" ) {
log.debug( "sending push message" )
sendPush( msg )
}
if ( phoneNumber ) {
log.debug( "sending text message" )
sendSms( phoneNumber, msg )
}
log.debug msg
}