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/smartapp-icons/ModeMagic/Cat-ModeMagic.png",
24 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/ModeMagic/Cat-ModeMagic@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
36 section ("Still at home past") {
37 input "timeOfDay", "time", title: "What time?", required: true
40 def phrases = location.helloHome?.getPhrases()*.label
43 section("Perform this action") {
44 input "wfhPhrase", "enum", title: "\"Hello, Home\" action", required: true, options: phrases
48 section (title: "More options", hidden: hideOptions(), hideable: true) {
49 input "sendPushMessage", "bool", title: "Send a push notification?"
50 input "phone", "phone", title: "Send a Text Message?", required: false
51 input "days", "enum", title: "Set for specific day(s) of the week", multiple: true, required: false,
52 options: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]
55 section([mobileOnly:true]) {
56 label title: "Assign a name", required: false
57 mode title: "Set for specific mode(s)", required: false
72 schedule(timeToday(timeOfDay, location?.timeZone), "checkPresence")
74 app.setTitle(customName)
79 if (daysOk && modeOk) {
80 if (person.latestValue("presence") == "present") {
81 log.debug "${person} is present, triggering WFH action."
82 location.helloHome.execute(settings.wfhPhrase)
83 def message = "${location.name} executed '${settings.wfhPhrase}' because ${person} is home."
90 if (sendPushMessage != "No") {
101 private getModeOk() {
102 def result = !modes || modes.contains(location.mode)
106 private getDaysOk() {
109 def df = new java.text.SimpleDateFormat("EEEE")
110 if (location.timeZone) {
111 df.setTimeZone(location.timeZone)
114 df.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"))
116 def day = df.format(new Date())
117 result = days.contains(day)
122 private hideOptions() {
123 (days || modes)? false: true