How to set timer value with a variable?

Hi All,

I have a few rules with timers similar to the line below:

FamilyRoomLightTimer = createTimer(now.plusMinutes(5)) [|
Do Something Cool.....]

In the example above I’d like to use a variable or better yet a number item to replace the “5”.

I would like the timers to be more dynamic based on time of day, occupancy, weather, etc and it would be far less lines of code to use a variable VS rewriting the entire rule block with separate conditions. If I substitute the “5” with anything that’s not a number I get errors in designer.

Is there a way to pull this off?

If you have a Number variable you would use the intValue method to get a primitive int which now.plusMinutes requires.

var Number myNum
// code that populates mynum
FamilyRoomLightTimer = create(now.plusMinutes(myNum.intValue)) [|
    // do stuff

Brilliant!! Thanks Rich!

Just so all my bases are covered, how would I use the value of a number item to accomplish the same thing?

now.plusMinutes((MyItem.state as DecimalType).intValue)

Thank you Rich! That works awesomely!! Thank you, Thank you.