OH3 ECMA-rule: previousState?

I’d like to access the item’s previousState in a OH3-rule:
So, if the log says:

  • Item 'MQTTOneWire_WhirlpoolCounter' changed from 7574 to 7579

I’d like to have something like:

logger.info("previous state of item: " + event.itemName + " was " + event.previousState);
logger.info("previous state of item: " + event.itemName + " was " + itemRegistry.getItem(event.itemName).previousState);logger.info("previous state of item: " + event.itemName + " was " + itemRegistry.getItem(event.itemName.toString()).previousState);

but everything I get is:

2021-07-13 18:58:55.837 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'MQTTOneWire_WhirlpoolCounter' changed from 7632 to 7633
2021-07-13 18:58:55.839 [INFO ] [org.openhab.rule.WhirlpoolEnergy    ] - previous state of item: MQTTOneWire_WhirlpoolCounter was undefined
2021-07-13 18:58:55.841 [INFO ] [org.openhab.rule.WhirlpoolEnergy    ] - previous state of item: MQTTOneWire_WhirlpoolCounter was undefined

What’s the correct syntax of this?

1 Like

Try event.oldItemState instead.

2 Likes

Thanks a lot!