console.info("previousState is: ", items.getItem("MyItem").persistence.previousState(true, "jdbc").state);
I only get “real” states, and not “UNDEF” or “NULL”. let’s say “MyItem” was
ON
UNDEF
OFF
If the rule runs on state #3, the above code will say, the previousState was “ON”. I’d like to see, if it was “UNDEF”.
Is there a way to determine, that the state of an item was UNDEF before? For a trigger of a rule I can use “UNDEF” as “previous state”, but not in a rule itself?
UNDEF and NULL do not get saved to persistence. You’ll never see UNDEF or NULL from any persistence call.
But the event Object has event.oldState for file based rules or event.oldItemStarte for UI rules.
These only exist for received update and changed triggers. If the rule is triggered by something else these variables will be undefined. Note that the UI event Object is the raw event Object meaning everything in it is the raw Java Object. In file based rules it’s a JS wrapper and it provides JS data types.