Hi SmartThings Community,
I’m encountering an issue while setting lock codes using the SmartThings CLI and API. Here’s the situation:
I use the following command to set a code for a specific slot:
const command = {
component: 'main',
capability: 'lockCodes',
command: 'setCode',
arguments: [slot, code, name],
};
await client.devices.executeCommand(stDeviceUuid, command);
If the codePin I’m trying to set is already in use for another slot, the API response returns a 200
status with the message “ACCEPTED.” However, when I check the SmartThings account, I see that the lock code appears in another slot, but with a status of “failed,” indicating the operation wasn’t successful.
Here’s the webhook event I receive in response:
{
"event": {
"eventTime": "2024-12-02T13:08:55Z",
"eventType": "DEVICE_EVENT",
"deviceEvent": {
"eventId": "95e14029-b0ae-11ef-a59b-73b611cd0233",
"locationId": "b8061385-4f6c-4597-bfd4-084e6ec6a1a5",
"ownerId": "b8061385-4f6c-4597-bfd4-084e6ec6a1a5",
"ownerType": "LOCATION",
"deviceId": "127cf400-e486-4889-a8a5-31caa15b1cbd",
"componentId": "main",
"capability": "lockCodes",
"attribute": "codeChanged",
"value": "1 failed",
"valueType": "string",
"stateChange": true,
"data": {},
"subscriptionName": "deviceCodeChanged"
}
}
}
My Questions:
- Is there a way to pass custom metadata when using the
setCode
command so I can track additional context in the webhook event? - Can I fetch more details about the failure using the
eventId
provided in the webhook event? - What is the best way to handle duplicate
codePin
errors programmatically, given the current API behavior?
Thanks in advance for any insights!