Smart relays and controllers