2 * Copyright 2014 Yves Racine
3 * LinkedIn profile: ca.linkedin.com/pub/yves-racine-m-sc-a/0/406/4b/
5 * Developer retains all right, title, copyright, and interest, including all copyright, patent rights, trade secret
6 * in the Background technology. May be subject to consulting fees under the Agreement between the Developer and the Customer.
7 * Developer grants a non exclusive perpetual license to use the Background technology in the Software developed for and delivered
8 * to Customer under this Agreement. However, the Customer shall make no commercial use of the Background technology without
9 * Developer's written consent.
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.
14 * Software Distribution is restricted and shall be done only with Developer's written approval.
16 * Resume Ecobee's Program when people arrive or there is been recent motion at home
17 * N.B. Requires MyEcobee device available at
18 * http://www.ecomatiqhomes.com/#!store/tc3yr
21 // Automatically generated. Make future change here.
23 name: "ecobeeResumeProg",
25 author: "Yves Racine",
26 description: "resumes your ecobee's scheduled program when a presence is back home or when motion is detected or when a ST hello mode is changed",
28 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/ecobee.png",
29 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/ecobee@2x.png"
34 page(name: "About", title: "About", install: false , uninstall: true, nextPage: "selectThermostats") {
36 paragraph "ecobeeResumeProg, the smartapp that resumes your ecobee's scheduled program when a presence is back home,or when motion is detected or when a ST hello mode is changed"
37 paragraph "Version 2.1.7"
38 paragraph "If you like this smartapp, please support the developer via PayPal and click on the Paypal link below "
39 href url: "https://www.paypal.me/ecomatiqhomes",
40 title:"Paypal donation..."
41 paragraph "Copyright©2014 Yves Racine"
42 href url:"http://github.com/yracine/device-type.myecobee", style:"embedded", required:false, title:"More information..."
43 description: "http://github.com/yracine/device-type.myecobee/blob/master/README.md"
46 page(name: "selectThermostats", title: "Thermostats", install: false , uninstall: false, nextPage: "selectModes") {
47 section("Resume Program at the ecobee thermostat(s)") {
48 input "ecobee", "device.myEcobeeDevice", title: "Ecobee Thermostat(s)", multiple: true
50 section("When one of these people arrive at home") {
51 input "people", "capability.presenceSensor", multiple: true, required:false
53 section("Or there is motion at home on these sensors [optional]") {
54 input "motions", "capability.motionSensor", title: "Where?", multiple: true, required: false
56 section("False alarm threshold [defaults = 3 minutes]") {
57 input "falseAlarmThreshold", "decimal", title: "Number of minutes", required: false
60 page(name: "selectModes", title: "Select Hello ST modes", content: "selectModes")
61 page(name: "Notifications", title: "Notifications Options", install: true, uninstall: false) {
62 section("Notifications") {
63 input "sendPushMessage", "enum", title: "Send a push notification?", metadata: [values: ["Yes", "No"]], required:
65 input "phone", "phone", title: "Send a Text Message?", required: false
67 section([mobileOnly:true]) {
68 label title: "Assign a name for this SmartApp", required: false
82 return dynamicPage(name: "selectModes", title: "Select Modes", install: false, uninstall: false, nextPage:
84 section("Or when SmartThings' hello home mode changes to (ex.'Home')[optional]") {
85 input "newMode", "enum", options: enumModes, multiple:true, required: false
91 log.debug ("appTouch>location.mode= $location.mode, about to takeAction (manual appTouch)")
98 log.debug "Installed with settings: ${settings}"
103 log.debug "Updated with settings: ${settings}"
109 log.debug "Current mode = ${location.mode}, people = ${people.collect{it.label + ': ' + it.currentPresence}}"
110 subscribe(location, changeMode)
111 subscribe(app, appTouch)
112 subscribe(people, "presence", presence)
113 subscribe(motions, "motion", motionEvtHandler)
117 def motionEvtHandler(evt) {
118 if ((evt.value == "active") && residentsHaveJustBeenActive()) {
119 def message = "EcobeeResumeProg>Recent motion just detected at home, do it"
126 private residentsHaveJustBeenActive() {
127 def threshold = (falseAlarmThreshold != null && falseAlarmThreshold != "") ? (falseAlarmThreshold*60*1000) as Long : 3*60*1000L
129 def t0 = new Date(now() - threshold)
130 for (sensor in motions) {
131 def recentStates = sensor.statesSince("motion", t0)
132 if (recentStates.find {it.value == "active"}) {
137 log.debug "residentsHaveJustBeenActive: $result"
141 def changeMode(evt) {
143 Boolean foundMode=false
146 if (it==location.mode) {
152 log.debug "changeMode>location.mode= $location.mode, newMode=${newMode},foundMode=${foundMode}, not resuming program"
155 def message = "EcobeeResumeProg>${newMode} has just been triggered, about to take actions.."
163 log.debug "evt.name: $evt.value"
164 def threshold = (falseAlarmThreshold != null && falseAlarmThreshold != "") ? (falseAlarmThreshold*60*1000) as Long : 3*60*1000L
167 def t0 = new Date(now() - threshold)
168 if (evt.value == "present") {
170 def person = getPerson(evt)
171 if (person != null) {
172 def recentNotPresent = person.statesSince("presence", t0).find {
173 it.value == "not present"
175 if (!recentNotPresent) {
176 message = "EcobeeResumeProg>${person.displayName} just arrived,take actions.."
182 message = "EcobeeResumeProg>somebody just arrived at home, but she/he is not been selected for resuming the ecobee program."
191 def message = "EcobeeResumeProg>resumed program at ${ecobee} thermostats..."
199 private getPerson(evt) {
201 evt.deviceId == it.id
206 if (sendPushMessage != "No") {
207 log.debug("sending push message")
211 log.debug("sending text message")