I’ve been diving into the world of OpenHAB and came across a challenge that I thought I’d share with the community. I’ve been trying to create a functioning looping timer to monitor the status of a device every hour. My goal is to check if a switch remains off after it’s been turned off and send a notification if it stays that way. Sounds straightforward, but I’ve hit a snag with a lambda expression error related to non-final variables.
Here’s what I’ve got so far:
var Timer testy = null
testy = createTimer(now.plusSeconds(30), [ |
if(BEStatusSwitch.state == ON){
sendNotification(“myusername”, “If has run”)
testy = null
} else {
sendNotification(“myusername”, “Else has run”)
testy.reschedule(now.plusSeconds(30))
}
])
The error I’m encountering is about referring to a non-final variable inside a lambda expression, specifically pointing to testy = null and testy.reschedule(now.plusSeconds(30)). I’ve scoured the documentation and forums, but I’m still not quite getting it. Has anyone else encountered this issue or have any insights on how to resolve it? Any help would be greatly appreciated!
I’m also curious if there are alternative approaches or best practices for implementing such a timer in OpenHAB. Maybe there’s a more efficient way to achieve this without running into lambda expression issues. I’d love to hear your thoughts and experiences!