Solution for electric window limit switch

Hello everyone!
so I have this window that goes up and down using an electric motor which is controlled by HA (using RF).
the motor has two inputs(not including the power supply) for each direction and each input is connected to an RF outlet.
anyway,the motor limit switch stopped working suddenly! I don’t why:which means the motor no longer knows when to stop and it can either roll up too much or go down too much which harms the window and results in a lot of problems.
the switch limits couldn’t be fixed, so I thought about asking the HA community for a solution:maybe with HA automation or something,because installing position sensor for the windows is not possible in my case.
thanks for your help!