REST Web Service SmartApp and Power/Energy Metering

Kind ST Community:

I’ve spent several days now trying to self-service this question, and pored over many threads ranging from the Architecture documentation, completed the SmartApp Tutorial (and have a working instance of the sample REST Web Service SmartApp which lists and allows controls of switches – but I’m having real trouble making the leap from this working / documented example - to interfacing with the powerMeter and energyMeter capabilities available from several of my devices.

I’m using the AeoTec Smart Switch 6, the ZooZ ZEN06, AeoTec SmartStrip, etc - and would be stoked to make any of them work (e.g. expose a REST endpoint allowing me to poll the Energy/Power Metering functions.

I’ve installed and am successfully using relevant custom DTH’s for each of the above devices - and they’re working as expected when viewed in the SmartThings mobile app (meaning - I know the DTH is properly communicating with the device, and that the data is available). I can also see this by watching the LiveLogging in the IDE, and seeing the results from each device (volts, amps, watts, KwH) on the configured interval.

Where I’m tripped up is on the syntax. I’m not a coder, by trade - and definitely have no previous experience with Groovy. As I’m looking at the syntax in the sample Web Service SmartApp - I’m struggling to discern what might be standard Groovy syntax, and what might be “SmartThings convention” - specifically, for reading attributes like:

it.displayName or it.currentValue

I’d be happy to RTFM - if I could only find the right manual. I’ve pored over my GitHub repos than I care to admit, and have found multiple examples that are close to what I want - but with differences significant enough to throw me off the scent. One example achieved what I wanted, but published (pushed) events to an API, rather than exposing an API endpoint to query them, etc.

I’m certain that all the information I need is there - included in the DTH that I’m using (which describes all the capabilities, including:


as well as, device.power, etc. Yet, somehow - I’m missing the puzzle pieces (e.g. the specific syntax I would use in a SmartApp) to query / return these values.

I’m managed to modify the sample Web Services SmartApp enough such that, in the simulator (or mobile app) it will present me a list of my four devices which have (for example) PowerMeter capabilities. I can publish the app, select one (or more) of them, and see them in a list (in the Simulator) - but no clue as to the code required to query / respond with the powerMeter values.

I’m hoping I don’t have to get so deep down the rabbit hole as to have to grok the low-level Z-Wave commands, ala:

0x32 COMMAND_CLASS_METER V3 Implemented


zwaveEvent(physicalgraph.zwave.commands.meterv3.MeterReport cmd)

to achieve my goal - but if that’s what it takes, I’m ready to have a go. Would welcome / deeply appreciate any pointers to sample/example code, documentation, other forum threads, or anything which might help me on this journey. I can certainly share a link to / copy of my current (modified) Web Services Smart App, if that would prove helpful.

Thanks in advance for any guidance / hand-holding / 2x4 to the forehead,

Without being too snarky and nothing personal intended because this is a statement of my general bewilderment… Why is it that folks think it should only take “several days” to learn how to do incredibly powerful and complex stuff with SmartThings??? :confused: I’ve been around here for 5 years and cannot guarantee an answer to any development question; there is no “writing SmartApps for Dummies” book, and I seriously think that a college class for ST would be 2 full semesters… Or at least a $5,000 to $10,000 intensive 2 week session like corporate trainers provide for SQL Server Reporting Services (just one module…)…

(end rant, but I hope you understand the point… Thus stuff takes a lot of time a trial and error to grasp).

Quickest Option:

Why not try the new API, as it gets all the Groovy nonsense out of the picture…?


Also what is the goal is here? Things like Initialstate and the Google Drive apps could get you where you need to go depending on where that is…

1 Like

Thank you for each of the responses - all helpful in their own light.

@tgauchat : I take no offense at your snark, at all. Truth be told, I’ve been at it a lot more than ‘a couple of days’: I’ve had my ST hub since the Kickstarter days, and am a 25 year veteran of IT in a fortune200 company - one that is “Industrial IoT” by nature, so a lot of experience in traditional (legacy? :slight_smile: Industrial Control Systems environments. So - I wasn’t so much complaining that it was difficult - but hoping for some guidance to ‘connect the dots’ (make the leap from reading Switch state with the Tutorial Web Services app - up to reading energyMeter or powerMeter attributes from devices already configured and working to expose that data via custom DTH.

As to the new Cloud API: Eureka!! Thank you, Thank you - I’ll definitely go have a look straight away. Sounds like it might be a great solution to my problem. BTW: ActionTiles RULES!! I’ve got it licensed on a Raspberry Pi3 w/ 7" touch screen for a nice little home controller.

@bridaus I appreciate your question. The goal here is to create a REST endpoint for inclusion in a larger, Energy Management / Utilization platform (where we’re already ingesting a variety of other data, ranging from utility consumption, solar production, weather, etc) - and looking to add some device-specific insights.

We could absolutely setup webhook / callback endpoints, and allow ST to “push” the data per several examples I’ve found for “power / energy data logging services”. You’d think those examples would contain enough context / insight for me to cobble together something that works (e.g. - the specific syntax to query a device power meter) - but the complexities of subscribing to events, and parsing Z-Wave messages - as opposed to a straight-forward polling mechanism - has me chasing my tail.

I’ll post a github link to my hardly-modified Tutorial Web Services SmartApp and be more specific on where I’m running into trouble, and what specific help / syntax I need.

Thanks again!

1 Like

While I’m off learning about the new Cloud API - just a quick link to my current SmartApp code:

Here, I’m trying to define an endpoint in the mappings section, which references a function (?) called listMeters.

I cobbled that function together by making edits to the listSwitches example above - but I’m guessing the syntax:

resp << [name: it.displayName, value: it.currentValue(“powerMeter”)]

is incorrect - at least, I’m getting a null response whenever I hit that endpoint (using Postman or curl).

As an interesting (to me) aside / clue: This code, executed in the Simulator OR on my mobile device, does in fact allow the selection of the (4) devices I have deployed with powerMeter or energyMeter capabilities - based on the addition of these two lines to the preferences section:

input "powerMeters", "capability.powerMeter", title: "Power meters", required: false, multiple: true
input "energyMeters", "capability.energyMeter", title: "Energy meters", required: false, multiple: true 

Still doesn’t get me quite where I want to be - but feels like incremental progress.


You’re chasing your tail because you’re running off in a tangent!

A fundamental principle of SmartThings (and many other IoT systems…) is the abstraction layer of Devices (Things).

Automations, Event Triggers/Collection & UIs are completely isolated from the details and intricacies of a particular device’s implementation of its abstraction.

Ummm… In other words, you are writing a SmartApp, not a Device Type.

A SmartApp accesses (subscribes) a Device’s Attributes and controls the Device via Commands. These are standardized based on the Official Capabilities claimed by the Device.

A SmartApp never needs to deal with “parsing Z-Wave” messages. That’s the tangent that has me concerned you’re off track (umm… That’s what a tangent is… :crazy_face:.).

(Please PM me if you’d like to have a consultation on this project and how the SmartThings architecture should be applied. Would be a lot quicker over the phone for a reasonable fee.) Thanks!


Precisely! Again, I was already worried my message was TL;DR, so I didn’t go on about having reviewed / digested the ST Architecture documentation, and having a rudimentary understanding of the various components. I’ve been using exactly that vocabulary - that the DTH is the ‘abstraction layer’ between the specific / physical device implementation, into the ST ecosystem and standardized interfaces.

As noted - since I have an (out-of-the-box, with no way to view the source code) SmartApp in the ST Mobile App which is successfully collecting and displaying the desired information - I know the “backend” (e.g. @jbisson 's well-documented and widely-used DTH) is solid - I just don’t have a good example to pull from on how to reference and invoke the data elements it provides.

I’m off on yet another / different tangent, now, with the ‘new Cloud API’ - but I’m certainly keen on making sense of how to connect these dots (e.g. plumb a SmartApp ‘front-end’ (even if that ‘frontend’ is merely exposing an API) to the corresponding bits in the DTH - and keen on any examples, if they exist and my googlefu just isn’t turning them up.

Thanks again!

1 Like

Yup… I think the picture is getting clearer for you and you’ll certainly learn a lot with trial/error/discovery/exploration.

There’s tremendous value in having a phone conversation with me though, so keep that option in mind.

(BTW: I’m co-founder of ActionTiles, so… kinda know what I’m talking about … I think… I hope!! :blush:).