To store the last on state you'll need a way to detect that power has been lost, then have enough power stored to save the last known state before the power really runs out. Could you show the circuit that you have to detect loss of power ? It may be that the circuit that you have to detect loss of power is not sending a signal to indicate a loss of power has occured.