You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* --Removed references to phrases and replaced with routines
10
+
* --Added bool logic to inputs instead of enum for "yes" "no" options
11
+
* --Fixed halting error with code installation
12
+
*
13
+
* Copyright 2015 Tim Slagle
14
+
*
15
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
16
+
* in compliance with the License. You may obtain a copy of the License at:
17
+
*
18
+
* http://www.apache.org/licenses/LICENSE-2.0
19
+
*
20
+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
21
+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
22
+
* for the specific language governing permissions and limitations under the License.
23
+
*
24
+
*/
25
+
definition(
26
+
name: "Routine Director",
27
+
namespace: "tslagle13",
28
+
author: "Tim Slagle",
29
+
description: "Monitor a set of presence sensors and activate routines based on whether your home is empty or occupied. Each presence status change will check against the current 'sun state' to run routines based on occupancy and whether the sun is up or down.",
input "awayDay", "enum", title: "Everyone Is Away And It's Day", required: true, options: routines, submitOnChange: true
79
+
input "awayNight", "enum", title: "Everyone Is Away And It's Night", required: true, options: routines, submitOnChange: true
80
+
input "homeDay", "enum", title: "At Least One Person Is Home And It's Day", required: true, options: routines, submitOnChange: true
81
+
input "homeNight", "enum", title: "At Least One Person Is Home And It's Night", required: true, options: routines, submitOnChange: true
82
+
}
83
+
/* section("Select modes used for each condition.") { This allows the director to know which rotuine has already been ran so it does not run again if someone else comes home.
84
+
input "homeModeDay", "mode", title: "Select Mode Used for 'Home Day'", required: true
85
+
input "homeModeNight", "mode", title: "Select Mode Used for 'Home Night'", required: true
86
+
}*/
87
+
}
88
+
}
89
+
}
90
+
91
+
definstalled() {
92
+
log.debug "Updated with settings: ${settings}"
93
+
initialize()
94
+
}
95
+
96
+
defupdated() {
97
+
log.debug "Updated with settings: ${settings}"
98
+
unsubscribe()
99
+
initialize()
100
+
}
101
+
102
+
definitialize() {
103
+
subscribe(people, "presence", presence)
104
+
checkSun()
105
+
subscribe(location, "sunrise", setSunrise)
106
+
subscribe(location, "sunset", setSunset)
107
+
state.homestate =null
108
+
}
109
+
110
+
//check current sun state when installed.
111
+
defcheckSun() {
112
+
def zip = settings.zip asString
113
+
def sunInfo = getSunriseAndSunset(zipCode: zip)
114
+
def current = now()
115
+
116
+
if (sunInfo.sunrise.time < current && sunInfo.sunset.time > current) {
117
+
state.sunMode ="sunrise"
118
+
runIn(60,"setSunrise")
119
+
}
120
+
else {
121
+
state.sunMode ="sunset"
122
+
runIn(60,"setSunset")
123
+
}
124
+
}
125
+
126
+
//change to sunrise mode on sunrise event
127
+
defsetSunrise(evt) {
128
+
state.sunMode ="sunrise";
129
+
changeSunMode(newMode);
130
+
log.debug "Current sun mode is ${state.sunMode}"
131
+
}
132
+
133
+
//change to sunset mode on sunset event
134
+
defsetSunset(evt) {
135
+
state.sunMode ="sunset";
136
+
changeSunMode(newMode)
137
+
log.debug "Current sun mode is ${state.sunMode}"
138
+
}
139
+
140
+
//change mode on sun event
141
+
defchangeSunMode(newMode) {
142
+
if (allOk) {
143
+
144
+
if (everyoneIsAway()) /*&& (state.sunMode == "sunrise")*/ {
0 commit comments