On the device side, the device must send sensor data to the SmartApp. I assume this is done with a device event (API | SmartThings Developers).
I would need an example or instructions on where to find the required object syntax.
value: object
Value associated with the event. The valid value depends on the capability.
data: object
Key value pairs about the state of the device. Valid values depend on the capability.
I think you use the terminology a little different to I do. To me the SmartApp and the Device are one and the same thing. so when, in that link, they say …
When a Device is managed by a SmartApp, the Device is responsible for creating events to update the Device attributes on the SmartThings Platform.
… I think it makes more sense if they say ‘the SmartApp is responsible for …’. It is the API equivalent of the old Groovy sendEvent or emitting an event in an Edge driver.
The details of each capability can be pulled from the API or read in a tarted up form (with links to the JSON) in the Capabilities Reference in the developer docs. In the most common cases the value object is a simple object like a string or number.
In our case, the device is cloud webhook. All communication is handled by http POST or GET commands. All our devices are first connected to our cloud. Our cloud handles all communication with the SmartThings/SmartApp.
We don’t use the SmartApp.
const SmartApp = require("@smartthings/smartapp");
Since we use the serverless services, I don’t think we can even use it.
Yes I understand. We just visualise a SmartApp differently. To me it is the app in your cloud that is communicating with SmartThings and managing your cloud connected devices.
In SmartThings device attributes, your sensor data, are updated using device events and for your cloud connected device those events are created using the API POST you referred to.
So for a simple device like a contact sensor you would do a POST
to https://api.smartthings.com/devices/{{deviceId}}/events
with the JSON body:
{
"deviceEvents": [
{
"component": "main",
"capability": "contactSensor",
"attribute": "contact",
"value": "open"
}
]
}
I don’t know why the API reference doesn’t include an example payload in this case.
1 Like
Thanks, I got this working.