Different values in `command` and `getState()`of same Item

I have a some strange behavior in an ECMAScript. Can anyone tell me why this is happening?

The rule is triggered by: TestItem received a command. TestItem is a switch.

The rule looks simplified as follows:

this.logger = (this.logger === undefined) ? Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.core.model.script.' + ctx.ruleUID) : this.logger;

logger.info("GetState: " + ir.getItem("TestItem").getState());
logger.info("Command:  " + command);

I would always expect the two statements to be either ON or OFF. So like this:

GetState: ON
Command:  ON

or

GetState: OFF
Command:  OFF

From time to time, however, it comes into the state that the two values differ.

GetState: OFF
Command:  ON

How can this be? command always shows the correct value, .getState() is sometimes not updated.

This is working as designed.
There are fundamental reasons that command and state are different, which is worth understanding.

Have a think about what you’d expect to see for a slow-moving rollershutter if sent command UP and initial position state was 50%

2 Likes