How to sleep for milliseconds given in an item state?

How can I sleep for the time specified in a number item?
When I just try putting the state of the item in into Thread::sleep(item.state) it fails with some error that it can’t run sleep on null. However I can log the value of that item.

I find the type system of this language very confusing even though I am able to code well in 3 other languages. Is there any real documentation on it? The docs for rules seem to be incomplete.

I think you’ll want an integer.
Thread::sleep((item.state as Number).intValue)
Thread::sleep is a Java function

1 Like

The problem is you are not working with just one language. When writing OH rules, no matter the scripting language chosen, all of your interactions with openHAB (e.g. sendCommand, createTimer, MyItem.state, etc.) is actually working with Java Objects. All the Java Objects are documented at Overview (openHAB Core 3.1.0-SNAPSHOT API).

Furthermore, especially in Rules DSL, much of the stuff you work with that are not openHAB, like Thread.sleep, createHashMap, etc will be creating Java Objects as well.

A Number Item carries a state of type DecimalType. Thread.sleep() expects a Java primitive int or long.

1 Like