OpenGarage › Forums › Comments, Suggestions, Requests › Request: SmartThings Integration › Reply To: Request: SmartThings Integration
codahq
@lawrence_jeff Yes, it does. It is pretty simple to register a URL for events if the URL is hosted on the SmartThings platform. Apparently it gets a little harder when you try to have a local device make calls at the SmartThings hubs directly.
If you want to add something to the firmware that would be awesome. Here is some documentation here.
http://docs.smartthings.com/en/latest/smartapp-web-services-developers-guide/tutorial-part1.html
Essentially you would need to make a HTTP GET for each action to:
https://${baseUrl}/api/smartapps/installations/${app.id}/${action}?access_token=${state.accessToken}
The base URL will change depending on where you got hosted when you log into SmartThings first so it might be one of about 10 values. For example, mine is “graph-na02-useast1.api.smartthings.com” but my brother’s who lives only 30 miles away is different. The ${app.id} is the unique ID given to the SmartApp when it is setup in SmartThing’s API. This is different for every instance of the app. The action is whatever we decide we want to implement. I would suggest at a bare minimum we have a “open” and “close” action. ${state.accessToken} is an OAUTH token that you have to generate after installing the SmartApp.
Please note, I am calling this part of the SmartThings integration a SmartApp instead of a Device Handler because from what I understand you can’t do this type of thing in a Device Handler. I could be wrong on that but that’s the gist after looking at a view examples. Full disclaimer, I am not an expert at SmartThings on any level. My first experience writing code for the platform is for the OpenGarage. I know this will work though… I setup a quick example to make sure I could hit the API and change the statuses on a virtual device with the following SmartApp code. This was mostly taken from another example I found on the SmartThings forum and modified to work for our purposes.
/**
* OpenGarage SmartApp
*
* Copyright 2018 Ben Rimmasch
*
*/
definition(
name: "HTTP Open/Close Endpoint",
namespace: "me.bendy.opengarage",
author: "Ben Rimmasch",
description: "Creates an HTTP motion endpoint for your OpenGarage",
category: "Convenience",
iconUrl: "https://need.an.icon.com/badly.png",
iconX2Url: "https://need.an.icon.com/[email protected]"
)
preferences {
page(name: "selectDevices", install: false, uninstall: true, nextPage: "viewURL") {
section("Allow endpoint to control this thing...") {
input "og", "capability.doorControl", title: "Which door controller is the OpenGarage?", required: true
label title: "Assign a name", required: false
mode title: "Set for specific mode(s)", required: false
}
}
page(name: "viewURL", title: "viewURL", install: true)
}
def installed() {
log.debug "Installed with settings: ${settings}"
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
}
mappings {
path("/open") {
action: [
GET: "openAction"
]
}
path("/close") {
action: [
GET: "closeAction"
]
}
}
void openAction() {
log.debug "Updated with settings: ${settings}"
og?.open()
}
void closeAction() {
log.debug "Updated with settings: ${settings}"
og?.close()
}
def generateURL() {
createAccessToken()
["https://graph.api.smartthings.com/api/smartapps/installations/${app.id}/open", "?access_token=${state.accessToken}"]
}
def viewURL() {
dynamicPage(name: "viewURL", title: "HTTP Motion Endpoint", install:!resetOauth, nextPage: resetOauth ? "viewURL" : null) {
section() {
generateURL()
paragraph "Open: https://graph.api.smartthings.com/api/smartapps/installations/${app.id}/open?access_token=${state.accessToken}"
paragraph "Close: https://graph.api.smartthings.com/api/smartapps/installations/${app.id}/close?access_token=${state.accessToken}"
}
}
}