Update hvac-auto-off.smartapp.groovy
[smartapps.git] / third-party / ecobeeSetFanMinOnTime.groovy
1 /**
2  *  ecobeeSetFanMinOnTime
3  *
4  *  Copyright 2015 Yves Racine
5  *  LinkedIn profile: ca.linkedin.com/pub/yves-racine-m-sc-a/0/406/4b/
6  *
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.
12  *
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. 
15  *
16  *  Software Distribution is restricted and shall be done only with Developer's written approval.
17  *
18  *  N.B. Requires MyEcobee device available at 
19  *          http://www.ecomatiqhomes.com/#!store/tc3yr 
20  */
21 definition(
22     name: "ecobeeSetFanMinOnTime",
23     namespace: "yracine",
24     author: "Yves Racine",
25     description: "ecobeeSetFanMinOnTime, the smartapp that sets your ecobee's fan to circulate for a minimum time (in minutes) per hour",
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 preferences {
31
32
33         page(name: "selectThermostats", title: "Thermostats", install: false , uninstall: true, nextPage: "selectProgram") {
34                 section("About") {
35                         paragraph "ecobeeSetFanMinOnTime, the smartapp that sets your ecobee's fan to circulate for a minimum time (in minutes) per hour." 
36                         paragraph "Version 1.2" 
37                         paragraph "If you like this smartapp, please support the developer via PayPal and click on the Paypal link below " 
38                                 href url: "https://www.paypal.me/ecomatiqhomes"
39                                         title:"Paypal donation..."
40                         paragraph "Copyright©2015 Yves Racine"
41                                 href url:"http://github.com/yracine/device-type.myecobee", style:"embedded", required:false, title:"More information..."  
42                                         description: "http://github.com/yracine/device-type.myecobee/blob/master/README.md"
43                 }
44                 section("Change the following ecobee thermostat(s)...") {
45                         input "thermostats", "device.myEcobeeDevice", title: "Which thermostat(s)", multiple: true
46                 }
47         }
48         page(name: "selectProgram", title: "Ecobee Programs", content: "selectProgram")
49         page(name: "Notifications", title: "Notifications Options", install: true, uninstall: true) {
50                 section("Notifications") {
51                         input "sendPushMessage", "enum", title: "Send a push notification?", metadata: [values: ["Yes", "No"]], required:
52                                 false
53                         input "phone", "phone", title: "Send a Text Message?", required: false
54                 }
55                 section([mobileOnly:true]) {
56                         label title: "Assign a name for this SmartApp", required: false
57                 }
58         }
59 }
60
61
62 def selectProgram() {
63     def ecobeePrograms = thermostats[0].currentClimateList.toString().minus('[').minus(']').tokenize(',')
64         log.debug "programs: $ecobeePrograms"
65
66         return dynamicPage(name: "selectProgram", title: "Select Ecobee Program", install: false, uninstall: true, nextPage:
67                         "Notifications") {
68                 section("Select Program") {
69                         input "givenClimate", "enum", title: "When change to this ecobee program?", options: ecobeePrograms, required: true
70                 }
71                 section("Set the minimum fan runtime per hour for this program [default: 10 min. per hour]") {
72                         input "givenFanMinTime", "number", title: "Minimum fan runtime in minutes", required: false
73                 }
74
75         
76         }
77 }
78
79
80 def installed() {
81         subscribe(thermostats,"climateName",changeFanMinOnTime)    
82         subscribe(app, changeFanMinOnTime)
83 }
84
85 def updated() {
86         unsubscribe()
87         subscribe(thermostats,"climateName",changeFanMinOnTime)    
88         subscribe(app, changeFanMinOnTime)
89 }
90
91
92 def changeFanMinOnTime(evt) {
93
94
95         if ((evt.value != givenClimate) && (evt.value != 'touch')) {
96                 log.debug ("changeFanMinOnTime>not right climate (${evt.value}), doing nothing...")
97                 return
98         }    
99         Integer min_fan_time = (givenFanMinTime != null) ? givenFanMinTime : 10 //  10 min. fan time per hour by default
100     
101         def message = "ecobeeSetFanMinOnTime>changing fanMinOnTime to ${min_fan_time} at ${thermostats}.."
102         send(message)
103
104         thermostats.each {
105                 it?.setThermostatSettings("", ['fanMinOnTime': "${min_fan_time}"])
106         }
107 }
108
109 private send(msg) {
110         if (sendPushMessage != "No") {
111                 log.debug("sending push message")
112                 sendPush(msg)
113         }
114         if (phone) {
115                 log.debug("sending text message")
116                 sendSms(phone, msg)
117         }
118
119         log.debug msg
120 }