mirror of
https://github.com/mtan93/SmartThingsPublic.git
synced 2026-03-16 21:03:28 +00:00
Compare commits
1 Commits
test-10
...
MSA-1718-1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
363f438bbf |
@@ -1,253 +1,548 @@
|
|||||||
/**
|
/**
|
||||||
* Gideon
|
* Gideon
|
||||||
*
|
*
|
||||||
* Copyright 2016 Nicola Russo
|
* Copyright 2016 Nicola Russo
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License. You may obtain a copy of the License at:
|
* in compliance with the License. You may obtain a copy of the License at:
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
|
||||||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
|
||||||
* for the specific language governing permissions and limitations under the License.
|
* for the specific language governing permissions and limitations under the License.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
definition(
|
definition(
|
||||||
name: "Gideon",
|
name: "Gideon",
|
||||||
namespace: "gideon.api",
|
namespace: "gideon.api",
|
||||||
author: "Braindrain Solutions",
|
author: "Braindrain Solutions ltd",
|
||||||
description: "Gideon AI Smart app allows you to connect and control all of your SmartThings devices through the Gideon AI app, making your SmartThings devices even smarter.",
|
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.",
|
||||||
category: "Family",
|
category: "Family",
|
||||||
iconUrl: "http://s33.postimg.org/t77u7y7v3/logo.png",
|
iconUrl: "http://s33.postimg.org/t77u7y7v3/logo.png",
|
||||||
iconX2Url: "http://s33.postimg.org/t77u7y7v3/logo.png",
|
iconX2Url: "http://s33.postimg.org/t77u7y7v3/logo.png",
|
||||||
iconX3Url: "http://s33.postimg.org/t77u7y7v3/logo.png",
|
iconX3Url: "http://s33.postimg.org/t77u7y7v3/logo.png",
|
||||||
oauth: [displayName: "Gideon AI API", displayLink: "gideon.ai"])
|
oauth: [displayName: "Gideon Smart Home API app", displayLink: "gideon.ai"])
|
||||||
|
|
||||||
|
|
||||||
preferences {
|
preferences {
|
||||||
section("Control these switches...") {
|
section("Control these contact sensors...") {
|
||||||
input "switches", "capability.switch", multiple:true
|
input "contact", "capability.contactSensor", multiple:true, required:false
|
||||||
}
|
}
|
||||||
section("Control these motion sensors...") {
|
section("Control these switches...") {
|
||||||
input "motions", "capability.motionSensor", multiple:true
|
input "switches", "capability.switch", multiple:true, required:false
|
||||||
}
|
}
|
||||||
section("Control these presence sensors...") {
|
section("Control these smoke alarms...") {
|
||||||
input "presence_sensors", "capability.presenceSensor", multiple:true
|
input "smoke_alarms", "capability.smokeDetector", multiple:true, required:false
|
||||||
}
|
}
|
||||||
section("Control these outlets...") {
|
section("Control these window shades...") {
|
||||||
input "outlets", "capability.switch", multiple:true
|
input "shades", "capability.windowShade", multiple:true, required:false
|
||||||
}
|
}
|
||||||
section("Control these locks...") {
|
section("Control these garage doors...") {
|
||||||
input "locks", "capability.lock", multiple:true
|
input "garage", "capability.garageDoorControl", multiple:true, required:false
|
||||||
}
|
}
|
||||||
section("Control these locks...") {
|
section("Control these water sensors...") {
|
||||||
input "temperature_sensors", "capability.temperatureMeasurement"
|
input "water_sensors", "capability.waterSensor", multiple:true, required:false
|
||||||
}
|
}
|
||||||
}
|
section("Control these motion sensors...") {
|
||||||
|
input "motions", "capability.motionSensor", multiple:true, required:false
|
||||||
def installed() {
|
}
|
||||||
log.debug "Installed with settings: ${settings}"
|
section("Control these presence sensors...") {
|
||||||
|
input "presence_sensors", "capability.presenceSensor", multiple:true, required:false
|
||||||
initialize()
|
}
|
||||||
}
|
/** section("Control these outlets...") {
|
||||||
|
input "outlets", "capability.switch", multiple:true, required:false
|
||||||
def updated() {
|
}
|
||||||
log.debug "Updated with settings: ${settings}"
|
*/
|
||||||
|
section("Control these power meters...") {
|
||||||
unsubscribe()
|
input "meters", "capability.powerMeter", multiple:true, required:false
|
||||||
initialize()
|
}
|
||||||
}
|
section("Control these locks...") {
|
||||||
|
input "locks", "capability.lock", multiple:true, required:false
|
||||||
def initialize() {
|
}
|
||||||
// TODO: subscribe to attributes, devices, locations, etc.
|
section("Control these temperature sensors...") {
|
||||||
subscribe(outlet, "energy", outletHandler)
|
input "temperature_sensors", "capability.temperatureMeasurement", multiple:true, required:false
|
||||||
subscribe(outlet, "switch", outletHandler)
|
}
|
||||||
}
|
section("Control these batteries...") {
|
||||||
|
input "batteries", "capability.battery", multiple:true, required:false
|
||||||
// TODO: implement event handlers
|
}
|
||||||
def outletHandler(evt) {
|
}
|
||||||
log.debug "$outlet.currentEnergy"
|
|
||||||
//TODO call G API
|
def installed() {
|
||||||
}
|
log.debug "Installed with settings: ${settings}"
|
||||||
|
|
||||||
|
initialize()
|
||||||
private device(it, type) {
|
}
|
||||||
it ? [id: it.id, label: it.label, type: type] : null
|
|
||||||
}
|
def updated() {
|
||||||
|
log.debug "Updated with settings: ${settings}"
|
||||||
//API Mapping
|
|
||||||
mappings {
|
unsubscribe()
|
||||||
path("/getalldevices") {
|
initialize()
|
||||||
action: [
|
}
|
||||||
GET: "getAllDevices"
|
|
||||||
]
|
def initialize() {
|
||||||
}
|
}
|
||||||
path("/doorlocks/:id/:command") {
|
|
||||||
action: [
|
private device(it, type) {
|
||||||
GET: "updateDoorLock"
|
it ? [id: it.id, label: it.label, type: type] : null
|
||||||
]
|
}
|
||||||
}
|
|
||||||
path("/doorlocks/:id") {
|
//API Mapping
|
||||||
action: [
|
mappings {
|
||||||
GET: "getDoorLockStatus"
|
path("/getalldevices") {
|
||||||
]
|
action: [
|
||||||
}
|
GET: "getAllDevices"
|
||||||
path("/tempsensors/:id") {
|
]
|
||||||
action: [
|
}
|
||||||
GET: "getTempSensorsStatus"
|
path("/doorlocks/lock/:id") {
|
||||||
]
|
action: [
|
||||||
}
|
GET: "lockDoorLock"
|
||||||
path("/presences/:id") {
|
]
|
||||||
action: [
|
}
|
||||||
GET: "getPresenceStatus"
|
path("/doorlocks/unlock/:id") {
|
||||||
]
|
action: [
|
||||||
}
|
GET: "unlockDoorLock"
|
||||||
path("/motions/:id") {
|
]
|
||||||
action: [
|
}
|
||||||
GET: "getMotionStatus"
|
path("/doorlocks/:id") {
|
||||||
]
|
action: [
|
||||||
}
|
GET: "getDoorLockStatus"
|
||||||
path("/outlets/:id") {
|
]
|
||||||
action: [
|
}
|
||||||
GET: "getOutletStatus"
|
path("/contacts/:id") {
|
||||||
]
|
action: [
|
||||||
}
|
GET: "getContactStatus"
|
||||||
path("/outlets/:id/:command") {
|
]
|
||||||
action: [
|
}
|
||||||
GET: "updateOutlet"
|
path("/smoke/:id") {
|
||||||
]
|
action: [
|
||||||
}
|
GET: "getSmokeStatus"
|
||||||
path("/switches/:command") {
|
]
|
||||||
action: [
|
}
|
||||||
PUT: "updateSwitch"
|
path("/shades/open/:id") {
|
||||||
]
|
action: [
|
||||||
}
|
GET: "openShade"
|
||||||
}
|
]
|
||||||
|
}
|
||||||
//API Methods
|
path("/shades/preset/:id") {
|
||||||
def getAllDevices() {
|
action: [
|
||||||
def locks_list = locks.collect{device(it,"Lock")}
|
GET: "presetShade"
|
||||||
def presences_list = presence_sensors.collect{device(it,"Presence")}
|
]
|
||||||
def motions_list = motions.collect{device(it,"Motion")}
|
}
|
||||||
def outlets_list = outlets.collect{device(it,"Outlet")}
|
path("/shades/close/:id") {
|
||||||
def switches_list = switches.collect{device(it,"Switch")}
|
action: [
|
||||||
def temp_list = temperature_sensors.collect{device(it,"Temperature")}
|
GET: "closeShade"
|
||||||
return [Locks: locks_list, Presences: presences_list, Motions: motions_list, Outlets: outlets_list, Switches: switches_list, Temperatures: temp_list]
|
]
|
||||||
}
|
}
|
||||||
|
path("/shades/:id") {
|
||||||
//LOCKS
|
action: [
|
||||||
def getDoorLockStatus() {
|
GET: "getShadeStatus"
|
||||||
def device = locks.find { it.id == params.id }
|
]
|
||||||
if (!device) {
|
}
|
||||||
httpError(404, "Device not found")
|
path("/garage/open/:id") {
|
||||||
} else {
|
action: [
|
||||||
return [Device_state: device.currentValue('lock')]
|
GET: "openGarage"
|
||||||
}
|
]
|
||||||
}
|
}
|
||||||
|
path("/garage/close/:id") {
|
||||||
def updateDoorLock() {
|
action: [
|
||||||
def command = params.command
|
GET: "closeGarage"
|
||||||
def device = locks.find { it.id == params.id }
|
]
|
||||||
if (command){
|
}
|
||||||
if (!device) {
|
path("/garage/:id") {
|
||||||
httpError(404, "Device not found")
|
action: [
|
||||||
} else {
|
GET: "getGarageStatus"
|
||||||
if(command == "toggle")
|
]
|
||||||
{
|
}
|
||||||
if(device.currentValue('lock') == "locked")
|
path("/watersensors/:id") {
|
||||||
device.unlock();
|
action: [
|
||||||
else
|
GET: "getWaterSensorStatus"
|
||||||
device.lock();
|
]
|
||||||
|
}
|
||||||
return [Device_id: params.id, result_action: "200"]
|
path("/tempsensors/:id") {
|
||||||
}
|
action: [
|
||||||
}
|
GET: "getTempSensorsStatus"
|
||||||
}
|
]
|
||||||
}
|
}
|
||||||
|
path("/meters/:id") {
|
||||||
//PRESENCE
|
action: [
|
||||||
def getPresenceStatus() {
|
GET: "getMeterStatus"
|
||||||
|
]
|
||||||
def device = presence_sensors.find { it.id == params.id }
|
}
|
||||||
if (!device) {
|
path("/batteries/:id") {
|
||||||
httpError(404, "Device not found")
|
action: [
|
||||||
} else {
|
GET: "getBatteryStatus"
|
||||||
return [Device_state: device.currentValue('presence')]
|
]
|
||||||
}
|
}
|
||||||
}
|
path("/presences/:id") {
|
||||||
|
action: [
|
||||||
//MOTION
|
GET: "getPresenceStatus"
|
||||||
def getMotionStatus() {
|
]
|
||||||
|
}
|
||||||
def device = motions.find { it.id == params.id }
|
path("/motions/:id") {
|
||||||
if (!device) {
|
action: [
|
||||||
httpError(404, "Device not found")
|
GET: "getMotionStatus"
|
||||||
} else {
|
]
|
||||||
return [Device_state: device.currentValue('motion')]
|
}
|
||||||
}
|
/** path("/outlets/:id") {
|
||||||
}
|
action: [
|
||||||
|
GET: "getOutletStatus"
|
||||||
//OUTLET
|
]
|
||||||
def getOutletStatus() {
|
}
|
||||||
|
path("/outlets/turnon/:id") {
|
||||||
def device = outlets.find { it.id == params.id }
|
action: [
|
||||||
if (!device) {
|
GET: "turnOnOutlet"
|
||||||
httpError(404, "Device not found")
|
]
|
||||||
} else {
|
}
|
||||||
return [Device_state: device.currentSwitch, Current_watt: device.currentValue("energy")]
|
path("/outlets/turnoff/:id") {
|
||||||
}
|
action: [
|
||||||
}
|
GET: "turnOffOutlet"
|
||||||
|
]
|
||||||
def updateOutlet() {
|
}
|
||||||
|
*/
|
||||||
def command = params.command
|
path("/switches/turnon/:id") {
|
||||||
def device = outlets.find { it.id == params.id }
|
action: [
|
||||||
if (command){
|
GET: "turnOnSwitch"
|
||||||
if (!device) {
|
]
|
||||||
httpError(404, "Device not found")
|
}
|
||||||
} else {
|
path("/switches/turnoff/:id") {
|
||||||
if(command == "toggle")
|
action: [
|
||||||
{
|
GET: "turnOffSwitch"
|
||||||
if(device.currentSwitch == "on")
|
]
|
||||||
device.off();
|
}
|
||||||
else
|
path("/switches/:id") {
|
||||||
device.on();
|
action: [
|
||||||
|
GET: "getSwitchStatus"
|
||||||
return [Device_id: params.id, result_action: "200"]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
//API Methods
|
||||||
|
def getAllDevices() {
|
||||||
//SWITCH
|
def locks_list = locks.collect{device(it,"Lock")}
|
||||||
def updateSwitch() {
|
def contact_list = contact.collect{device(it,"Contact Sensor")}
|
||||||
def command = params.command
|
def smokes_list = smoke_alarms.collect{device(it,"Smoke Alarm")}
|
||||||
def device = switches.find { it.id == params.id }
|
def shades_list = shades.collect{device(it,"Window Shade")}
|
||||||
if (command){
|
def garage_list = garage.collect{device(it,"Garage Door")}
|
||||||
if (!device) {
|
def water_sensors_list = water_sensors.collect{device(it,"Water Sensor")}
|
||||||
httpError(404, "Device not found")
|
def presences_list = presence_sensors.collect{device(it,"Presence")}
|
||||||
} else {
|
def motions_list = motions.collect{device(it,"Motion")}
|
||||||
if(command == "toggle")
|
/** def outlets_list = outlets.collect{device(it,"Outlet")} */
|
||||||
{
|
def switches_list = switches.collect{device(it,"Switch")}
|
||||||
if(device.currentSwitch == "on")
|
def temp_list = temperature_sensors.collect{device(it,"Temperature")}
|
||||||
device.off();
|
def meters_list = meters.collect{device(it,"Power Meters")}
|
||||||
else
|
def battery_list = batteries.collect{device(it,"Batteries")}
|
||||||
device.on();
|
return 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
|
||||||
|
}
|
||||||
return [Device_id: params.id, result_action: "200"]
|
|
||||||
}
|
//contact sensors
|
||||||
}
|
def getContactStatus() {
|
||||||
}
|
def device = contact.find { it.id == params.id }
|
||||||
}
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
//TEMPERATURE
|
} else {
|
||||||
def getTempSensorsStatus() {
|
def args = getTempSensorsStatus(device.id)
|
||||||
|
return [Device_state: device.currentValue('contact')] + args
|
||||||
def device = temperature_sensors.find { it.id == params.id }
|
}
|
||||||
if (!device) {
|
}
|
||||||
httpError(404, "Device not found")
|
|
||||||
} else {
|
//smoke detectors
|
||||||
return [Device_state: device.currentValue('temperature')]
|
def getSmokeStatus() {
|
||||||
}
|
def device = smoke_alarms.find { it.id == params.id }
|
||||||
}
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
def bat = getBatteryStatus(device.id)
|
||||||
|
return [Device_state: device.currentValue('smoke')] + bat
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//garage
|
||||||
|
def getGarageStatus() {
|
||||||
|
def device = garage.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
return [Device_state: device.currentValue('door')]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def openGarage() {
|
||||||
|
def device = garage.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
|
||||||
|
device.open();
|
||||||
|
|
||||||
|
return [Device_id: params.id, result_action: "200"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def closeGarage() {
|
||||||
|
def device = garage.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
|
||||||
|
device.close();
|
||||||
|
|
||||||
|
return [Device_id: params.id, result_action: "200"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//shades
|
||||||
|
def getShadeStatus() {
|
||||||
|
def device = shades.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
return [Device_state: device.currentValue('windowShade')]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def openShade() {
|
||||||
|
def device = shades.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
|
||||||
|
device.open();
|
||||||
|
|
||||||
|
return [Device_id: params.id, result_action: "200"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def presetShade() {
|
||||||
|
def device = shades.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
|
||||||
|
device.presetPosition();
|
||||||
|
|
||||||
|
return [Device_id: params.id, result_action: "200"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def closeShade() {
|
||||||
|
def device = shades.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
|
||||||
|
device.close();
|
||||||
|
|
||||||
|
return [Device_id: params.id, result_action: "200"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//water sensor
|
||||||
|
def getWaterSensorStatus() {
|
||||||
|
def device = water_sensors.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
def bat = getBatteryStatus(device.id)
|
||||||
|
return [Device_state: device.currentValue('water')] + bat
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//batteries
|
||||||
|
def getBatteryStatus() {
|
||||||
|
def device = batteries.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
return [Device_state: device.latestValue("battery")]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def getBatteryStatus(id) {
|
||||||
|
def device = batteries.find { it.id == id }
|
||||||
|
if (!device) {
|
||||||
|
return []
|
||||||
|
} else {
|
||||||
|
return [battery_state: device.latestValue("battery")]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//LOCKS
|
||||||
|
def getDoorLockStatus() {
|
||||||
|
def device = locks.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
def bat = getBatteryStatus(device.id)
|
||||||
|
return [Device_state: device.currentValue('lock')] + bat
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def lockDoorLock() {
|
||||||
|
def device = locks.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
|
||||||
|
device.lock();
|
||||||
|
|
||||||
|
return [Device_id: params.id, result_action: "200"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def unlockDoorLock() {
|
||||||
|
def device = locks.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
|
||||||
|
device.unlock();
|
||||||
|
|
||||||
|
return [Device_id: params.id, result_action: "200"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//PRESENCE
|
||||||
|
def getPresenceStatus() {
|
||||||
|
|
||||||
|
def device = presence_sensors.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
def bat = getBatteryStatus(device.id)
|
||||||
|
return [Device_state: device.currentValue('presence')] + bat
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//MOTION
|
||||||
|
def getMotionStatus() {
|
||||||
|
|
||||||
|
def device = motions.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
def args = getTempSensorsStatus(device.id)
|
||||||
|
return [Device_state: device.currentValue('motion')] + args
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//OUTLET
|
||||||
|
/**
|
||||||
|
def getOutletStatus() {
|
||||||
|
|
||||||
|
def device = outlets.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
def watt = getMeterStatus(device.id)
|
||||||
|
return [Device_state: device.currentSwitch] + watt
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
def getMeterStatus() {
|
||||||
|
|
||||||
|
def device = meters.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
return [Device_id: device.id, Device_type: device.type, Current_watt: device.currentValue("power")]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def getMeterStatus(id) {
|
||||||
|
|
||||||
|
def device = meters.find { it.id == id }
|
||||||
|
if (!device) {
|
||||||
|
return []
|
||||||
|
} else {
|
||||||
|
return [Current_watt: device.currentValue("power")]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
def turnOnOutlet() {
|
||||||
|
def device = outlets.find { it.id == params.id }
|
||||||
|
if (command){
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
|
||||||
|
device.on();
|
||||||
|
|
||||||
|
return [Device_id: params.id, result_action: "200"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def turnOffOutlet() {
|
||||||
|
def device = outlets.find { it.id == params.id }
|
||||||
|
if (command){
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
|
||||||
|
device.off();
|
||||||
|
|
||||||
|
return [Device_id: params.id, result_action: "200"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
//SWITCH
|
||||||
|
def getSwitchStatus() {
|
||||||
|
def device = switches.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
return [Device_state: device.currentValue('switch')]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def turnOnSwitch() {
|
||||||
|
def device = switches.find { it.id == params.id }
|
||||||
|
if (command){
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
|
||||||
|
device.on();
|
||||||
|
|
||||||
|
return [Device_id: params.id, result_action: "200"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def turnOffSwitch() {
|
||||||
|
def device = switches.find { it.id == params.id }
|
||||||
|
if (command){
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
|
||||||
|
device.on();
|
||||||
|
|
||||||
|
return [Device_id: params.id, result_action: "200"]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//TEMPERATURE
|
||||||
|
def getTempSensorsStatus() {
|
||||||
|
|
||||||
|
def device = temperature_sensors.find { it.id == params.id }
|
||||||
|
if (!device) {
|
||||||
|
httpError(404, "Device not found")
|
||||||
|
} else {
|
||||||
|
def bat = getBatteryStatus(device.id)
|
||||||
|
return [Device_state: device.currentValue('temperature')] + bat
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def getTempSensorsStatus(id) {
|
||||||
|
def device = temperature_sensors.find { it.id == id }
|
||||||
|
if (!device) {
|
||||||
|
return []
|
||||||
|
} else {
|
||||||
|
def bat = getBatteryStatus(device.id)
|
||||||
|
return [temperature: device.currentValue('temperature')] + bat
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user