A thermostat is a device for maintaining the temperature of a system within a range by controlling the flow of heat energy into or out of the system.