I am pretty sure, that this is quite easily answered.
I have the following code:
rule "Bad aus bei keiner Bewegung"
when
Item OccupancyBad changed from "true" to "false"
then
logInfo("Status", "Dimming Bad")
badDimming = true
val currentBrightness = (Bad_Farbtemperatur.state as DecimalType).intValue
val timeInSecondsForDimming = 15;
if(currentBrightness>0){
val sleepTime = timeInSecondsForDimming * 1000 / currentBrightness
var i = currentBrightness
while ((i=i-1) >= 0) {
Thread::sleep(sleepTime)
if(badDimming){
logInfo("Status", "Setting Bad to Brightness: "+i)
sendCommand(Bad_Farbtemperatur, i)
}
}
}else{
logInfo("Status", "Bad Lights already off")
}
end
This rule dims the light from the current value to 0 in 15 seconds.
I now want to use the same dimming for other lamps. In java for example I would create a function that takes the item “Bad_Farbtemperatur” and the variable “badDimming” as parameters and then use them.