Smart ventilation control for buildings