Capture error of previousState()

Hello,

ist there a way to capture the error of previousState() for an item, if the previousState is not available yet.
This does not work (DSL Rule):

if (Item.previousState(true).state !=null) {
}

It gives following error:
// Script execution of rule with UID ‘ae’ failed: cannot invoke method public abstract org.openhab.core.types.State org.openhab.core.persistence.HistoricItem.getState() on null

Thanks!

Are you sure the item is persisted by the default persistence?

Maybe better show a more complete rule :slight_smile: instead of a single line.

Please be aware that .state will never be null but NULL. Maybe you’ll have to get information if previousState() itself is null

if(Item.previousState(true) !== null) {
}

And please be aware of !== instead of !=, as this check is about not being identical