NEW YORK (AP) — Google will pay $3.2 billion to buy Nest Labs, which develops high-tech versions of devices like thermostats and smoke detectors, in its second-largest acquisition ever.

The search engine operator was an early investor in Nest Labs. It says the company’s Nest Learning Thermostat has been a “consistent best-seller.” The thermostat, which retails for $249, is designed to learn how inhabitants like their homes to be heated and cooled. Once it learns the consumers’ preferences, it automatically adjusts the temperature on its own.

Google Buys Company That Makes Popular Smart Thermostat for Over $3 Billion

SAN RAFAEL, CA – JANUARY 13: The Nest Learning Thermostat is displayed at a Home Depot store on January 13, 2014 in San Rafael, California. Google announced today that it has acquired Palo Alto, Calif. based digital smoke alarm and thermostat company Nest for $3.2 billion in cash. Justin Sullivan/Getty Images

Its Nest Protect alarm is intended to be less annoying than traditional alarms: when it detects rising smoke or carbon monoxide levels, it lights up yellow and speaks with human voice, giving consumers an option to turn the device off if there is no emergency. They can stop the alert by waving an arm. The Nest Protect costs $129 while an older smoke and carbon monoxide detector could cost $50 to $80.

Analyst Shyam Patil of Wedbush Securities said Google is positioning itself to offer products that work on the “Internet of Things” – specifically a “connected home” full of intelligent wireless devices that collect data and could be controlled with a smartphone. The “Internet of Things” is a global network that not only links computers, tablets and phones but connects everything from bikes to washing machines to thermostats. Last year Google introduced Chromecast, a device that lets users connect their TVs and mobile devices.

“It’s a big market opportunity and it provides Google with good technology to attack it over time,” Patil said in a telephone interview. He has a “Neutral” rating on Google shares.

The deal is Google’s biggest since it closed on the $12.5 billion purchase of Motorola in May 2012.

Google Buys Company That Makes Popular Smart Thermostat for Over $3 Billion

SAN RAFAEL, CA – JANUARY 13: The Nest Learning Thermostat is displayed at a Home Depot store on January 13, 2014 in San Rafael, California. Google announced today that it has acquired Palo Alto, Calif. based digital smoke alarm and thermostat company Nest for $3.2 billion in cash. Justin Sullivan/Getty Images

Nest Labs is based in Palo Alto, Calif. It was founded in 2010 by Tony Fadell, a gadget guru who helped design the iPod and original iPhone while working at Apple.

Google Inc. is based in Mountain View, Calif. Its shares fell $7.20 to $1,122.98 on Monday before the report and rose $6.02 to $1,129 in aftermarket trading.