Fan controller

The schematic I posted above had the relays wired differently than the linked post. The linked post is a bit more intuitive as one and only one relay is energized for each fan speed. To wire the 4th relay to LF this would be the arrangement:

HA reboot should not impact the fan state. It would keep running at current speed.

Fan state after ac power loss to fan or esp reboot is controlled by fan: restore_mode