Help with a zigbee thermostat device handler


I’m completely new to this and a total noob, but I like to thinker with things so…

I have an Elko thermostat that works very well with smartthings, (Zigbee device) but there is a small flaw in the device handler.
The guy who made the device handler wasn’t sure what value he was getting, so he assumed it was “Watts”. It is a number from 0 and 2000, reported every 600 seconds and it is in fact how many 1/3 seconds the thermostat has been heating the last 10 minutes. (heating all the time = 2000, Heating half the time = 1000)

  1. Is there any way I can take this number and divide it by 3.333 to get “seconds active last 600 seconds” and multiply it by x (I know my floors power consumption) to get “wattseconds last 10 minutes” Then multiply it with 3600 to get Kwh?
    Is it possible to do math in the device handler?

  2. Can I get this new number to accumulate so the next 10 minutes adds to the last, and I have a working energymeter on my thermostat?
    This will need the device handler to log and add up a value. Is it supported?
    I assume my other energy measuring devices logs the energy in the device and just reports it to the device handler.

If you have the code of the DTH, then you can change anything. You just need some groovy programming skills.

1 Like

Yes you can do that.

You can take the value you got and convert it to float and perform your computation.

Example: I take here a temperature temp_cal_float that is a text and compute something with it:
/ Real feel indoor temperature
float realfeel= temp_cal_float.toFloat()+0.348emc_humid6.105Math.exp((17.27temp_cal_float.toFloat())/(237.7+temp_cal_float.toFloat()))-4.25

  1. Yes you can do Maths. I assume you mean 0.3 seconds rather than 1/3 seconds. I’d just multiply by 1080 and then multiply by ‘x’ myself.

If the DTH is incorrectly reporting power it probably has the capability ‘Power Meter’, it probably has a UI valuetile for ‘device.power’, and it will be creating an event for ‘power’. You’d probably want it to be an ‘Energy Meter’ and use ‘’ and ‘energy’. Oh and fix any incorrect units.

  1. might help you out with this, once you’ve gotten over ‘state’ meaning different things in different contexts in SmartThings.

Is this is a correction to the DTH as per the thermostat specs ? If so, what’s the name of the DTH you’re using and I’ll be happy to submit a patch to ST. Also need the thermostat specs to verify it.


Been busy for a few days.

This is the device handler:

This is the developers notes I guess:

As I said, it’s working like a charm, so this is just a minor issue, but a little modification I hope to learn a little from.

I wish I had skillz, and this is the first thing I “need” to change so far.
I hope to learn a bit from this.

Linked the DTH in a later reply.


I guess I’ll have to start reading a lot about Groovy, cause your example looks pretty confusing to me :smiley:

Sorry… I meant to say 3 & 1/3 :flushed:

The value I get is from the regulator part of the device I guess. I don’t think this device measures power, but It reports in how many % of the time it has been on the last 10 minutes ( 600 seconds). I get a number between 0 and 2000 (0 - 100%)
2000 / 600 = 3.33333…

So the first step to my problem is to just divide the value by 3.3333… Which would give me “seconds on last 10 minutes”. Divide it by 20 instead and it would show me “% on last 10 minutes.”

Not very useful, but at least it is what the thermostat is reporting.

If I get that to work the useful bit is to add this value to the last one and get the total number of seconds this thing has been heating… (If that is even possible? )

Before I start making changes, I didn’t completely understand. The device reports how many 0.33 seconds units it was turned for in the last 600 seconds, is that correct?


Power (W) = Reported value * 3 * RATED_POWER

RATED_POWER should be an input from the user, is that correct?

Energy Consmption (KWh) = Last KWh + (latest W) * 10/60

Is the above correct?

The thermostat is actually not keeping track of the energy consumption and power at all. The value I get is from the regulator option. The number reported by the device (0-2000) corresponds with 0-600 seconds on last 600 seconds.

First thing: Value /3.3333… (2000 / 3,33333… = 600) “Seconds active last 600 seconds.”

If possible the next thing is to log this new value (seconds) and add the next report on top of it.
If I multiply this with my Wattage (X) I have Wattseconds.

At some point it makes sense to divide it by 3,600,000 to make Kwh.
This can also be done in the beginning (Value / 1080000) but it will be easier to track it in seconds for testing purposes and convert it later maybe?

Where to put in the X? Manually write it in the DHT or make an option to input watts in the missing option settings?

Was this properly explained?

Even if the rest isn’t supported I would like to se the first value conversion for learning purposes :slightly_smiling_face:

Ah okay, so

You’ll have to enter X, the POWER_CONSUMPTION (W) in the device preferences page
which will be reported as is since the device isn’t tracking it and then

KWh = (Last KWh) + (W * (LATEST_REPORTED_VALUE/3) * 60 * 60 / 1000)

Yeah. The Power consumption has to be manually added as a fixed value. At this point I don’t think it has a preference page at all.

Think you’re spot on if you switch out the “3” with “3.3333” or" (3+(1/3)) "

Here’s the patch:

Hi again.
Great work. I will sit down and read through it to understand what happens.

I had to tweek it a little bit, but now I think it’s working as intended. Doing testing as we speak. =)

Compilation error: Line 57
valueTile(“energy”, “”, inactiveLabel: false, decoration: “flat”, width: 2, height: 1)) {

Solution: Removed a “)”
valueTile(“energy”, “”, inactiveLabel: false, decoration: “flat”, width: 2, height: 1) {

Tweek math: Line 195
state.lastKWh = (state.lastKWh ?: 0.0) + ((watts ?: 0.0) * (lrv/3.333) * 60 * 60 / 1000)

state.lastKWh = (state.lastKWh ?: 0.0) + ((watts ?: 0.0) * (lrv/3.333)) / (60 * 60 * 1000)

One thing I’ve noticed is that value 408 now comes in as a hex code, and it used to report as a decimal. Is this for further logging and math or just a preference?

Thanks again =)

Forgot to reply on this.

I had to change line 192 , but now it works pretty well.

state.lastKWh = (state.lastKWh ?: 0.0) + ((watts ?: 0.0) * (lrv/3.333)) / (60 * 60 * 1000)

Thanks for the help =)

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.