How to deal with sensors sending signals in bursts

I’ve struggled with the same issues. Don’t use the Thread:sleep - ive tried to a few times and every time I end up “locking up” the rule engine. It seems like two or more rules can fire at once, then they both sleep, and it never wakes up…

I use your first method to stop the ‘double action’ like this -

 val java.util.concurrent.locks.ReentrantLock lock  = new java.util.concurrent.locks.ReentrantLock()

rule "send email when front door open"
when
    Item Front_door_sensor received update
then
     if( !lock.isLocked() ) 
     {
    	lock.lock()
    	try{
    			logInfo(“rules”, “Front door open!!”)
                            // do whatever you want
       }
           finally {
	    lock.unlock()
           }
    }
    else{
          logInfo("rules", "Ignoring second action")
    }

Note I just coded it in the browser from my rules as a reference, it looks correct, but didnt test it :wink:

1 Like