Querying for contactSensor from external app, checking if door was open

Hi,
In external app I’m polling to get status of a device with a contactSensor.
https://api.smartthings.com/v1/devices/{{deviceID}}/status
I get something like this which is great.
“contact”: {
“value”: “open”,
“timestamp”: “2021-01-06T17:04:19.677Z”
}
I need to know if it was opened and then closed since the last poll. Otherwise it may open then close and by the time I poll again it will look like it never opened!

Short of polling every second is there anything I can do?

From the documentation, there is a limit of 20 subscriptions per smart app so I can’t use a subscription to push the door open event, as location may need more sensors than that.

Any ideas?
Thanks,
S

Hey, @sbarrett

Why don’t you subscribe specifically to the capability? If you’re using the SmartApp SDK, which implements the Core SDK, you can use this resouce at your SmartApp.

Check this output example (in my case, tested it with Switch):

{
  eventId: 'xxxx-xxxx-xxxxx-xxxx',
  locationId: 'xxxx-xxxx-xxxxx-xxxx',
  ownerId: 'xxxx-xxxx-xxxxx-xxxx',
  ownerType: 'LOCATION',
  deviceId: 'xxxx-xxxx-xxxxx-xxxx',
  componentId: 'main',
  capability: 'switch',
  attribute: 'switch',
  value: 'off',
  valueType: 'string',
  stateChange: true,
  data: {},
  subscriptionName: 'switchSub'
}

Hi Erick,
Thanks for the reply. That would be awesome.

From the documentation, though, I gather that a Smart App may have only 20 subscriptions.
Each device would take up one to subscribe to the capability.
We have more than 20 devices.

Perhaps I’m getting this wrong, I’m just starting with this.