- Platform information:
- Hardware: RP4 8Gb
- OS: Bullseye
- openHAB version: 3.2.0.M5
I am trying to create a script that uses a Timer to turn lights off if no motion has been detected for a fixed time. I created the following rule using the UI
configuration: {}
triggers:
- id: "1"
configuration:
itemName: DenMotionSensor
state: OK
previousState: ""
type: core.ItemStateChangeTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
considerConditions: true
ruleUIDs:
- f627c72323
type: core.RunRuleAction
which call this script:
val String logName = "den.rules"
val Integer timeoutSeconds = 3 //Time to leave lights on after motion no longer detected
var Timer occupancyTimer = null //Tracks time until lights are to be turned OFF
if(occupancyTimer === null || occupancyTimer.hasTerminated()) {
occupancyTimer = createTimer(
now.plusSeconds(timeoutSeconds),
[|
sendCommand(DenLights, OFF)
occupancyTimer = null
logInfo(logName,
"Motion stopped: timer expired, lights off")
]
)
logInfo(logName, "Motion stopped: timer started")
}
else {
occupancyTimer.reschedule(now.plusSeconds(timeoutSeconds))
logInfo(logName, "Motion stopped: timer rescheduled")
}
I get the following error: āCannot refer to the non-final variable occupancyTimer inside a lambda expression; line 10, column 400, length 14.ā The script ran in OH2.5. I canāt identify the problem and donāt know how to correct it. Any suggestions will be appreciated.
As an aside, note that the error message refers to ācolumn 400.ā