/** * aiwatch monitor * * Copyright 2015 SmartThings * * 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: * * 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 * 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. * */ definition( name: "aiwatch camera integration", namespace: "smartthings", author: "Ram Kuppusamy", description: "Add intelligent alerts to your camera using AI", category: "Convenience", iconUrl: "https://aiwatch.live/img/icons/apple-icon-60x60.png", iconX2Url: "https://aiwatch.live/img/icons/apple-icon-120x120.png", iconX3Url: "https://aiwatch.live/img/icons/apple-icon-180x180.png", oauth: [displayName: "aiwatch smartthings integration", displayLink: "https://aiwatch.live"]) preferences { section ("Allow external service to control these things...") { input "switches", "capability.switch", multiple: false, required: true } } mappings { path("/switches") { action: [ GET: "listSwitches" ] } path("/switches/:command") { action: [ PUT: "updateSwitches" ] } } // returns a list like // [[name: "kitchen lamp", value: "off"], [name: "bathroom", value: "on"]] def listSwitches() { def resp = [] switches.each { resp << [name: it.displayName, value: it.currentValue("switch")] } return resp } void updateSwitches() { // use the built-in request object to get the command parameter def command = params.command // all switches have the comand // execute the command on all switches // (note we can do this on the array - the command will be invoked on every element switch(command) { case "on": switches.on() log.debug "switch turned on" switches.off([delay: 5000]) log.debug "switch turned off" break case "off": switches.off() break default: httpError(400, "$command is not a valid command for all switches specified") } } def installed() {} def updated() {}