This could be tricky depending on what circuitry is inside the fan. If power is controlled by a relay then it’s probably not difficult to bypass but if this is a multi speed fan then it’s probably solid state which is not easy.
One other way to do this is to get an esp IR remote controller like this one.