Rule responding to command gets old value

One of the many issues I’m having switching to OH2. Without the delay below, the rule sees the previous value of “Alarm_Mode”. I spent a lot of time debugging this and now it concerns me that this could potentially impact most of my other rules. Apparently, the rule gets triggered before the new item value is available.

Is this a known bug? Do I need to put a timer in all rules to prevent this from happening?

Without the timer delay, the wrong audio file was played about 75% of the time. I’ve made the rule more complex during debugging.

rule "Alarm Mode Notify"
	when
		Item Alarm_Mode received command
	then	createTimer(now.plusMillis(80)) [ 
		switch(Alarm_Mode.state){
				case 0: {Audio_File2= "sysdisarmed.mp3"}
				case 1: {Audio_File2= "sysarmaway.mp3"}
			SqueezeAudio2.postUpdate(Audio_File2+"")
			}
		}]
end
rule "Squeeze Notification 2"
	when
		Item SqueezeAudio2 received update
	then	SqueezeUSerStrm.sendCommand("openhab/" + SqueezeAudio2.state)	
end

Does your rule need to know the actual .state (perhaps after it has been returned by some external device or service)? you could trigger on changed or received update
Or does your rule need to know the command that was sent, i.e. use receivedCommand instead of state?

I don’t believe this is is a bug, just a misunderstanding that sending a command to an Item may not instantly (or indeed ever) change its state.

@rossko57

I tried every combination of triggers and state (such as receivedCommand) I could find. None of that made a difference. I originally thought the problem was in the second rule, but it doesn’t matter how I format that one. I didn’t think to look at the original trigger, so you made me realize that the update must lag behind the command. I changed from Item Alarm_Mode received <command> to <update> and that solved the problem.

Thank you