Motor control for home and building automation