4 * Copyright 2014 Yves Racine
5 * LinkedIn profile: ca.linkedin.com/pub/yves-racine-m-sc-a/0/406/4b/
7 * Developer retains all right, title, copyright, and interest, including all copyright, patent rights, trade secret
8 * in the Background technology. May be subject to consulting fees under the Agreement between the Developer and the Customer.
9 * Developer grants a non exclusive perpetual license to use the Background technology in the Software developed for and delivered
10 * to Customer under this Agreement. However, the Customer shall make no commercial use of the Background technology without
11 * Developer's written consent.
13 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
14 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * Software Distribution is restricted and shall be done only with Developer's written approval.
18 * You may want to create multiple instances of this smartapp (and rename them in SmartSetup) for each time
19 * you want to set a different Climate at a given day and time during the week.*
21 * N.B. Requires MyEcobee device available at
22 * http://www.ecomatiqhomes.com/#!store/tc3yr
25 name: "ecobeeSetClimate",
27 author: "Yves Racine",
28 description: "This script allows an ecobee user to set a Climate at a given day & time",
30 iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/ecobee.png",
31 iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/ecobee@2x.png"
38 page(name: "selectThermostats", title: "Thermostats", install: false, uninstall: true, nextPage: "selectProgram") {
40 paragraph "ecobeeSetClimate, the smartapp that sets your ecobee thermostat to a given climate at a given day & time"
41 paragraph "Version 1.2"
42 paragraph "If you like this smartapp, please support the developer via PayPal and click on the Paypal link below "
43 href url: "https://www.paypal.me/ecomatiqhomes",
44 title:"Paypal donation..."
45 paragraph "Copyright©2014 Yves Racine"
46 href url:"http://github.com/yracine/device-type.myecobee", style:"embedded", required:false, title:"More information..."
47 description: "http://github.com/yracine/device-type.myecobee/blob/master/README.md"
49 section("Set the ecobee thermostat(s)") {
50 input "ecobee", "device.myEcobeeDevice", title: "Which ecobee thermostat(s)?", multiple: true
53 section("Configuration") {
54 input "dayOfWeek", "enum",
55 title: "Which day of the week?",
71 input "begintime", "time", title: "Beginning time"
75 page(name: "selectProgram", title: "Ecobee Programs", content: "selectProgram")
76 page(name: "Notifications", title: "Notifications Options", install: true, uninstall: true) {
77 section("Notifications") {
78 input "sendPushMessage", "enum", title: "Send a push notification?", metadata: [values: ["Yes", "No"]], required:
80 input "phone", "phone", title: "Send a Text Message?", required: false
82 section([mobileOnly:true]) {
83 label title: "Assign a name for this SmartApp", required: false
84 mode title: "Set for specific mode(s)", required: false
91 def ecobeePrograms = ecobee.currentClimateList.toString().minus('[').minus(']').tokenize(',')
92 log.debug "programs: $ecobeePrograms"
95 return dynamicPage(name: "selectProgram", title: "Select Ecobee Program", install: false, uninstall: true, nextPage:
97 section("Select Program") {
98 input "givenClimate", "enum", title: "Which program?", options: ecobeePrograms, required: true
106 // subscribe to these events
111 // we have had an update
112 // remove everything and reinstall
120 log.debug "Scheduling setClimate for day " + dayOfWeek + " at begin time " + begintime
121 subscribe(ecobee, "climateList", climateListHandler)
123 schedule(begintime, setClimate)
124 subscribe(app, setClimateNow)
127 def climateListHandler(evt) {
128 log.debug "thermostat's Climates List: $evt.value, $settings"
131 def setClimateNow(evt) {
136 def climateName = (givenClimate ?: 'Home').capitalize()
139 def doChange = IsRightDayForChange()
141 // If we have hit the condition to schedule this then lets do it
143 if (doChange == true) {
144 log.debug "setClimate, location.mode = $location.mode, newMode = $newMode, location.modes = $location.modes"
147 it.setThisTstatClimate(climateName)
149 send("ecobeeSetClimate>set ${ecobee} to ${climateName} program as requested")
151 log.debug "climate change to ${climateName} not scheduled for today."
153 log.debug "End of Fcn"
157 def IsRightDayForChange() {
159 def makeChange = false
160 String currentDay = new Date().format("E", location.timeZone)
162 // Check the condition under which we want this to run now
163 // This set allows the most flexibility.
164 if (dayOfWeek == 'All Week') {
166 } else if ((dayOfWeek == 'Monday' || dayOfWeek == 'Monday to Friday') && currentDay == 'Mon') {
168 } else if ((dayOfWeek == 'Tuesday' || dayOfWeek == 'Monday to Friday') && currentDay == 'Tue') {
170 } else if ((dayOfWeek == 'Wednesday' || dayOfWeek == 'Monday to Friday') && currentDay == 'Wed') {
172 } else if ((dayOfWeek == 'Thursday' || dayOfWeek == 'Monday to Friday') && currentDay == 'Thu') {
174 } else if ((dayOfWeek == 'Friday' || dayOfWeek == 'Monday to Friday') && currentDay == 'Fri') {
176 } else if ((dayOfWeek == 'Saturday' || dayOfWeek == 'Saturday & Sunday') && currentDay == 'Sat') {
178 } else if ((dayOfWeek == 'Sunday' || dayOfWeek == 'Saturday & Sunday') && currentDay == 'Sun' ) {
183 // some debugging in order to make sure things are working correclty
184 log.debug "Calendar DOW: " + currentDay
185 log.debug "SET DOW: " + dayOfWeek
192 if (sendPushMessage != "No") {
193 log.debug("sending push message")
198 log.debug("sending text message")
199 sendSms(phoneNumber, msg)
209 log.debug "value: $evt.value, event: $evt, settings: $settings, handlerName: ${evt.handlerName}"