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
82 log.debug "Installed with settings: ${settings}"
88 log.debug "Updated with settings: ${settings}"
97 private device(it, type) {
98 it ? [id: it.id, label: it.label, type: type] : null
103 path("/getalldevices") {
109 path("/thermostat/setcool/:id/:temp") {
114 path("/thermostat/setheat/:id/:temp") {
119 path("/thermostat/setfanmode/:id/:mode") {
124 path("/thermostat/setmode/:id/:mode") {
126 GET: "setThermostatMode"
129 path("/thermostat/:id") {
131 GET: "getThermostatStatus"
135 path("/light/dim/:id/:dim") {
137 GET: "setLevelStatus"
140 path("/light/kelvin/:id/:kelvin") {
145 path("/colorlight/:id/:hue/:sat") {
150 path("/light/status/:id") {
152 GET: "getLightStatus"
155 path("/light/on/:id") {
160 path("/light/off/:id") {
165 path("/doorlocks/lock/:id") {
170 path("/doorlocks/unlock/:id") {
172 GET: "unlockDoorLock"
175 path("/doorlocks/:id") {
177 GET: "getDoorLockStatus"
180 path("/contacts/:id") {
182 GET: "getContactStatus"
187 GET: "getSmokeStatus"
190 path("/shades/open/:id") {
195 path("/shades/preset/:id") {
200 path("/shades/close/:id") {
205 path("/shades/:id") {
207 GET: "getShadeStatus"
210 path("/garage/open/:id") {
215 path("/garage/close/:id") {
220 path("/garage/:id") {
222 GET: "getGarageStatus"
225 path("/watersensors/:id") {
227 GET: "getWaterSensorStatus"
230 path("/tempsensors/:id") {
232 GET: "getTempSensorsStatus"
235 path("/meters/:id") {
237 GET: "getMeterStatus"
240 path("/batteries/:id") {
242 GET: "getBatteryStatus"
245 path("/presences/:id") {
247 GET: "getPresenceStatus"
250 path("/motions/:id") {
252 GET: "getMotionStatus"
255 path("/outlets/:id") {
257 GET: "getOutletStatus"
260 path("/outlets/turnon/:id") {
265 path("/outlets/turnoff/:id") {
270 path("/switches/turnon/:id") {
275 path("/switches/turnoff/:id") {
280 path("/switches/:id") {
282 GET: "getSwitchStatus"
288 def getAllDevices() {
289 def locks_list = locks.collect{device(it,"Lock")}
290 /*def thermo_list = thermostats.collect{device(it,"Thermostat")}*/
291 def colors_list = colors.collect{device(it,"Color")}
292 def kelvin_list = kelvin.collect{device(it,"Kelvin")}
293 def contact_list = contact.collect{device(it,"Contact Sensor")}
294 def smokes_list = smoke_alarms.collect{device(it,"Smoke Alarm")}
295 def shades_list = shades.collect{device(it,"Window Shade")}
296 def garage_list = garage.collect{device(it,"Garage Door")}
297 def water_sensors_list = water_sensors.collect{device(it,"Water Sensor")}
298 def presences_list = presence_sensors.collect{device(it,"Presence")}
299 def motions_list = motions.collect{device(it,"Motion")}
300 def outlets_list = outlets.collect{device(it,"Outlet")}
301 def switches_list = switches.collect{device(it,"Switch")}
302 def switchlevels_list = switchlevels.collect{device(it,"Switch Level")}
303 def temp_list = temperature_sensors.collect{device(it,"Temperature")}
304 def meters_list = meters.collect{device(it,"Power Meters")}
305 def battery_list = batteries.collect{device(it,"Batteries")}
306 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 = thermostats.find { it.id == params.id }
314 httpError(404, "Device not found")
316 if(device.hasCommand("setCoolingSetpoint")) {
317 device.setCoolingSetpoint(params.temp.toInteger());
318 return [result_action: "200"]
321 httpError(510, "Not supported!")
326 def device = thermostats.find { it.id == params.id }
328 httpError(404, "Device not found")
330 if(device.hasCommand("setHeatingSetpoint")) {
331 device.setHeatingSetpoint(params.temp.toInteger());
332 return [result_action: "200"]
335 httpError(510, "Not supported!")
340 def device = thermostats.find { it.id == params.id }
342 httpError(404, "Device not found")
344 if(device.hasCommand("setThermostatFanMode")) {
345 device.setThermostatFanMode(params.mode);
346 return [result_action: "200"]
349 httpError(510, "Not supported!")
353 def setThermostatMode() {
354 def device = thermostats.find { it.id == params.id }
356 httpError(404, "Device not found")
358 if(device.hasCommand("setThermostatMode")) {
359 device.setThermostatMode(params.mode);
360 return [result_action: "200"]
363 httpError(510, "Not supported!")
367 def getThermostatStatus() {
368 def device = thermostats.find{ it.id == params.id }
370 httpError(404, "Device not found")
372 return [ThermostatOperatingState: device.currentValue('thermostatOperatingState'), ThermostatSetpoint: device.currentValue('thermostatSetpoint'),
373 ThermostatFanMode: device.currentValue('thermostatFanMode'), ThermostatMode: device.currentValue('thermostatMode')]
379 def device = switches.find { it.id == params.id }
381 httpError(404, "Device not found")
385 return [Device_id: params.id, result_action: "200"]
390 def device = switches.find { it.id == params.id }
392 httpError(404, "Device not found")
396 return [Device_id: params.id, result_action: "200"]
400 def getLightStatus() {
401 def device = switches.find{ it.id == params.id }
403 httpError(404, "Device not found")
405 return [Status: device.currentValue('switch'), Dim: getLevelStatus(params.id), Color: getColorStatus(params.id), Kelvin: getKelvinStatus(params.id)]
411 def device = colors.find { it.id == params.id }
413 httpError(404, "Device not found")
416 def map = [hue:params.hue.toInteger(), saturation:params.sat.toInteger()]
418 device.setColor(map);
420 return [Device_id: params.id, result_action: "200"]
424 def getColorStatus(id) {
425 def device = colors.find { it.id == id }
427 return [Color: "none"]
429 return [hue: device.currentValue('hue'), saturation: device.currentValue('saturation')]
435 def device = kelvin.find { it.id == params.id }
437 httpError(404, "Device not found")
440 device.setColorTemperature(params.kelvin.toInteger());
442 return [Device_id: params.id, result_action: "200"]
446 def getKelvinStatus(id) {
447 def device = kelvin.find { it.id == id }
449 return [kelvin: "none"]
451 return [kelvin: device.currentValue('colorTemperature')]
456 def getLevelStatus() {
457 def device = switchlevels.find { it.id == params.id }
461 return [Level: device.currentValue('level')]
465 def getLevelStatus(id) {
466 def device = switchlevels.find { it.id == id }
470 return [Level: device.currentValue('level')]
475 def setLevelStatus() {
476 def device = switchlevels.find { it.id == params.id }
477 def level = params.dim
479 httpError(404, "Device not found")
481 device.setLevel(level.toInteger())
482 return [result_action: "200", Level: device.currentValue('level')]
488 def getContactStatus() {
489 def device = contact.find { it.id == params.id }
491 httpError(404, "Device not found")
493 def args = getTempSensorsStatus(device.id)
494 return [Device_state: device.currentValue('contact')] + args
499 def getSmokeStatus() {
500 def device = smoke_alarms.find { it.id == params.id }
502 httpError(404, "Device not found")
504 def bat = getBatteryStatus(device.id)
505 return [Device_state: device.currentValue('smoke')] + bat
510 def getGarageStatus() {
511 def device = garage.find { it.id == params.id }
513 httpError(404, "Device not found")
515 return [Device_state: device.currentValue('door')]
520 def device = garage.find { it.id == params.id }
522 httpError(404, "Device not found")
527 return [Device_id: params.id, result_action: "200"]
532 def device = garage.find { it.id == params.id }
534 httpError(404, "Device not found")
539 return [Device_id: params.id, result_action: "200"]
543 def getShadeStatus() {
544 def device = shades.find { it.id == params.id }
546 httpError(404, "Device not found")
548 return [Device_state: device.currentValue('windowShade')]
553 def device = shades.find { it.id == params.id }
555 httpError(404, "Device not found")
560 return [Device_id: params.id, result_action: "200"]
565 def device = shades.find { it.id == params.id }
567 httpError(404, "Device not found")
570 device.presetPosition();
572 return [Device_id: params.id, result_action: "200"]
577 def device = shades.find { it.id == params.id }
579 httpError(404, "Device not found")
584 return [Device_id: params.id, result_action: "200"]
589 def getWaterSensorStatus() {
590 def device = water_sensors.find { it.id == params.id }
592 httpError(404, "Device not found")
594 def bat = getBatteryStatus(device.id)
595 return [Device_state: device.currentValue('water')] + bat
599 def getBatteryStatus() {
600 def device = batteries.find { it.id == params.id }
602 httpError(404, "Device not found")
604 return [Device_state: device.latestValue("battery")]
608 def getBatteryStatus(id) {
609 def device = batteries.find { it.id == id }
613 return [battery_state: device.latestValue("battery")]
618 def getDoorLockStatus() {
619 def device = locks.find { it.id == params.id }
621 httpError(404, "Device not found")
623 def bat = getBatteryStatus(device.id)
624 return [Device_state: device.currentValue('lock')] + bat
629 def device = locks.find { it.id == params.id }
631 httpError(404, "Device not found")
636 return [Device_id: params.id, result_action: "200"]
640 def unlockDoorLock() {
641 def device = locks.find { it.id == params.id }
643 httpError(404, "Device not found")
648 return [Device_id: params.id, result_action: "200"]
652 def getPresenceStatus() {
654 def device = presence_sensors.find { it.id == params.id }
656 httpError(404, "Device not found")
658 def bat = getBatteryStatus(device.id)
659 return [Device_state: device.currentValue('presence')] + bat
664 def getMotionStatus() {
666 def device = motions.find { it.id == params.id }
668 httpError(404, "Device not found")
670 def args = getTempSensorsStatus(device.id)
671 return [Device_state: device.currentValue('motion')] + args
676 def getOutletStatus() {
678 def device = outlets.find { it.id == params.id }
680 device = switches.find { it.id == params.id }
682 httpError(404, "Device not found")
685 def watt = getMeterStatus(device.id)
687 return [Device_state: device.currentValue('switch')] + watt
690 def getMeterStatus() {
692 def device = meters.find { it.id == params.id }
694 httpError(404, "Device not found")
696 return [Device_id: device.id, Device_type: device.type, Current_watt: device.currentValue("power")]
700 def getMeterStatus(id) {
702 def device = meters.find { it.id == id }
706 return [Current_watt: device.currentValue("power")]
712 def device = outlets.find { it.id == params.id }
714 device = switches.find { it.id == params.id }
716 httpError(404, "Device not found")
722 return [Device_id: params.id, result_action: "200"]
725 def turnOffOutlet() {
726 def device = outlets.find { it.id == params.id }
728 device = switches.find { it.id == params.id }
730 httpError(404, "Device not found")
736 return [Device_id: params.id, result_action: "200"]
740 def getSwitchStatus() {
741 def device = switches.find { it.id == params.id }
743 httpError(404, "Device not found")
745 return [Device_state: device.currentValue('switch'), Dim: getLevelStatus(params.id)]
750 def device = switches.find { it.id == params.id }
752 httpError(404, "Device not found")
757 return [Device_id: params.id, result_action: "200"]
761 def turnOffSwitch() {
762 def device = switches.find { it.id == params.id }
764 httpError(404, "Device not found")
769 return [Device_id: params.id, result_action: "200"]
775 def getTempSensorsStatus() {
776 def device = temperature_sensors.find { it.id == params.id }
778 httpError(404, "Device not found")
780 def bat = getBatteryStatus(device.id)
781 def scale = [Scale: location.temperatureScale]
782 return [Device_state: device.currentValue('temperature')] + scale + bat
786 def getTempSensorsStatus(id) {
787 def device = temperature_sensors.find { it.id == id }
791 def bat = getBatteryStatus(device.id)
792 return [temperature: device.currentValue('temperature')] + bat