Global Variable In App

Trying to use a Global Variable in an App. Can't seem to figure out where I'm going wrong. From what I can read, this code should work, but it errors out.

fanRunTime is a global variable of type number.

    def fanOnTime = getGlobalVar("fanRunTime")
    log.debug "${fanOntime}"
    runIn(fanOnTime * 60 *60, fanOff)
1 Like

getGlobalVar() returns a GlobalVariable object, not the value itself. This object has a getValue() method, or, equivalently in Groovy, a value property, which should return the value you're looking for--and be of the appropriate type. So, use fanOnTime.value or something along those lines.

If that doesn't help, logs of the actual error you get would be helpful.

1 Like

The getValue worked, once I got the syntax right. I don't do this often enuf to remember that stuff. Thanks.

1 Like