Shelly devices might help here. There are various models of relays that can be controlled either by dry contact inputs or via MQTT/HTTP commands.
They also have settings for relay state on power-up.