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.