Home server?
I have a dedicated home server that runs Unraid. It is primarily used to download and host media (Plex, sonarr, radarr, etc.) but I’ve also found it can be used for home automation purposes.
You can run Home Assistant in a VM/Docker. I primarily use Hubitat, but have a “Echo Speaks” plugin self hosted on a docker container.
I think you missed the point. You are overcomplicating something with a much easier solution.
You already have a “smart” switch. Make your programming smarter to avoid the problem instead of a using a complicated workaround.