A comfort-based, energy-aware HVAC agent and its applications in the smart grid