I see that the device’s API endpoint doesn’t come with online/offline status. Meaning that I am currently interating with devices and status api endpoints, which in the end makes things slow.
So my question is whether there would be a different method that could speed up things.
Did you come across the Health API? It doesn’t seem to make the API reference. No idea if it works, I just came across it in the maze that is the Developer docs.
Thanks. That’s exactly what I am using now. I call device endpoint and then iterate with the health api endpoint for each deviceId. Although this works for 10 or 20 devices setup, it becomes very slow for 200. Besides, I guess I would have problems with rate limits.
A workaround that I’d suggest you is developing a SmartApp Automation (no device selector needed) to get your devices list through the SmartThings API and then create Subscriptions for your devices.
This approach will help you to receive real-time Device Events if a device goes offline instead of scheduling health requests.
See the next example using the SmartApp NodeJS SDK to get the list of devices:
const SmartApp = require('@smartthings/smartapp');
const exampleDeviceMonitor = new SmartApp('Example Monitoring SmartApp')
.enableEventLogging(2)
.disableCustomDisplayName(true)
.appId('Example Monitoring SmartApp')
.permissions(['r:devices:*'])
.updated(async (context, updateData) => {
// Clear previous subscriptions to avoid API errors.
context.api.subscriptions.unsubscribeAll()
// List of devices
const myDevices = await context.api.devices.listAll()
// Here you can create subscriptions recursively
// following the Subscriptions documentation.
})
Note: SmartApp Automations are only available for self-publish.