Since my SmartThings scheduling hasn’t worked in the last 4 months, I’ve sort-of taken things into my own hands and created my own scheduling system. It’s basically a SmartApp from their OAuth tutorial - no frills. Then I have a script on my server that uses cron to run the script every miniute. Inside the script are a series of time’s where certain events trigger.
When I add a new device to the SmartApp for control, I have to go through some processes to find the device ID.
My question is: is it possible to control a device using the device name (or label)?
Here’s where I am at today:
I have my switches mappings like below:
path("/switches/:id/:command") {
action: [
GET: "updateSwitch",
]
}
Which calls this function (admittedly, I think I found this portion on GitHub not the tutorial, but the concept is the same):
// From the HTTP GET to update switch status
void updateSwitch() {
update(switches)
}
private void update(devices) {
log.debug "update, request: ${request.JSON}, params: ${params}, devices: $devices.id"
//def command = request.JSON?.command
def command = params.command
if (command)
{
command = command.toLowerCase()
def device = devices.find { it.id == params.id }
if (!device)
{
httpError(404, "Device not found")
}
else
{
device."$command"()
}
}
}
This way I can easily run https://graph.api.smartthings.com/api/smartapps/installations/my-smartapp-id/switches/My+Switch+Name+Here/on?access_token=my-access-token
Then I guess once I do find the device name, I would need to convert the name to the ID to do the controls?
Any tips are appreciated.