Can I sell and install homemade smart light switches legally?
In the US, nothing electrical can be installed unless it is listed and labeled by a nationally recognized testing laboratory. That is not a law, but is part of the administrative regulations of every jurisdiction. Local regulations also determine who can perform installation and repairs.
See also AC Wiring rules for switched mains output device on this site.