Good point, I can try an extension that saves the pin state as a preference and resets that on reboot.My ESP32 also randomly rebooting almost every day.
It's control power strip with refugium light, so it's easy to see when my refugium light turning on at night.
Main problem that ESP do not save Pin state after reboot.
I'm not a big fun of Arduino, so can't give the solution, but already thinking to rewrite this on Micropython
Downside is that one then doesn’t have the panic- option of cutting power in emergency, as reboot will reset to a possibly faulty behavior.