4 * Copyright 2016 Nicola Russo
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.
17 name: "Gideon Smart Home",
18 namespace: "gideon.api",
19 author: "Braindrain Solutions ltd",
20 description: "Gideon Smart Home SmartApp allows you to connect and control all of your SmartThings devices through the Gideon app, making your SmartThings devices even smarter.",
22 iconUrl: "http://s33.postimg.org/t77u7y7v3/logo.png",
23 iconX2Url: "http://s33.postimg.org/t77u7y7v3/logo.png",
24 iconX3Url: "http://s33.postimg.org/t77u7y7v3/logo.png",
25 oauth: [displayName: "Gideon Smart Home API app", displayLink: "gideon.ai"])
28 section("Control these contact sensors...") {
29 input "contact", "capability.contactSensor", multiple:true, required:false
31 section("Control these switch levels...") {
32 input "switchlevels", "capability.switchLevel", multiple:true, required:false
34 /* section("Control these thermostats...") {
35 input "thermostats", "capability.thermostat", multiple:true, required:false
37 section("Control the color for these devices...") {
38 input "colors", "capability.colorControl", multiple:true, required:false
40 section("Control the color temperature for these devices...") {
41 input "kelvin", "capability.colorTemperature", multiple:true, required:false
43 section("Control these switches...") {
44 input "switches", "capability.switch", multiple:true, required:false
46 section("Control these smoke alarms...") {
47 input "smoke_alarms", "capability.smokeDetector", multiple:true, required:false
49 section("Control these window shades...") {
50 input "shades", "capability.windowShade", multiple:true, required:false
52 section("Control these garage doors...") {
53 input "garage", "capability.garageDoorControl", multiple:true, required:false
55 section("Control these water sensors...") {
56 input "water_sensors", "capability.waterSensor", multiple:true, required:false
58 section("Control these motion sensors...") {
59 input "motions", "capability.motionSensor", multiple:true, required:false
61 section("Control these presence sensors...") {
62 input "presence_sensors", "capability.presenceSensor", multiple:true, required:false
64 section("Control these outlets...") {
65 input "outlets", "capability.outlet", multiple:true, required:false
67 section("Control these power meters...") {
68 input "meters", "capability.powerMeter", multiple:true, required:false
70 section("Control these locks...") {
71 input "locks", "capability.lock", multiple:true, required:false
73 section("Control these temperature sensors...") {
74 input "temperature_sensors", "capability.temperatureMeasurement", multiple:true, required:false
76 section("Control these batteries...") {
77 input "batteries", "capability.battery", multiple:true, required:false
83 path("/getalldevices") {
89 path("/thermostat/setcool/:id/:temp") {
94 path("/thermostat/setheat/:id/:temp") {
99 path("/thermostat/setfanmode/:id/:mode") {
104 path("/thermostat/setmode/:id/:mode") {
106 GET: "setThermostatMode"
109 path("/thermostat/:id") {
111 GET: "getThermostatStatus"
115 path("/light/dim/:id/:dim") {
117 GET: "setLevelStatus"
120 path("/light/kelvin/:id/:kelvin") {
125 path("/colorlight/:id/:hue/:sat") {
130 path("/light/status/:id") {
132 GET: "getLightStatus"
135 path("/light/on/:id") {
140 path("/light/off/:id") {
145 path("/doorlocks/lock/:id") {
150 path("/doorlocks/unlock/:id") {
152 GET: "unlockDoorLock"
155 path("/doorlocks/:id") {
157 GET: "getDoorLockStatus"
160 path("/contacts/:id") {
162 GET: "getContactStatus"
167 GET: "getSmokeStatus"
170 path("/shades/open/:id") {
175 path("/shades/preset/:id") {
180 path("/shades/close/:id") {
185 path("/shades/:id") {
187 GET: "getShadeStatus"
190 path("/garage/open/:id") {
195 path("/garage/close/:id") {
200 path("/garage/:id") {
202 GET: "getGarageStatus"
205 path("/watersensors/:id") {
207 GET: "getWaterSensorStatus"
210 path("/tempsensors/:id") {
212 GET: "getTempSensorsStatus"
215 path("/meters/:id") {
217 GET: "getMeterStatus"
220 path("/batteries/:id") {
222 GET: "getBatteryStatus"
225 path("/presences/:id") {
227 GET: "getPresenceStatus"
230 path("/motions/:id") {
232 GET: "getMotionStatus"
235 path("/outlets/:id") {
237 GET: "getOutletStatus"
240 path("/outlets/turnon/:id") {
245 path("/outlets/turnoff/:id") {
250 path("/switches/turnon/:id") {
255 path("/switches/turnoff/:id") {
260 path("/switches/:id") {
262 GET: "getSwitchStatus"
268 log.debug "Installed with settings: ${settings}"
274 log.debug "Updated with settings: ${settings}"
283 private device(it, type) {
284 it ? [id: it.id, label: it.label, type: type] : null
289 def getAllDevices() {
290 def locks_list = locks.collect{device(it,"Lock")}
291 /*def thermo_list = thermostats.collect{device(it,"Thermostat")}*/
292 def colors_list = colors.collect{device(it,"Color")}
293 def kelvin_list = kelvin.collect{device(it,"Kelvin")}
294 def contact_list = contact.collect{device(it,"Contact Sensor")}
295 def smokes_list = smoke_alarms.collect{device(it,"Smoke Alarm")}
296 def shades_list = shades.collect{device(it,"Window Shade")}
297 def garage_list = garage.collect{device(it,"Garage Door")}
298 def water_sensors_list = water_sensors.collect{device(it,"Water Sensor")}
299 def presences_list = presence_sensors.collect{device(it,"Presence")}
300 def motions_list = motions.collect{device(it,"Motion")}
301 def outlets_list = outlets.collect{device(it,"Outlet")}
302 def switches_list = switches.collect{device(it,"Switch")}
303 def switchlevels_list = switchlevels.collect{device(it,"Switch Level")}
304 def temp_list = temperature_sensors.collect{device(it,"Temperature")}
305 def meters_list = meters.collect{device(it,"Power Meters")}
306 def battery_list = batteries.collect{device(it,"Batteries")}
307 return outlets_list + kelvin_list + colors_list + switchlevels_list + smokes_list + contact_list + water_sensors_list + shades_list + garage_list + locks_list + presences_list + motions_list + switches_list + temp_list + meters_list + battery_list
312 def device = switches.find { it.id == params.id }
314 httpError(404, "Device not found")
318 return [Device_id: params.id, result_action: "200"]
323 def device = switches.find { it.id == params.id }
325 httpError(404, "Device not found")
329 return [Device_id: params.id, result_action: "200"]
333 def getLightStatus() {
334 def device = switches.find{ it.id == params.id }
336 httpError(404, "Device not found")
338 return [Status: device.currentValue('switch'), Dim: getLevelStatus(params.id), Color: getColorStatus(params.id), Kelvin: getKelvinStatus(params.id)]
344 def device = colors.find { it.id == params.id }
346 httpError(404, "Device not found")
349 def map = [hue:params.hue.toInteger(), saturation:params.sat.toInteger()]
351 device.setColor(map);
353 return [Device_id: params.id, result_action: "200"]
357 def getColorStatus(id) {
358 def device = colors.find { it.id == id }
360 return [Color: "none"]
362 return [hue: device.currentValue('hue'), saturation: device.currentValue('saturation')]
368 def device = kelvin.find { it.id == params.id }
370 httpError(404, "Device not found")
373 device.setColorTemperature(params.kelvin.toInteger());
375 return [Device_id: params.id, result_action: "200"]
379 def getKelvinStatus(id) {
380 def device = kelvin.find { it.id == id }
382 return [kelvin: "none"]
384 return [kelvin: device.currentValue('colorTemperature')]
389 def getLevelStatus() {
390 def device = switchlevels.find { it.id == params.id }
394 return [Level: device.currentValue('level')]
398 def getLevelStatus(id) {
399 def device = switchlevels.find { it.id == id }
403 return [Level: device.currentValue('level')]
408 def setLevelStatus() {
409 def device = switchlevels.find { it.id == params.id }
410 def level = params.dim
412 httpError(404, "Device not found")
414 device.setLevel(level.toInteger())
415 return [result_action: "200", Level: device.currentValue('level')]
421 def getContactStatus() {
422 def device = contact.find { it.id == params.id }
424 httpError(404, "Device not found")
426 def args = getTempSensorsStatus(device.id)
427 return [Device_state: device.currentValue('contact')] + args
432 def getSmokeStatus() {
433 def device = smoke_alarms.find { it.id == params.id }
435 httpError(404, "Device not found")
437 def bat = getBatteryStatus(device.id)
438 return [Device_state: device.currentValue('smoke')] + bat
443 def getGarageStatus() {
444 def device = garage.find { it.id == params.id }
446 httpError(404, "Device not found")
448 return [Device_state: device.currentValue('door')]
453 def device = garage.find { it.id == params.id }
455 httpError(404, "Device not found")
460 return [Device_id: params.id, result_action: "200"]
465 def device = garage.find { it.id == params.id }
467 httpError(404, "Device not found")
472 return [Device_id: params.id, result_action: "200"]
476 def getShadeStatus() {
477 def device = shades.find { it.id == params.id }
479 httpError(404, "Device not found")
481 return [Device_state: device.currentValue('windowShade')]
486 def device = shades.find { it.id == params.id }
488 httpError(404, "Device not found")
493 return [Device_id: params.id, result_action: "200"]
498 def device = shades.find { it.id == params.id }
500 httpError(404, "Device not found")
503 device.presetPosition();
505 return [Device_id: params.id, result_action: "200"]
510 def device = shades.find { it.id == params.id }
512 httpError(404, "Device not found")
517 return [Device_id: params.id, result_action: "200"]
522 def getWaterSensorStatus() {
523 def device = water_sensors.find { it.id == params.id }
525 httpError(404, "Device not found")
527 def bat = getBatteryStatus(device.id)
528 return [Device_state: device.currentValue('water')] + bat
532 def getBatteryStatus() {
533 def device = batteries.find { it.id == params.id }
535 httpError(404, "Device not found")
537 return [Device_state: device.latestValue("battery")]
541 def getBatteryStatus(id) {
542 def device = batteries.find { it.id == id }
546 return [battery_state: device.latestValue("battery")]
551 def getDoorLockStatus() {
552 def device = locks.find { it.id == params.id }
554 httpError(404, "Device not found")
556 def bat = getBatteryStatus(device.id)
557 return [Device_state: device.currentValue('lock')] + bat
562 def device = locks.find { it.id == params.id }
564 httpError(404, "Device not found")
569 return [Device_id: params.id, result_action: "200"]
573 def unlockDoorLock() {
574 def device = locks.find { it.id == params.id }
576 httpError(404, "Device not found")
581 return [Device_id: params.id, result_action: "200"]
585 def getPresenceStatus() {
587 def device = presence_sensors.find { it.id == params.id }
589 httpError(404, "Device not found")
591 def bat = getBatteryStatus(device.id)
592 return [Device_state: device.currentValue('presence')] + bat
597 def getMotionStatus() {
599 def device = motions.find { it.id == params.id }
601 httpError(404, "Device not found")
603 def args = getTempSensorsStatus(device.id)
604 return [Device_state: device.currentValue('motion')] + args
609 def getOutletStatus() {
611 def device = outlets.find { it.id == params.id }
613 device = switches.find { it.id == params.id }
615 httpError(404, "Device not found")
618 def watt = getMeterStatus(device.id)
620 return [Device_state: device.currentValue('switch')] + watt
623 def getMeterStatus() {
625 def device = meters.find { it.id == params.id }
627 httpError(404, "Device not found")
629 return [Device_id: device.id, Device_type: device.type, Current_watt: device.currentValue("power")]
633 def getMeterStatus(id) {
635 def device = meters.find { it.id == id }
639 return [Current_watt: device.currentValue("power")]
645 def device = outlets.find { it.id == params.id }
647 device = switches.find { it.id == params.id }
649 httpError(404, "Device not found")
655 return [Device_id: params.id, result_action: "200"]
658 def turnOffOutlet() {
659 def device = outlets.find { it.id == params.id }
661 device = switches.find { it.id == params.id }
663 httpError(404, "Device not found")
669 return [Device_id: params.id, result_action: "200"]
673 def getSwitchStatus() {
674 def device = switches.find { it.id == params.id }
676 httpError(404, "Device not found")
678 return [Device_state: device.currentValue('switch'), Dim: getLevelStatus(params.id)]
683 def device = switches.find { it.id == params.id }
685 httpError(404, "Device not found")
690 return [Device_id: params.id, result_action: "200"]
694 def turnOffSwitch() {
695 def device = switches.find { it.id == params.id }
697 httpError(404, "Device not found")
702 return [Device_id: params.id, result_action: "200"]
708 def getTempSensorsStatus() {
709 def device = temperature_sensors.find { it.id == params.id }
711 httpError(404, "Device not found")
713 def bat = getBatteryStatus(device.id)
714 def scale = [Scale: location.temperatureScale]
715 return [Device_state: device.currentValue('temperature')] + scale + bat
719 def getTempSensorsStatus(id) {
720 def device = temperature_sensors.find { it.id == id }
724 def bat = getBatteryStatus(device.id)
725 return [temperature: device.currentValue('temperature')] + bat