State of a bipolar Relais
Bipolar relays keep their last switching state by a weak permanent magnet. The core (C) is therefore biased by the permanent magnet in one direction. This also means that a current in the coil (L) will drive it into saturation faster in one direction than in the other.
Additional mechanic components and the contacts that are moved by the armature (A) are not shown here.
When the core is saturated, only the winding inductance is effective and not the inductance of the iron core, which is larger by a factor of µr. (~factor 1000). Of course this does not happen all at once but rather abruptly.
This means that it can store more additional energy in the magnetic field in one direction than in the other.
If a suitable pulse is applied to the coil and you measure the stored energy, you can distinguish whether the premagnetization was in one direction or the other.
The pulse must provide enough energy to saturate the core in case of equal premagnetization (else we would not see a difference) but it must be low enough not to switch the relais over.
The energy necessary has to be determined once depending on the relay you use.
Now you can dissipate the stored energy via a zener diode and simply measure the time until the voltage drops below a certain threshold. This time is roughly proportional to the energy.
A suitable voltage divider, which lowers the Zener voltage to just below VCC, allows any port to be used so that no analog input or ADC is required.
Here we can see a clear difference depending on the state of the relais.
The required pulse and measuring times are in the range of some 10 µs up to a few ms.