Receive Pushed Events for Devices

Hoping to get some guidance. I have successfully connected to and been able to control devices using the SmartThings API. I know I can use the API to get the current state of the device, but does SmartThings offer a push event service that will send me an event/message when the device state has changed?

For example, when a TV is turned on. Instead of me hitting the API every second to get the state. Can I configure SmartThings to send me a push event through a webhook, mqtt or other method?

Thank you.
David

There is a subscription service that offers webhook calls, but it’s intended to be used with smartapps. Check out Subscriptions | Developer Documentation | SmartThings.

2 Likes

Thanks Bruce. This is were I was already going down and I created a webhook to my server and performed the validation steps. However I don’t see any traffic coming to the webhook after the validation step, so I am assuming that I need to somehow register the device(s) that I want to be informed about…

Hi, @David_Valencia
Did you create a subscription to such events?

In this tutorial, you can see how you can subscribe to a single device’s contactSensor event (open/close sensor) but there are other types of subscriptions as mentioned in the documentation posted by Bruce above.
In the Core-SDK you can see the functions you can call from the SmartApp SDK to create them: smartthings-core-sdk/src/endpoint/subscriptions.ts at main · SmartThingsCommunity/smartthings-core-sdk · GitHub

To validate which subscriptions were created by your SmartApp (and their configuration), you can call the endpoint https://api.smartthings.com/v1/installedapps/{installedAppId}/subscriptions using the installedAppId that you can see in the logs of your SmartApp. Also, the token for the request’s authorization can be the current one of the SmartApp (included in the logs) or your Personal Access Token.

Remember there’s a limit of 20 subscriptions per installed app so, if you want to receive the notification of events of more than 20 devices for the same capability, you can use a capability subscription instead.

2 Likes