4 * Copyright 2016 Matthew Page
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 * in compliance with the License. You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
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. See the License
13 * for the specific language governing permissions and limitations under the License.
18 namespace: "com.gidjit.smartthings.hub",
19 author: "Matthew Page",
20 description: "Act as an endpoint so user's of Gidjit can quickly access and control their devices and execute routines. Users can do this quickly as Gidjit filters these actions based on their environment",
21 category: "Convenience",
22 iconUrl: "http://www.gidjit.com/appicon.png",
23 iconX2Url: "http://www.gidjit.com/appicon@2x.png",
24 iconX3Url: "http://www.gidjit.com/appicon@3x.png",
25 oauth: [displayName: "Gidjit", displayLink: "www.gidjit.com"])
28 // deviceAuthorization page is simply the devices to authorize
29 page(name: "deviceAuthorization", title: "Device Authorization", nextPage: "instructionPage",
30 install: false, uninstall: true) {
31 section ("Allow Gidjit to have access, thereby allowing you to quickly control and monitor your following devices. Privacy Policy can be found at http://priv.gidjit.com/privacy.html") {
32 input "switches", "capability.switch", title: "Control/Monitor your switches", multiple: true, required: false
33 input "thermostats", "capability.thermostat", title: "Control/Monitor your thermostats", multiple: true, required: false
34 input "windowShades", "capability.windowShade", title: "Control/Monitor your window shades", multiple: true, required: false //windowShade
38 page(name: "instructionPage", title: "Device Discovery", install: true) {
40 paragraph "Now the process is complete return to the Devices section of the Detected Screen. From there and you can add actions to each of your device panels, including launching SmartThings routines."
46 path("/structureinfo") {
51 path("/helloactions") {
56 path("/helloactions/:label") {
62 path("/switch/:id/:command") {
68 path("/thermostat/:id/:command") {
70 PUT: "updateThermostat"
74 path("/windowshade/:id/:command") {
76 PUT: "updateWindowShade"
79 path("/acquiredata/:id") {
88 log.debug "Installed with settings: ${settings}"
94 log.debug "Updated with settings: ${settings}"
101 // subscribe to attributes, devices, locations, etc.
104 def actions = location.helloHome?.getPhrases()*.label
110 def executeAction() {
111 def actions = location.helloHome?.getPhrases()*.label
112 def a = actions?.find() { it == params.label }
114 httpError(400, "invalid label $params.label")
117 location.helloHome?.execute(params.label)
119 /* this is the primary function called to query at the structure and its devices */
120 def structureInfo() { //list all devices
122 def currId = location.id
124 list[currId].name = location.name
125 list[currId].id = location.id
126 list[currId].temperatureScale = location.temperatureScale
127 list[currId].devices = [:]
131 return [id: it.id, name: it.displayName]
133 def newList = [id: it.id, name: it.displayName, suppCapab: it.capabilities.collect {
135 }, suppAttributes: it.supportedAttributes.collect {
137 }, suppCommands: it.supportedCommands.collect {
144 list[currId].devices[it.id] = setValues(it)
147 list[currId].devices[it.id] = setValues(it)
150 list[currId].devices[it.id] = setValues(it)
156 /* This function returns all of the current values of the specified Devices attributes */
160 httpError(400, "invalid id $params.id")
163 def dev = switches.find() { it.id == params.id } ?: windowShades.find() { it.id == params.id } ?:
164 thermostats.find() { it.id == params.id }
167 httpError(400, "invalid id $params.id")
170 def att = dev.supportedAttributes
172 resp[it.name] = dev.currentValue("$it.name")
177 void updateSwitch() {
178 // use the built-in request object to get the command parameter
179 def command = params.command
180 def sw = switches.find() { it.id == params.id }
182 httpError(400, "invalid id $params.id")
187 if ( sw.currentSwitch != "on" ) {
192 if ( sw.currentSwitch != "off" ) {
197 httpError(400, "$command is not a valid")
202 void updateThermostat() {
203 // use the built-in request object to get the command parameter
204 def command = params.command
205 def therm = thermostats.find() { it.id == params.id }
206 if (!therm || !command) {
207 httpError(400, "invalid id $params.id")
221 def passNumParamComm = [
222 "setHeatingSetpoint",
223 "setCoolingSetpoint",
225 def passStringParamComm = [
227 "setThermostatFanMode",
229 if (command in passComm) {
231 } else if (command in passNumParamComm && params.p1 && params.p1.isFloat()) {
232 therm."$command"(Float.parseFloat(params.p1))
233 } else if (command in passStringParamComm && params.p1) {
234 therm."$command"(params.p1)
236 httpError(400, "$command is not a valid command")
240 void updateWindowShade() {
241 // use the built-in request object to get the command parameter
242 def command = params.command
243 def ws = windowShades.find() { it.id == params.id }
244 if (!ws || !command) {
245 httpError(400, "invalid id $params.id")
253 if (command in passComm) {
256 httpError(400, "$command is not a valid command")
259 // TODO: implement event handlers