Get Device Status Update From API Call Without Page Refresh

Ok, so I have been searching and searching and I don’t see this question asked anywhere else. Right now I am building out an Angular app similar to ActionTiles/SharpTools. I have a connection to the SmartThings API and I am able to hit the API to get the devices state successfully like so:

  getSmartThingsDeviceState(deviceId: string): Observable<any>{

      const deviceUrl = `https://api.smartthings.com/v1/devices/${deviceId}/status`;

      const smartThingsStorage = JSON.parse(localStorage.getItem('SmartThings'));
      const smartThingsAuth = `Bearer ${smartThingsStorage.accessToken}`;

      const options = {
        headers: {
          Authorization: smartThingsAuth,
          'Content-Type': 'application/json',
          Accept: 'application/json',
        },
      };

      return this.http.get(deviceUrl, options);
   } 

Unfortunately I am a little unsure how to keep a connection open so that when a device updates in the SmartThings app my app will update with that devices status (ex. a light getting turned on/off). I see this is possible in other apps but am not sure exactly how they are achieving this. I am pretty sure its not polling as this would get very expensive very quick.

Anyone have any ideas on how this is done? Any help would be greatly appreciated. Thanks.

Also one last important bit of information, I created my app using the API Access option in the developer workspace.

It doesn’t work quite like what you describe, but I think what you want to look at is smartapp subscriptions

You are absolutely right. I wish you would have found this a few days ago. You would have saved me a ton of pain :smiley: . I now finally have it working after a ton of searching and prodding.

Thanks though Tony, your answer is absolutely correct. Subscriptions are definitely what I was looking for.

Yes, Subscriptions were the solution, thanks, @TonyFleisher.
Here’s the summary in case anyone else is interested:

  • This is an API Access app, also known as OAuth Integration.
  • When the user authorizes this app, the Access Token and InstalledAppId are granted.
  • Subscriptions are linked to an InstalledAppId so, you can create them using this value.
  • To receive the Subscription events, you need to assign a Target URL in your API Access project (Developer Workspace) and save it.
    You’ll receive a Confirmation URL (part of the “Confirmation” Lifecycle). As with the SmartApps, you need to paste that URL in a browser, click enter and the response should be the TargetURL value (this means confirmation was successful). This step is essential, otherwise, the events won’t be received

@Joseph_Alvini, please, remember to mark the post that helped you as “Solution” in this thread. Thanks! :wink: