I’m not sure how what is here works. Xbase is pretty forgiving I guess. The first error and the persistence error you saw might be a bit misleading. I bet your persistence is fine but I see several problems with your code that makes me think it is having difficulty casting what you are pulling from the database to what you are telling the rules engine to store it in.
First of all, maximumSince() returns an object of type HistoricItem and HistoricItem.state returns an object of type State so assigning it to an object of type Contact should generate an error.
Second of all, in any case I think what you want is org.openhab.core.libary.items.ContactItem, not Contact for the type of “a” and “b”. But that is a little bit of a red herring since maximumSince isn’t return that type anyway.
Third of all, this is a nit pick but a Contact’s states are OPEN and CLOSE, not ON and OFF. What is here might work though.
I think to correct the code as is you would need:
var State a
var State b
a = personA.maximumSince(now.minusMinutes(20)).state
b = personB.maximumSince(now.minusMinutes(20)).state
if((a==OPEN) || (b==OPEN))
However, I find I run into this sort of error (and greatly reduce my imports) far less frequently if I roll up a lot of this code and let the Rules engine figure the types of things out for me. At a minimum you could do:
val a = personA.maximumSince(now.minusMinutes(20)).state // since a and b are never reassigned, use val instead of var
val b = personB.maximumSince(now.minusMinutes(20)).state // Xbase is really good about figuring out the types of things most of the time so you don't have to explicitly state it
if((a == OPEN) || (b == OPEN))
But I personally would roll it up even further and avoid the assignments entirely.
if((personA.maximumSince(now.minusMinutes(20)).state == OPEN) ||
(personB.maximumSince(now.minusMinutes(20)).state == OPEN))
Finally, if I ever thought I would have more than two people controlling the presence I would drop the person Items into a group and use a filter:
Contact personA (gPresence)
Contact personB (gPresence)
if(gPresence.members.filter(person | person.maximumSince(now.minusMinutes(20) == OPEN).size > 0)
This way to add another person you just need to add them in the Items file and make them a member of gPresence. You don’t have to touch your rules at all. I use this design pattern all over the place and as a result my rules have become much much shorter (more than a 50% reduction in lines of code) and much much easier to read.
Finally, are you using Designer? I think it would have caught some of the original errors, though maybe not. I can’t figure out which package Contact is in so I can’t tell if it would have caught the assignment error (i.e. assigning a State object to a Contact variable).