Inputting integer


(Paul) #1

I’m having trouble inputting a integer variable in the preferences section, and then using it later to calculate time.

This code works fine if I define deltaSeconds in the function:

def doorOpenCheck() {
    def deltaSeconds = 10
    def doorAgo = new Date(now() - (1000 * deltaSeconds))
    def recentEvents = contact1.eventsSince(doorAgo)
}

But if I try to define deltaSeconds in the preferences like this:

preferences {
    section("Some section name...") {
    	input "deltaSeconds", "number", title "Some title..."
	}
}

And then use deltaSeconds in the function like this…

def doorOpenCheck() {
    def doorAgo = new Date(now() - (1000 * deltaSeconds))
    def recentEvents = contact1.eventsSince(doorAgo)
}

I get an error. Do I have to cast deltaSeconds in some way if I input it in the preferences? Is it not available somehow? Newb coder alert… I’m clearly missing something…

Thanks…


(Geko) #2

Try deltaSeconds.toInteger()


(Paul) #3

Awesome. I’ll give that a shot.

So just so I understand… when I input a variable in preferences, it comes in as a string? And Groovy won’t auto-cast a string to an int?

Thanks.