Just one thing I changed now :
if (!contactA && !contactB) {
contact = false;
}
else {
contact = true;
}
Looking at the doc there’s only one closed state, and two open states (open or timeout open). In your code you consider the timeout open state as a closed state, so I just removed the second condition to consider anything that’s not closed as open. With the above if the door is left open longer than the timeout, it keeps showing open in HA