Error in getting .previousState on a string item

Am on OH2.5.12.

I have a rule checking for specific statuses of an outdoor security cam

I have the following statement in a rule:
if (NetatmoWelcome_VideoStatus.previousState(true).state == UNDEF) {

which is giving me the following error in the log:
2021-05-21 04:33:01.339 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'real presence events': rrd4j does not allow querys without a begin date, unless order is descending and a single value is requested

This is an example of state change of the field (here changed from “UNDEF” to “available” from the eventlog:
2021-05-21 05:38:59.156 [vent.ItemStateChangedEvent] - NetatmoWelcome_VideoStatus changed from UNDEF to available

What I want to achieve is, that the if-statement captures where the previous value of the string item "NetatmoWelcome_VideoStatus is = UNDEF

I understand it has to do with a wrongful use of .previousState - but could anyone suggest how this should look like ?

None of the persistence services store UNDEF (or NULL) states, by design. They are simply ignored.

Note that for a String type Item, UNDEF or NULL state is not the same as strings “UNDEF” or “NULL” (or any other string).

Simply, you won’t be able to use persistence to find out when any Item was last NULL/UNDEF

Your next problem is that rrd4j service is numeric based, and never stores any String type Items at all. You’d need to use a different service for that.

But maybe you don’t need to use any persistence for this, depending on what you’re doing with your rule. There’s a previousState implicit variable, depending on rule trigger. Or even conditional triggers,
when Itemxx changed from UNDEF

Thanks ! - I was not aware of that. I have fixed it with a conditional trigger (changed from UNDEF) - and then control the status through a proxy switch…