cli-example-nodejs icon indicating copy to clipboard operation
cli-example-nodejs copied to clipboard

Status / Events

Open mschwartz opened this issue 6 years ago • 1 comments

Thanks for this.

What ideally should be added is a demo of how to watch devices to see when their state changes.

I'm not fully versed in the API yet, but it looks like you have to poll each device? If so, any rate limiting would kick in pretty quick (or you have some massive lag in updating your UI).

Ideally, this demo (cli-example-nodejs) would have a "monitor" command. When you run sthelper monitor the program would sit there waiting for you to turn on/off switches (etc.). If I go to the wall switch and turn it on, the program would print "Kitchen Lights On". If I turn the switch off, the program would print "Kitchen Lights Off." If I use the SmartThings App to turn on the lights, the running sthelper would print "Kitchen Lights On" and so on.

There really should be a websocket capability to receive a stream of notifications for the device state changes (on connection, all device states would be sent). Otherwise, my home has 30 smartthings devices and to poll for 30 things with a 60/second limit would mean very infrequent polling of each device (and a lot of network overhead for the polling).

The Nest developer API uses EventSource, which is perfect for this application.

https://developer.mozilla.org/en-US/docs/Web/API/EventSource

I don't want to implement a full blown SmartApp - I just want to use the personal token and REST API like this demo uses. I absolutely do not want to run an HTTP server open to the internet on my home network so SmartThings cloud can post to it. Seems silly that I already have a device that's open to the Internet talking to SmartThings cloud - the SmartThings hub itself.

mschwartz avatar Feb 21 '19 01:02 mschwartz

The CLI example, when you get all device status, does 30 or 50 or 200 (depends on how many things are connected to your hub) single device status API calls. Instant flood/rate limit.

mschwartz avatar Feb 21 '19 01:02 mschwartz