[HELP] Something isn't right with my rule

I’m not getting the expected log output from the Rule below. When the Study door is opened and the Lux level is below 400 the Cabinet lights should turn on. The log output shows what I’m getting. The rule does work as it should, as in the lights come on and switch off it’s just the output to the log for the lights that’s not right. What do I need to change?

rule "Study Door"
when
	Item Study_ZW089_Sensor changed
then
    if(Study_ZW089_Sensor.state == OPEN) {
        if(Porch_ST815_Lux_Level.state < 400) {
            Study_Cabinet_Lights.sendCommand(ON)
        }
    } else {
        if(Study_Cabinet_Lights.state == ON) {
            Study_Cabinet_Lights.sendCommand(OFF)
        }
    }
    logInfo("org.openhab", "Study: Door {} and the Cabinet lights are {}",Study_ZW089_Sensor.state,Study_Cabinet_Lights.state)
end
2019-08-05 20:00:32.010 [INFO ] [e.smarthome.model.script.org.openhab] - Study: Door OPEN and the Cabinet lights are OFF
2019-08-05 20:00:46.074 [INFO ] [e.smarthome.model.script.org.openhab] - Study: Door CLOSED and the Cabinet lights are ON
2019-08-05 20:02:18.477 [INFO ] [e.smarthome.model.script.org.openhab] - Study: Door OPEN and the Cabinet lights are OFF

I think perhaps you are expecting Study_Cabinet_Lights.sendCommand(ON) to have an instant effect (it doesn’t) or the rule to stop and wait while it gets actioned (it doesn’t).
Examining the state of an Item a couple of milliseconds after you sent it a command is almost certain to give you the “old” state.

You don’t need to look at the state because you already know what command you just sent.

Thanks, always the simplest of answers.

Well, it’s not really simple. Many people struggle to get to grips with the asynchronous nature of sendCommand and postUpdate.