Help with a simple (I think) Groovy question

Trying to make a simple change to a premade community DTH named SmartWeather Station Tile 2.0 (thank you @takissd). Whoever knows Groovy, please help. I am not a programmer and it is driving me batty trying to make this simple change.

To summarize, this DTH currently gives a very loose estimate of lux based on the weather conditions. Sunny = 10000 lux, cloudy = 1000 lux etc. I want to change it so that Lux populates instead as a function of Solar Radiation which is a defined Attribute in the data set.

Specifically I want the formula to be Lux = solarradiation / .015.

Currently Solar Radiation is defined in the following way within the DTH:

In the metadata section:

attribute “solarradiation”, “string”

I am trying to create a lux value in the following way:

def lux = (solarradiation)/0.015

I know the ‘def lux =’ part is right because when i put ‘def lux =1’ i get the value of 1 returned.

I know this is super simple. Help Please!


def lux = device.currentValue(“solarradiation”) / 0.015

@krlaframboise - Thanks for the code! I tried putting it in the DTH and I get the following error:

Any ideas?

You mentioned that it’s currently defined as:

attribute “solarradiation”, “string”

To read that value you need to use the following, but since it’s defined as a string and your using it as a number you’d probably need to append either toInteger() or .toDecimal() to it:


To set that value you need to send an event:

sendEvent(name: "solarradiation", value: newValue)

Edit: I copied “solarradiation” from your original post and it looks like it used slanted quotes so if you copied and pasted it back into your code that would explain the error you posted.

Hey @krlaframboise . Thanks again for getting back. I tried the above but it would then take my solarradiation value to zero in SmartThings. When you mentioned taking the string to an integer I Googled it and ended up trying a few lines of what you reccomended and what I saw online. Bottom line is the below works. I probably could have saved a step but not going to touch it anymore now that it finally works.
Thx again!

def SRInteger = device.currentValue(“solarradiation”) as int
def lux = SRInteger / 0.015

1 Like