2 * Copyright 2015 SmartThings
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
10 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
11 * for the specific language governing permissions and limitations under the License.
13 * title: Carpool Notifier
16 * Do you carpool to work with your spouse? Do you pick your children up from school? Have they been waiting in doors for you? Let them know you've arrived with Carpool Notifier.
18 * This SmartApp is designed to send notifications to your carpooling buddies when you arrive to pick them up. What separates this SmartApp from other notification SmartApps is that it will only send a notification if your carpool buddy is not with you.
22 * icon: https://s3.amazonaws.com/smartapp-icons/Family/App-IMadeIt.png
23 * icon2X: https://s3.amazonaws.com/smartapp-icons/Family/App-IMadeIt%402x.png
30 name: "Carpool Notifier",
31 namespace: "smartthings",
32 author: "SmartThings",
33 description: "Send notifications to your carpooling buddies when you arrive to pick them up. If the person you are picking up is home, and has been for 5 minutes or more, they will get a notification when you arrive.",
34 category: "Green Living",
35 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Family/App-IMadeIt.png",
36 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Family/App-IMadeIt@2x.png"
41 input(name: "driver", type: "capability.presenceSensor", required: true, multiple: false, title: "When this person arrives", description: "Who's driving?")
42 input("recipients", "contact", title: "Notify", description: "Send notifications to") {
43 input(name: "phoneNumber", type: "phone", required: true, multiple: false, title: "Send a text to", description: "Phone number")
45 input(name: "message", type: "text", required: false, multiple: false, title: "With the message:", description: "Your ride is here!")
46 input(name: "rider", type: "capability.presenceSensor", required: true, multiple: false, title: "But only when this person is not with you", description: "Who are you picking up?")
51 log.debug "Installed with settings: ${settings}"
57 log.debug "Updated with settings: ${settings}"
64 subscribe(driver, "presence.present", presence)
69 if (evt.value == "present" && riderIsHome())
71 // log.debug "Rider Is Home; Send A Text"
79 // log.debug "rider presence: ${rider.currentPresence}"
81 if (rider.currentPresence != "present")
86 def riderState = rider.currentState("presence")
87 // log.debug "riderState: ${riderState}"
93 def latestState = rider.latestState("presence")
96 def minusFive = new Date(minutes: now.minutes - 5)
99 if (minusFive > latestState.date)
108 if (location.contactBookEnabled) {
109 sendNotificationToContacts(message ?: "Your ride is here!", recipients)
112 sendSms(phoneNumber, message ?: "Your ride is here!")