Automation for my device (for example, Blinds or HVAC) based on trigger from my SchemaApp

Hello,

I have a use case where I need to trigger a device(not from my C2C integration but in SmartThings ecosystem) from my SchemaApp when I receive a trigger to my SchemaApp from my cloud devices.

For example, When a person enters a room, my cloud SchemaApp will get event from the occupancy sensor and I need to turn on the HVAC or open the blinds.

Is there a way to do this?

Currently, I have SchemaApp up and running using a webhook and I can see my cloud devices in SmartThings App.

Would I need to do this using SmartThings API? If yes, is there an easy way to retrieve the SmartThings token? I was reading SmartThings API Help for tokens. Is this the only way to get tokens?

I tried the steps in the above link and could get the access token. Using that token, I can control the devices.

However, How do I get this token in background when I receive event from my sensor to control the device in my account but not added through the C2C integration without needing to login on a user interface. Can someone please help?

After reading a bit, I stumbled upon “grantCallbackAccess” interactionType which is sent only once during linking Schema App. I understand this sends a code and can be used to get the access and refresh token. Is this refresh token valid forever, so that I can keep using it to get access token every time I get event from my sensor to control HVAC?

@nayelyz Will you please confirm if this approach will work for my use case mentioned above?

Hi, @Divya_Nagarajan
Sorry we missed your post. Feel free to tag us for any questions regarding customization in the SmartThings platform.

So, if I understand you have two types of devices:

  1. One that is part of a Schema Connector that you developed (Occupancy sensor)
  2. A common device that is connected to the SmartThings platform through another integration (HVAC)

Is it correct?
Also, we need to clarify the following:

  1. There’s an Access Token (AKA Personal Access Token) that can be created on this website that can help you control all your devices and other things in your account, depending on the scopes selected.
    • This expires in 24 hours, and you need to enter the website to create a new one
  2. There’s a SmartApp (Webhook) or API_ONLY app Access Token, which also depending on the scopes, can help you control devices, create subscriptions, etc.
    • Here, you’ll get an Access Token which also expires in 24 hours and a refresh token that expires in 30 days (if not used)
    • The API_ONLY token is the one mentioned in the post you shared in the first post.
  3. There’s a Reciprocal Access Token (AKA Callback Access Token) that is only used for the devices discovered by the Schema Connector and to send status updates and the periodic discovery.
    • The Access Token also expires in 24 hours

The refresh token of a Schema Connector is valid until you delete the integration completely.

So, if you get an event of a person entering a room from the occupancy sensor in your Schema Connector, you just need to update the status of the corresponding capability.

The SmartThings app already offers a section to create automations based on device’s status, so you can use the occupancy sensor as the condition and send a command to your HVAC.

For more advanced automations, you can use the Rules API, the next step would be a SmartApp (Webhook app - for self-publish only) and API_ONLY apps are focused on third-party clouds which want to control other user’s devices but is also helpful for users who want an easy way of getting Access Tokens and Refreshing them.

Hi @nayelyz

Thank you for your reply. It clarifies a lot of aspects about tokens and saves our time in deciding he approach.

I am still contemplating if we should show occupancy sensor on SmartThings mainly because an end user cannot control it and may not want to see its status. I understand the solution with automation and will consider this.

However, in case we decide to not show the occupancy sensor on SmartThings and my Schema Connector receives a trigger from our cloud, what other options do we have if we want to control a device on SmartThings platform through another integration?

Hi, @Divya_Nagarajan
Based on your description, other questions came up:

  1. Are you working on an integration that you plan to share with other users? Meaning from an official Company and not for personal use
  2. Is the occupancy sensor a physical device or a service based on the user’s location?
    If the status of occupancy will be received from a service and not a physical device, then the approach shouldn’t be a Schema Connector, since this is only for IoT device integrations, which need to be certified to be available for other users.

If you’re handling the reception of the occupancy status, you could use an API_ONLY app to get an Access Token and be able to control the devices based on that status without having an extra device on the SmartThings side.

Also, something to note is that users can “hide devices” in case they don’t find useful seeing them in the ST app’s dashboard, but they still exist in the background.

Hi @nayelyz

To answer your questions,

Yes. I am working for my company and plan to share it with other users

Occupancy sensor is a physical device and we plan to show it in SmartThings app based on your suggestion in your earlier reply. So will use automation to catch the event and control another device on SmartThings platform

Will you please redirect me to a source where I can find reference to handle grantCallbackAccess in a Java code?
Thanks for all the help.

Hi, @Divya_Nagarajan
There are no samples using Java, but the documentation shows samples of the requests and responses of this interaction type.

Are you having issues receiving the requests?

@nayelyz I could finally get it working with automation and token obtained via grantCallbackAccess. Thanks for the information.