I’ve written my first Device Type, and would welcome feedback and suggestions.
The code is here: https://github.com/cmeans/SmartThings/blob/master/devicetypes/ComEd-Rate-Meter/rate_meter.groovy
The API it consumes is documented here (and there are no restrictions on its use): https://hourlypricing.comed.com/hp-api/
If you use Commonwealth Edison Residential Real Time Pricing then the rate you pay per kWh varies constantly based upon demand. This device will monitor the changes in that rate, and allow you to use it as a trigger to turn off other devices, send an alert or whatever.
I only purchased my SmartThings hub last week (was using another Kickstarter product, but it was not a friendly platform), so I’m very new at development in this space. I am a programmer by profession, so Groovy etc. is familiar, but obviously, all the extras that SmartThings bring will take me a while to learn.
The rate changes about every five minutes, so it would be nice to stay up on the changes, I’m unclear if my implementation is appropriate…I realize that I shouldn’t be polling too much.
I have noticed that I get the error:
java.util.concurrent.TimeoutException: Execution time exceeded 20 app execution seconds: 238188856992526
A lot…but the calls to the REST API do not take anywhere near that long.
I originally wrote this in NodeJS (it’s currently running on a Raspberry Pi 2), and it reports changes to IFTTT which then controls some Phillips Hue Lightstrips. I also have an Amazon Echo Skill (in certification) for a voice request version (just reports the current rate).
For this implementation…what have I done wrong what can I do better?