I have a script that turns off a light after XX seconds and would like to be able to change the XX seconds in runtime via a slider.
I created an item as:
and I am trying to use it as:
…but I get an error "Could not invoke method: java.lang.Thread.sleep(long) on instance: null
What am I doing wrong?
Until you actually set the Item to something, it’s value will be NULL, thus throwing the error.
You need something on your sitemap to actually set the item’s value.
I would recommend a setpoint rather than a slider, it’s better to set to a defined value.
Setpoint item=StairsTimeout minValue=1 maxValue=60 step=1
With this you can set the value from 1 to 60 seconds in 1 second intervals.
If you did this and the error is still there, cast the Item like so:
(StairsTimeout.state as DecimalType).longValue
I would also suggest to persist the item, else you will get the same error after a restart of OH.
I checked if StairsTimeout has a value and it does, I tested it in the script rule by logging its value to the logger
I think you’ll need to make it an integer type to use with sleep
can you show the casting coding?
Thread::sleep((LightStairsTimeout.state as DecimalType).longValue * 1000)