Hi all,
I am looking at the subscription endpoint for the SmartThings SDK.
On line 299 the subscribeToDevices
method is declared which takes 5 inputs, the comments above the method describe it and the inputs (Have copied them below just for ease of reference)
/**
* Creates device event subscriptions for one or more devices specified in a SmartApp device configuration setting.
* This method is intended for use from SmartApps or API Access apps and must be called from a client configured
* with an installedAppId. Use the create() method if the client is not
* so configured.
* @param devices a SmartApp device configuration setting configured with one or more devices
* @param capability alphanumeric ID of the capability to subscribe to or '*' to subscribed to all capabilities of
* the devices
* @param attribute string defining what attribute(s) and attribute value(s) to subscribe to. Specifying an attribute
* name such as 'switch' subscribed to all values of the switch attribute. Specifying a name.value string such as
* 'switch.on' subscribed to only the on values of the switch. Specifying the wildcard '*' subscribes to all
* values of all attributes of the capability.
* @param subscriptionName the alphanumeric subscription name
* @param options map of options, stateChange only a modes. If not stateChangeOnly is not specified the default
* is true. If modes is not specified then events are sent for all modes.
*/
My question is on the first input parameter devices
which is described as:
@param devices a SmartApp device configuration setting configured with one or more devices
What would this input if I wanted to subscribe to a device but have not set it up in the SmartApp device configuration
I can get the devices listed out using the devices but now I want to be able to be able to subscribe to particular devices.
router.get('/callback', async function (req, res, next) {
try{
// Will verify the refresh and retrieve resfresh and
const ctx = await smartapp.handleOAuthCallback(req)
// Remove any existing subscriptions and unsubscribe to device switch events
// To see the endpoints look here https://github.com/SmartThingsCommunity/smartthings-core-sdk/tree/master/src/endpoint
await ctx.api.subscriptions.unsubscribeAll()
let devices = await (ctx.api.devices.list())
console.log(devices)
}catch(error){
console.error(error)
}
The output from console.log(devices)
is an array of my devices. Taking just one of the elements from this array shown below, what information from it should I pass (if any) as the
parameter devices
for the subscribeToDevices
function?
{
deviceId: 'f3e720c5-665f-4328-8e1f-618a771863d1',
name: 'Qubino Energy Monitor',
label: 'Meter1',
manufacturerName: 'SmartThingsCommunity',
presentationId: 'SmartThings-smartthings-Test_Meter',
deviceManufacturerCode: '0159-0007-0052',
locationId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
roomId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
deviceTypeId: '179c4492-1189-4629-8d88-c6577b0c221b',
deviceTypeName: 'Test Meter',
deviceNetworkType: 'ZWAVE',
components: [ [Object] ],
dth: {
deviceTypeId: '179c4492-1189-4629-8d88-c6577b0c221b',
deviceTypeName: 'Test Meter',
deviceNetworkType: 'ZWAVE',
completedSetup: true,
networkSecurityLevel: 'ZWAVE_S2_AUTHENTICATED',
hubId: 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
executingLocally: false
},
type: 'DTH',
restrictionTier: 0
}
EDIT
Just to clarify a bit more what I am trying to do. I can currently subscribe to an individual capability of the device. For example the code below subscribes to the voltageMeasurement
of the device listed above.
await ctx.api.subscriptions.subscribeToCapability('voltageMeasurement', '*', 'voltageHandler');
Instead of subscribing to each capability individually it would be nice to have one subscription which subscribes to the entire device as it updates all its sensory capabilities at the same time.