Programmable logic controller for home and building automation