An intelligent controller comprising: one or more processors for controlling an environmental condition within an enclosure, wherein the intelligent controller is configured to operate in a plurality of modes comprising: a normal mode wherein the environmental condition is controlled according to a stored control schedule; and an auto-away mode; one or more sensors for detecting indications of occupancy in the enclosure; one or more memories that stores a historical pattern of occupancy based on historical readings from the one or more sensors; instructions stored in the one or more memories that, when executed by the one or more processors, cause the one or more processors to perform operations comprising: periodically receiving measurements from the one or more sensors; determining times when the enclosure is likely unoccupied based at least in part on the measurements received from the one or more sensors not indicating occupancy for at least a first time interval, wherein a length of the first time interval is determined based at least in part on a portion of the historical pattern of occupancy; during the times when it is determined that the enclosure is likely unoccupied, causing the intelligent controller to transition from the normal operating mode to the auto-away mode; and decreasing the length of the first time interval if the portion of the historical pattern of occupancy indicates that it is becoming less likely that the enclosure is occupied during the first time interval. one or more processors for controlling an environmental condition within an enclosure, wherein the intelligent controller is configured to operate in a plurality of modes comprising: a normal mode wherein the environmental condition is controlled according to a stored control schedule; and an auto-away mode; a normal mode wherein the environmental condition is controlled according to a stored control schedule; and an auto-away mode; one or more sensors for detecting indications of occupancy in the enclosure; one or more memories that stores a historical pattern of occupancy based on historical readings from the one or more sensors; instructions stored in the one or more memories that, when executed by the one or more processors, cause the one or more processors to perform operations comprising: periodically receiving measurements from the one or more sensors; determining times when the enclosure is likely unoccupied based at least in part on the measurements received from the one or more sensors not indicating occupancy for at least a first time interval, wherein a length of the first time interval is determined based at least in part on a portion of the historical pattern of occupancy; during the times when it is determined that the enclosure is likely unoccupied, causing the intelligent controller to transition from the normal operating mode to the auto-away mode; and decreasing the length of the first time interval if the portion of the historical pattern of occupancy indicates that it is becoming less likely that the enclosure is occupied during the first time interval. periodically receiving measurements from the one or more sensors; determining times when the enclosure is likely unoccupied based at least in part on the measurements received from the one or more sensors not indicating occupancy for at least a first time interval, wherein a length of the first time interval is determined based at least in part on a portion of the historical pattern of occupancy; during the times when it is determined that the enclosure is likely unoccupied, causing the intelligent controller to transition from the normal operating mode to the auto-away mode; and decreasing the length of the first time interval if the portion of the historical pattern of occupancy indicates that it is becoming less likely that the enclosure is occupied during the first time interval.