HAM Bridge can execute any script via Applescript, shell script, or Python, but most folks using it simply want a GET endpoint to their devices.
Understandable. That’s how we had it documented for a time, but we are trying to follow the best practice of having inbound change requests use the PUT method and storing the token in the header, rather than in the URL.
I suppose I have no problem with that, just show me how it works.
But note this complicates access for what I would guess is a lot of folks using things like iRule and Tasker. This is probably why IFTTT’s Maker channel uses GET.
So… you might want to rethink that. Ideally, we should have the choice to use either method.
Hey Jody…
Any traction on this?
I have not forgotten about you. Apologies for the delay, but I am still working on it.
Feels like you have…
Sorry for the delay.
Please see the source here:
Install the app and then enable oAuth in the settings. In the IDE, install the app in the simulator and grab the token and endpoint url.
You should be able to call yourEndpoint.ide.smartthings.com/api/smartapps/xxxxx-xxxx-xxxx--xxxx/devices/switches
Pass the token in the header with something like postman for google chrome. You will get a list of the switches that you have selected and the available commands.
PUT /devices/switches/xxxx-xxxx-xxxx-xxxx/off
PUT /devices/switches/xxxx-xxxx-xxxx-xxxx/on
while passing the token in the header.
-
Aren’t SmartApps supposed to explicitly check and allow only the Commands applicable to the Capability selector of the
inputpreferences? -
Isn’t this best done by just defining explicit Endpiont mappings, instead of having all the commands exposed as Endpoints.
-
Or, even better, shouldn’t the Platform only expose the appropriately authorized Command and Attribute Endpoints, since the Platform has mechanisms to know what the Device selection input filter is…?
Endpoints should not accept arbitrary commands. There is a check for supported commands. More explicit control of permissions might be required to get this published, but this a starter template that exposes everything in a sane way.
def listDeviceCommands() {
def type = params.deviceType
def id = params.id
def device = settings[type]?.find{it.id == id}
def result = []
if(!device) {
httpError(404, "Device not found")
} else {
device.supportedCommands?.each {
result << ["command" : it.name, "params" : [:]]
}
}
log.debug "Returning COMMANDS: $result"
result
}
Right… this code exposes ALL “supported commands”, not just those explicitly in the Capability the user was prompted with.
The U of M study example was that a “supported command” for a Lock Device includes lock(), unlock(), setLockPIN(), ..., even though this Device was selected as a part of a list filtered on Capability Battery (i.e., read-only Attribute battery).
What is “xxxxx-xxxx-xxxx–xxxx”
That is your installation ID. You can see find the full URL in the IDE Simulator, or from using the oAuth flow in postman.
So what is “yourEndpoint”? GET or PUT? What is the key for the token value? I assumed it was token, but am getting access denied.
The endpoint will be different depending on the server you are on.
if you look in the simulator you will see something like
API Endpoint: https://graph.api.smartthings.com/api/smartapps/installations/XXXXX-YOUR ID-XXXXX
Let’s go at this from another side. My endpoint is:
https://graph.api.smartthings.com/api/smartapps/installations/myID
given this, what is the url to get the list of devices?
GET
https://graph.api.smartthings.com/api/smartapps/installations/myID/devices
And the token is passed in the header
Actually, dont you mean:
https://graph.api.smartthings.com/api/smartapps/installations/myID/devices/switches
Not “https://graph.api.smartthings.com/api/smartapps/installations/myID/devices”
or whatever you meant by:
yourEndpoint.ide.smartthings.com/api/smartapps/myID/devices/switches
Anyway… I did successfully get the list with the first url above, but no available commands:
{
“id”: “a_device_ID”,
“name”: “Intermatic CA5100”,
“displayName”: “Amplifiers”
}
but executing:
PUT /api/smartapps/installations/myID/devices/switches/deviceID/on HTTP/1.1
Host: graph.api.smartthings.com
token: myTOKEN
Cache-Control: no-cache
returns:
{“error”:true,“type”:“SmartAppException”,“message”:“Not Found”}
After you get the list of devices, you need to query the individual device