Delay between mqtt state change and rule executuion

I’m running openhabian.

I see a behavior I don’t understand…

I have the following two rules. Sometimes there is there is a long delay (like 5 seconds) between the two different lights coming on. Other times not.

And sometimes, there is a delay, then they both come on nearly simultaneously.

The log shows the delta between ItemCommandEvent for the two devices is around 30mS. Are the delays I’m seeing the zwave lag times?

I fooled around with the time the mqtt stays in the Motion state, but that seems to have no effect.

val night_beg = new DateTime(Night_Start.state.toString)
val night_end = new DateTime(Night_End.state.toString)
val day_beg = new DateTime(Day_Start.state.toString)
val day_end = new DateTime(Day_End.state.toString)
val motion_count = 0

rule "Driveway Motion Night"
when
	Item mqtt_test changed from "No Motion" to "Motion"
then
	logInfo("loggerName", "In Driveway Motion Night, day_beg: " + day_beg)
	if(	(now.isAfter(day_beg))  &&
        (now.isBefore(day_end))  && 
		(zwave_device_16500637f6a_node12_switch_binary.state == OFF)) {
			logInfo("loggerName", "Send driveway lights on")
			zwave_device_16500637f6a_node12_switch_binary.sendCommand(ON)
			createTimer(now.plusSeconds(30), [ | zwave_device_16500637f6a_node12_switch_binary.sendCommand(OFF) ])
			}
end

rule "Driveway Motion Night Amber"
when
	Item mqtt_test changed from "No Motion" to "Motion"
then
	Garage_test.postUpdate("Set from rule")
	if(	(now.isAfter(day_beg))  &&
        (now.isBefore(day_end))  && 
		(zwave_device_16500637f6a_node10_switch_binary.state == OFF)) {
			zwave_device_16500637f6a_node10_switch_binary.sendCommand(ON)
			createTimer(now.plusSeconds(10), [ | zwave_device_16500637f6a_node10_switch_binary.sendCommand(OFF) ])
			}
end

Do you have any other rules with while loops or Thread:sleep?

No while loops, no Thread:sleep.

There is a sendMail.
I have since changed the rule, but still none of those:

rule "Driveway Motion Night"
when
	Item mqtt_test changed from "NULL" to "Motion" or
	Item mqtt_test changed from "No Motion" to "Motion"	
then
	logInfo("loggerName", "In Driveway Motion Night, day_beg: " + day_beg)
	//if(	(now.isAfter(night_beg))  &&
    //    (now.isBefore(night_end))  && 
	if(	(now.isAfter(day_beg))  &&
        (now.isBefore(day_end))  && 
		(zwave_device_16500637f6a_node12_switch_binary.state == OFF)) {
			logInfo("loggerName", "Send driveway lights on")
			zwave_device_16500637f6a_node12_switch_binary.sendCommand(ON)
			createTimer(now.plusSeconds(30), [ | zwave_device_16500637f6a_node12_switch_binary.sendCommand(OFF) ])
			}
	//if(	(now.isAfter(night_beg))  &&
    //    (now.isBefore(night_end))  && 
	if(	(now.isAfter(day_beg))  &&
        (now.isBefore(day_end))  && 
		(zwave_device_16500637f6a_node10_switch_binary.state == OFF)) {
			zwave_device_16500637f6a_node10_switch_binary.sendCommand(ON)
			createTimer(now.plusSeconds(10), [ | zwave_device_16500637f6a_node10_switch_binary.sendCommand(OFF) ])
			}
	Garage_test.postUpdate("Set from rule")
	val tc = Motion_Count.state as Number + 1
	Motion_Count.postUpdate(tc)
	val String mailTo = "macdroid53@gmail.com"
	val String message = "New motion detected. New Total: " + tc
	sendMail(mailTo, "Motion Detected", message)

end

rule "Motion Count Daily Reset"
when
	Time is midnight
	//Time cron "0 56 0,14 ? * * *"
then
	val String mailTo = "macdroid53@gmail.com"
	val String message = "Motion Count Daily Total: " + Motion_Count.state
	sendMail(mailTo, "Motion Daily Report", message)
	Motion_Count.postUpdate(0)

end

rule "sys init"
when
	System started
then
	Garage_test.postUpdate("Started this thing...")
end

It is better now, but still, sometimes there is a lag.