Update circadian-daylight.groovy
[smartapps.git] / third-party / ecobeeGetTips.groovy
1 /*
2  *  ecobeeGetTips
3  *  Copyright 2015 Yves Racine
4  *  LinkedIn profile: http://www.linkedin.com/in/yracine
5  *
6  *  Developer retains all right, title, copyright, and interest, including all copyright, patent rights, trade secret 
7  *  in the Background technology. May be subject to consulting fees under the Agreement between the Developer and the Customer. 
8  *  Developer grants a non exclusive perpetual license to use the Background technology in the Software developed for and delivered 
9  *  to Customer under this Agreement. However, the Customer shall make no commercial use of the Background technology without
10  *  Developer's written consent.
11  *
12  *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
13  *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
14  *
15  *  Software Distribution is restricted and shall be done only with Developer's written approval.
16  *  N.B. Requires My Ecobee device ( v5.0 and higher) available at:
17  *      http://www.ecomatiqhomes.com/store
18  */
19 definition(
20     name: "ecobeeGetTips",
21     namespace: "yracine",
22     author: "Yves Racine",
23     description: "Get Energy Saving Tips from My Ecobee device",
24     category: "My Apps",
25     iconUrl: "https://s3.amazonaws.com/smartapp-icons/Partner/ecobee.png",
26     iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Partner/ecobee@2x.png"
27 )
28
29
30 preferences {
31
32         page (name: "generalSetupPage", title: "General Setup", uninstall:true, nextPage: "displayTipsPage") {
33                 section("About") {
34                         paragraph "ecobeeGetTips, the smartapp that Get Comfort & Energy Saving Tips from My Ecobee device"
35                         paragraph "Version 1.1" 
36                         paragraph "If you like this smartapp, please support the developer via PayPal and click on the Paypal link below " 
37                                 href url: "https://www.paypal.me/ecomatiqhomes",
38                                         title:"Paypal donation..."
39                         paragraph "Copyright©2016 Yves Racine"
40                                 href url:"http://github.com/yracine/device-type.myecobee", style:"embedded", required:false, title:"More information..."  
41                                         description: "http://github.com/yracine/device-type.myecobee/blob/master/README.md"
42                 }
43                 section("Get tips for this ecobee thermostat") {
44                         input "ecobee", "device.myEcobeeDevice", title: "Ecobee Thermostat"
45                 }  
46                 section("Level Of Tip") {
47                         input (name:"level", title: "Which level ([1..4], 4 is the highest, but not always applicable, ex. for multi-stage heating/cooling systems)?", type:"number", 
48                         required:false, description:"optional")
49                 }  
50                 section("Tip processing reset") {
51                         input (name:"resetTipFlag", title: "Do you want to re-start over and reset tips?", type:"bool")
52                 }  
53         }
54         page (name: "displayTipsPage", content: "displayTipsPage", install: false, uninstall:true)
55         page(name: "OtherOptions", title: "Other Options", install: true, uninstall: true) {
56         section([mobileOnly:true]) {
57                         label title: "Assign a name for this SmartApp", required: false
58                 }
59         }
60 }
61
62 def displayTipsPage() {
63         if (resetTipFlag) {
64                 log.debug("displayPageTips>about to call resetTips()")    
65                 ecobee.resetTips()
66         }    
67         log.debug("displayPageTips>about to call getTips()")   
68         ecobee.getTips(level)
69         def tip1 = ecobee.currentTip1Text    
70         def tip2 = ecobee.currentTip2Text    
71         def tip3 = ecobee.currentTip3Text    
72         def tip4 = ecobee.currentTip4Text    
73         def tip5 = ecobee.currentTip5Text
74         def tip1Level = ecobee.currentTip1Level    
75         def tip2Level = ecobee.currentTip2Level    
76         def tip3Level = ecobee.currentTip3Level    
77         def tip4Level = ecobee.currentTip4Level    
78         def tip5Level = ecobee.currentTip5Level
79     
80         return dynamicPage (name: "displayTipsPage", title: "Display Current Tips",  nextPage: "OtherOptions") {
81     
82                 section("Tips") {
83                 
84                         if (tip1) {    
85                                 paragraph image: "${getCustomImagePath()}/tip.jpg","** Tip1 - Level $tip1Level **\n\n ${tip1}\n"
86                 
87                         } else {
88                                 paragraph image: "${getCustomImagePath()}/tip.jpg", "Based on the input data available, no tips may apply at this time for this level. " +
89                                         "You can try with a different level of tips or later when the indoor/outdoor conditions have changed!"
90                         }            
91                                     
92                         if (tip2) {    
93                                 paragraph image: "${getCustomImagePath()}tip.jpg", "** Tip2 - Level$tip2Level **\n\n  ${tip2}\n"    
94                         }        
95                         if (tip3) {    
96                                 paragraph image: "${getCustomImagePath()}tip.jpg",  "** Tip3 - Level $tip3Level **\n\n  ${tip3}\n"    
97                         }
98                         if (tip4) {    
99                                 paragraph image: "${getCustomImagePath()}tip.jpg", "** Tip4 - Level $tip4Level **\n\n  ${tip4}\n"    
100                         }        
101                         if (tip5) {    
102                                 paragraph image: "${getCustomImagePath()}tip.jpg", "** Tip5 - Level $tip5Level **\n\n  ${tip5}\n"    
103                         }
104                 }  
105         }  
106  
107 }
108 def installed() {
109
110         initialize()
111 }
112
113 def updated() {
114         log.debug "Updated with settings: ${settings}"
115
116         unsubscribe()
117         initialize()
118 }
119
120 def initialize() {
121         // TODO: subscribe to attributes, devices, locations, etc.
122 }
123
124
125 def getCustomImagePath() {
126         return "http://raw.githubusercontent.com/yracine/device-type.myecobee/master/icons/"
127 }