4 * Copyright 2014 George Sudarkoff
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 * in compliance with the License. You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
12 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
13 * for the specific language governing permissions and limitations under the License.
18 name: "Working From Home",
19 namespace: "com.sudarkoff",
20 author: "George Sudarkoff",
21 description: "If after a particular time of day a certain person is still at home, trigger a 'Working From Home' action.",
22 category: "Mode Magic",
23 iconUrl: "https://s3.amazonaws.com/smartthings-device-icons/Office/office22-icn.png",
24 iconX2Url: "https://s3.amazonaws.com/smartthings-device-icons/Office/office22-icn@2x.png"
28 page (name:"configActions")
32 dynamicPage(name: "configActions", title: "Configure Actions", uninstall: true, install: true) {
33 section ("When this person") {
34 input "person", "capability.presenceSensor", title: "Who?", multiple: false, required: true
35 input "days", "enum", title: "Set for specific day(s) of the week", multiple: true, required: false,
36 options: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
38 section ("Still at home past") {
39 input "timeOfDay", "time", title: "What time?", required: true
42 def phrases = location.helloHome?.getPhrases()*.label
45 section("Perform this action") {
46 input "wfhPhrase", "enum", title: "\"Hello, Home\" action", required: true, options: phrases
50 section (title: "More options", hidden: hideOptions(), hideable: true) {
51 input "sendPushMessage", "bool", title: "Send a push notification?"
52 input "phone", "phone", title: "Send a Text Message?", required: false
53 //input "days", "enum", title: "Set for specific day(s) of the week", multiple: true, required: false,
54 // options: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
57 section([mobileOnly:true]) {
58 label title: "Assign a name", required: false
59 mode title: "Set for specific mode(s)", required: false
74 schedule("someTime", "checkPresence")
75 //schedule(timeToday(timeOfDay, location.timeZone), "checkPresence")
77 // app.setTitle(customName)
82 if (daysOk && modeOk) {
83 if (person.latestValue("presence") == "present") {
84 log.debug "${person} is present, triggering WFH action."
85 location.helloHome.execute(settings.wfhPhrase)
86 def message = "${location.name} executed '${settings.wfhPhrase}' because ${person} is home."
93 if (sendPushMessage != "No") {
104 private getModeOk() {
105 def result = !modes || modes.contains(location.mode)
109 private getDaysOk() {
112 def df = new java.text.SimpleDateFormat("EEEE")
113 if (location.timeZone) {
114 df.setTimeZone(location.timeZone)
117 df.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"))
119 def day = df.format(new Date())
120 result = days.contains(day)
125 private hideOptions() {
126 (days || modes)? false: true