Update speaker-mood-music.groovy
[smartapps.git] / third-party / ecobeeManageVacation.groovy
1 /***
2  *  Copyright 2014 Yves Racine
3  *  LinkedIn profile: ca.linkedin.com/pub/yves-racine-m-sc-a/0/406/4b/
4  *
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.
10  *
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. 
13  * 
14  *  Software Distribution is restricted and shall be done only with Developer's written approval.
15  *  Manage Vacation events at Ecobee Thermostat(s)
16  *  N.B. Requires MyEcobee device available at 
17  *          http://www.ecomatiqhomes.com/#!store/tc3yr 
18  */
19
20 // Automatically generated. Make future change here.
21 definition(
22         name: "ecobeeManageVacation",
23         namespace: "yracine",
24         author: "Yves Racine",
25         description: "manages your ecobee vacation settings ['creation', 'update', 'delete']",
26         category: "My Apps",
27         iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/ecobee.png",
28         iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/ecobee@2x.png"
29 )
30
31 preferences {
32         section("About") {
33                 paragraph "ecobeeManageVacation, the smartapp that manages your ecobee vacation settings ['creation', 'update', 'delete']"
34                 paragraph "Version 1.9.3" 
35                 paragraph "If you like this smartapp, please support the developer via PayPal and click on the Paypal link below " 
36                         href url: "https://www.paypal.me/ecomatiqhomes",
37                                 title:"Paypal donation..."
38                 paragraph "Copyright©2014 Yves Racine"
39                         href url:"http://github.com/yracine/device-type.myecobee", style:"embedded", required:false, title:"More information..."  
40                                 description: "http://github.com/yracine/device-type.myecobee/blob/master/README.md"
41         }
42
43         section("For the Ecobee thermostat(s)") {
44                 input "ecobee", "device.myEcobeeDevice", title: "Ecobee Thermostat", multiple:true
45         }
46         section("Create this Vacation Name") {
47                 input "vacationName", "text", title: "Vacation Name"
48         }
49     
50         section("Or delete the vacation [default=false]") {
51                 input "deleteVacation", "Boolean", title: "delete?", metadata: [values: ["true", "false"]], required: false
52         }
53         section("Cool Temp for vacation, [default = 80°F/27°C]") {
54                 input "givenCoolTemp", "decimal", title: "Cool Temp", required: false
55         }
56         section("Heat Temp for vacation [default= 60°F/14°C]") {
57                 input "givenHeatTemp", "decimal", title: "Heat Temp", required: false
58         }
59         section("Start date for the vacation, [format = DD-MM-YYYY]") {
60                 input "givenStartDate", "text", title: "Beginning Date"
61         }
62         section("Start time for the vacation [HH:MM 24HR]") {
63                 input "givenStartTime", "text", title: "Beginning time"
64         }
65         section("End date for the vacation [format = DD-MM-YYYY]") {
66                 input "givenEndDate", "text", title: "End Date"
67         }
68         section("End time for the vacation [HH:MM 24HR]") {
69                 input "givenEndTime", "text", title: "End time"
70         }
71
72
73 }
74
75
76
77 def installed() {
78
79         subscribe(app, appTouch)
80         takeAction()
81
82 }
83
84
85 def updated() {
86
87         unsubscribe()
88         subscribe(app, appTouch)
89         takeAction()
90
91
92 }
93
94 def appTouch(evt) {
95         takeAction()
96 }
97 def takeAction() {    
98         log.debug "ecobeeManageVacation> about to take actions"
99         def minHeatTemp, minCoolTemp
100         def scale = getTemperatureScale()
101         if (scale == 'C') {
102                 minHeatTemp = givenHeatTemp ?: 14 // by default, 14°C is the minimum heat temp
103                 minCoolTemp = givenCoolTemp ?: 27 // by default, 27°C is the minimum cool temp
104         } else {
105                 minHeatTemp = givenHeatTemp ?: 60 // by default, 60°F is the minimum heat temp
106                 minCoolTemp = givenCoolTemp ?: 80 // by default, 80°F is the minimum cool temp
107         }
108         def vacationStartDateTime = null
109         String dateTime = null
110
111         dateTime = givenStartDate + " " + givenStartTime
112         log.debug("Start datetime= ${datetime}")
113         vacationStartDateTime = new Date().parse('d-M-yyyy H:m', dateTime)
114
115         dateTime = givenEndDate + " " + givenEndTime
116         log.debug("End datetime= ${datetime}")
117         def vacationEndDateTime = new Date().parse('d-M-yyyy H:m', dateTime)
118
119         if (deleteVacation == 'false') {
120                 // You may want to change to ecobee.createVacation('serial number list',....) if you own EMS thermostat(s)
121
122                 log.debug("About to call iterateCreateVacation for ${vacationName}")
123                 ecobee.each {        
124                         it.createVacation("", vacationName, minCoolTemp, minHeatTemp, vacationStartDateTime,
125                         vacationEndDateTime)
126                 }            
127                 send("ecobeeManageVacation> vacationName ${vacationName} created at ${ecobee}")
128         } else {
129                 ecobee.each {
130                         it.deleteVacation("", vacationName)
131                 }                
132                 send("ecobeeManageVacation> vacationName ${vacationName} deleted at ${ecobee}")
133
134         }
135
136 }
137
138
139 private send(msg) {
140         if (sendPushMessage != "No") {
141                 log.debug("sending push message")
142                 sendPush(msg)
143         }
144
145         if (phoneNumber) {
146                 log.debug("sending text message")
147                 sendSms(phoneNumber, msg)
148         }
149
150         log.debug msg
151 }