Maintaining a constant temperature by heating or cooling