Hey guys, I’m playing with my first app and I’ve used the below code and enabled OAuth.
When I go to http://unix.co.nz/smartthings.php it forwards me to Smartthings to Authorize devices, no matter what device I choose and click Authorize, i get the error “Please select at least one device to authorize”
Any help would be greatly appreciated.
preferences {
section("Allow Endpoint to Control These Things...") {
input "switches", "capability.switch", title: "Which Switches?", multiple: true
input "locks", "capability.lock", title: "Which Locks?", multiple: true
input "motions", "capability.motionSensor", title: "Which Motion Sensors?", multiple: true, required: false
input "temperature", "capability.temperatureMeasurement", title: "Which Temperature Sensors?", multiple: true, required: false
input "humidity", "capability.relativeHumidityMeasurement", title: "Which Humidity Sensors?", multiple: true, required: false
input "battery", "capability.battery", title: "Which Battery Sensors?", multiple: true, required: false
input "contact", "capability.contactSensor", title: "Which Contact Sensors?", multiple: true, required: false
}
}
mappings {
path("/switches") {
action: [
GET: "listSwitches"
]
}
path("/switches/:id") {
action: [
GET: "showSwitch"
]
}
path("/switches/:id/:command") {
action: [
GET: "updateSwitch"
]
}
path("/locks") {
action: [
GET: "listLocks"
]
}
path("/locks/:id") {
action: [
GET: "showLock"
]
}
path("/locks/:id/:command") {
action: [
GET: "updateLock"
]
}
}
def installed() {}
def updated() {}
//switches
def listSwitches() {
switches.collect{device(it,"switch")}
}
def showSwitch() {
show(switches, "switch")
}
void updateSwitch() {
update(switches)
}
//locks
def listLocks() {
locks.collect{device(it,"lock")}
}
def showLock() {
show(locks, "lock")
}
void updateLock() {
update(locks)
}
def deviceHandler(evt) {}
private void update(devices) {
log.debug "update, request: params: ${params}, devices: $devices.id"
//def command = request.JSON?.command
def command = params.command
//let's create a toggle option here
if (command)
{
def device = devices.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
} else {
if(command == "toggle")
{
if(device.currentValue('switch') == "on")
device.off();
else
device.on();
}
else
{
device."$command"()
}
}
}
}
private show(devices, type) {
def device = devices.find { it.id == params.id }
if (!device) {
httpError(404, "Device not found")
}
else {
def attributeName = type == "motionSensor" ? "motion" : type
def s = device.currentState(attributeName)
[id: device.id, label: device.displayName, value: s?.value, unitTime: s?.date?.time, type: type]
}
}
private device(it, type) {
it ? [id: it.id, label: it.label, type: type] : null
}