- Platform information:
- Hardware: Raspberry Pi 4 Model B Rev 1.4 8GB
- OS: Debian GNU/Linux 10 (buster) (openhabian)
- Java Runtime Environment: _openjdk version “11.0.10” 2021-01-19 LTS
- openHAB version: 3.1.0.M1 - Milestone Build
Hey!
I was running openhab 2.5 for some time, and decided to migrate to version 3 and follow the best practices where possible. I am DIY coder so my code is not always pretty. In OH3 I decided to start setup from scratch with DSL rules created via UI.
Where possible I copied in some old rules and just cleaned them up. I got a pretty decent minimal setup, however in my old rules I was using Thread::sleep which I know is not the best practice as it makes system wait the time before executing the rest. I wanted to give timers a go but after scrolling through a lot of topics I am still a bit confused on how to create it in UI rule.
Below is one of the scripts I would like to convert to use timer:
Thread::sleep(2000)
if (FrontDoorSensor_ContactFrontdoor.state==CLOSED){
Frontdoor_DoorLock.sendCommand(ON)
}
Now what it does is: If sensor on the door fires CLOSED system should wait 2 seconds and if the door is still closed, turn the lock. The delay is there to prevent the system from closing when the door is not yet fully closed or if you close it, then go like, crap, forgot keys and open them again to grab them, then lock. Could you guide me a bit how to change it to create a timer and achieve similar result?
I am also using timer with my light, so if I hold two buttons on my Aqara double switch it should lock the back door, kill all the lights and if it is after dawn (I have a dummy switch switching on at night with Astro binding) switch light in the hallway for a short time and then switch it off so that I don’t have to leave the house in darkness. This is sort of I am leaving action.
The below is a section of CASE statement for this:
case “both_long”:{
Lights_all.sendCommand(OFF)
Backdoor_DoorLock.sendCommand(ON)
if (NightTime.state == ON){
OnByMovement_Staircase.sendCommand(OFF)
StaircaseMovementOn.sendCommand(OFF)
HallwayLight_Brightness.sendCommand(30)
Thread::sleep(10000)
HallwayLight_Power.sendCommand(OFF)
StaircaseMovementOn.sendCommand(ON)
}
}
Now the above is doing all as expected but doesn’t really wait the 10s but just blinking the light and switching it off. Can’t see anything wrong (except for using sleep that I also want to get rid of).
I would really appreciate your help in that matter.
Apologies if any of the info is incomplete.