Thread::sleep doesn't work since OH2

So I have the following rule

rule "Forgot door Open"
        when
                Item HallwayDoorSensor_DoorSensor changed from CLOSED to OPEN
        then
                Thread::sleep(30000)
                logInfo("SurveillanceCheck", "Usa de la intrare s-a deschis")
                if (HallwayDoorSensor_DoorSensor.state == OPEN)
                {
                        sendNotification (“email@gmail.com","Usa de la intrare a ramas deschisa")
                        logInfo("SurveillanceCheck", "Usa de la intrare a ramas " + HallwayDoorSensor_DoorSensor.state)
                }
end

As you can see, if the door opens, it should wait 30 seconds and if the door is still opened should send a notification.

The issue is that since OH2 the notification is sent instantly, without actually waiting the 30 seconds to check if the door is still opened.

This is running on a RPi 3 with OSMC, so basically fancy raspbian.

Thread::sleep(30000)
on my 2.3.0#1157 works fine
To check write logInfo before and after the sleep.

This is the better Way :slight_smile:

rule "Forgot door Open"
when
  Item HallwayDoorSensor_DoorSensor changed from CLOSED to OPEN
then
  createTimer(now.plusSeconds(30), [| 
    logInfo("SurveillanceCheck", "Usa de la intrare s-a deschis")
    if (HallwayDoorSensor_DoorSensor.state == OPEN) {
      sendNotification ("email@gmail.com","Usa de la intrare a ramas deschisa")
      logInfo("SurveillanceCheck", "Usa de la intrare a ramas " + HallwayDoorSensor_DoorSensor.state)
    }
  ])
end
1 Like

Thanks guys! I’ve just now realised that the issue is. It’s not the thread sleep, it’s that the sensor reports it the wrong way. It reports it’s OPEN when the door is closed and the other way around.