I have a physical Aeon Home Energy Monitor. SmartThings conveniently has a pretty good device handler for it, but I want to add some functionality to publish the separate clamp energy readings rather than a single clamp sum as the current device handler does. I created a new device handler via Template for the existing SmartThings Aeon HEM. Based on the pepper1 library entry for this device, I changed configure() to tell the HEM to report the sum of energy (same as it was before), plus energy for clamp 1 plus energy for clamp 2. Now I want to check my progress and see if that configuration change actually results in the physical HEM sending the desired updates. So, I add a log.debug message in parse() to print any incoming description. Now, how can I see that log statement print?
I can Install my new Device Handler from the editor IDE window and select my real Aeon HEM from the list of possible devices (which also includes a Virtual device), but then the log at the bottom of the screen never reports anything. I can edit my HEM device under My Devices and change its Type to the Draft version of my new device handler, but then I have no idea where to look to see the log.debug messages.
Using the published device handler, my HEM works fine – I get updates every 5 minutes for both power and energy. But, I can’t figure out how to go about doing development for device handlers. The documentation mentions the simulator for testing out certain functionality, but that seems almost worthless in this case since pretty much all device handler development would be with regard to interacting with the real hardware (and whether doing so works).
I personally find the simulator useless in almost all cases. I usually just open the device settings through the IDE and change the device type to the one I’m building. I make changes, publish them, and then test them on the actual device.
Disclaimer: If you’re changing the device’s configuration settings, it’s possible that you could make a mistake and put the device into a non-operational state. Usually if you switch back to the original DTH things will start working again and all the Aeon devices I’ve worked with have a way to factory reset them, but there are no guarantees.
Using log.debug like @desertblade mentioned is pretty much the only debugging tool that’s available. I rely on it heavily, but be aware that if you’re logging a lot of information in a short amount of time, some of it will probably get skipped or get logged in the wrong order.
The Groovy compiler lets a lot of things slide and that can lead to logic errors that are hard to troubleshoot so if something’s not working the way it’s supposed to, I usually use https://groovyconsole.appspot.com/.
It allows me to test the contents of a method using fixed values instead of trying to replicate the situation in SmartThings. It can’t be used to test anything specific to SmartThings or the device, but I still find it really useful.
If you post a link to the original DTH and post the changes you made, someone might be able to point out the problem.
I think I’m still missing something with regard to when and where I’m supposed to see the log messages.
Guess 1: When I’m editing my device handler, I can Set Location, select my physical HEM, and click Install. Now there’s a log at the bottom of the page, but I don’t see anything printed to it unless I send things via the simulator(?) controls on the right. Aside: if I’ve selected a real device in this view and I click “configure” in the right pane, is my configure() method executed and the commands sent to the real device, or somewhere else?
Guess 2: I can to go My Devices, Edit my real HEM, change the Type to the device handler I’m developing, select a Version, and then Update. Aside: which Version should I select, and what do they point to? The options are Draft, Self-Published, and Published. I’ve been selecting Draft and then just saving my device handler (not publishing) because if that works, it’d be nice to skip the publish step. Now my real device should be using the device handler I’m developing, but…what log window should I look in to see the output of the device handler? There is no log window in the My Devices selection.
Guess 3: I do everything in Option 2, and then also create a SmartApp which has a preference entry for capability.energyMeter which I then use my real HEM for when I run the simulator. Now there’s a log at the bottom of the screen again, but as far as I can tell, it only prints the log.debug statements in my SmartApp, and not the ones in my device handler. Aside: log printing seems to be asynchronous; with the code below, I see “Done with Initialize” first and “Initial energy is…” second.
def initialize() {
log.debug "Initial energy is $meter.currentEnergy, initial power is $meter.currentPower"
subscribe(meter, "energy", energyUpdateHandler)
log.debug "Done with initialize"
}
So: how do I get a log where my device handler’s log.debug statements will print while interacting with my real HEM?
Huh, that works now. Thought I had tried it, but apparently not the right way. I do get log messages from both my device handler and my SmartApp in Live Logging. Now to figure out why I’m not getting any messages from from my HEM… (but I’m not stuck any more; I’ll post again if I can’t figure that out )
Open up 2 (or more) tabs in your browser. Set one tab to the Device Handler page while the other tab to Live Logging page. This was you can have your DH code open and in edit mode all the time. Make your changes, save and publish then switch to the Logging tab to see the changes.