If (item.state == Undefined) throws exception

I know that Uninitialized should be renamed to NULL, thats working.

I’ve used the Initialization rule in here

am not quiet sure if [ if(item.state == Undefined) is meaningful in the first place ? specially for values that is not persisted and openhab is running for the first time

Error is :

[See nested exception: java.lang.RuntimeException: The name 'Undefined' cannot be resolved to an item or type.]

1 Like

I think Undefined is renamed to UNDEF

1 Like

Actually yes, checking for Undefined can be meaningful, particularly for Items that are not restored on startup. It tells you that an Item is in an uninitialized state. There can be many circumstances where knowing whether your Item has been initialized can be meaningful and cause a rule to take a certain action it otherwise wouldn’t.

For example, if I have an Item that stores some sort of value (e.g. an alarm time) I might want to check that it isn’t Undefined before trying to process it as if it had a value or at least do something different if it is Undefined.

It may be irrelevant in most cases. For example you can test for ON and then threat OFF and Undefined as the same thing.

Personally I use restoreOnStartup on all my Items as I would much rather have my home automation run based on its past state than deal with Undefined.

1 Like

Thanks, i use restoreOnStartup too.

I am wondering then what is the difference between Uninitialized (check using term NULL) according to Kai here and Undefined (check using term UNDEF?)

1 Like