Optimizing Energy Use of SmartFarms with Smartgrid Integration