Skip to main content

Control Nest from linux shell (or other programs)

The steps below let’s you create a shell script to control the Nest Thermostat from the linux shell. Once created the shell script you can control your Nest Thermostat in other applications like PiMatic, Domoticz…

Step 1 – Create a Nest Developer account and product

Nest Developer Product ScreenYou need to create a Nest Developer account and product to get the API access you need to control your thermostat.
You must create a Nest Developer account here if you don’t have one –

Then create a Product.  Mine is called “Control Nest from shell”.  Make sure you grant read/write permissions for the Thermostat and Away.

Copy down the Product ID and Product Secret values.  You will need them later.  You will also need the Authorization URL in the next step so don’t close this window!

Step 2 – Get your PIN Code for your Nest Thermostat

Nest Thermostat Authorization ScreenCopy the Authorization URL shown on the right side of the Nest Developer Product Details page and paste it into a new browser window.  It should prompt you to allow your Product to connect to your personal Nest account.  Click on Continue.

It should then give you a PIN Code.  Copy this down carefully!!!


Step 3 – Get your Access Code

Now that you have a PIN Code, you need to generate an API Access Code using your PIN Code and the Product ID and Product Secret from your Nest Developer Product Details Page.

curl -X POST ""

Replace the %YOUR_*% values with the correct values for your application the Nest PIN. And replace & with &.  Then execute this in your command line.  You should get back a long access token that starts with a “c.”.  This long string is your Access Token and will be used for authorization for API calls.

Step 4 – Get Your Nest Thermostat and Structure IDs

Now that you have your Access Token you can retrieve the IDs for your Thermostat and Structure (Home) which you’ll need to setup the command line API aliases.

curl -L\?auth\=%YOUR_ACCESS_TOKEN%

This command will return a big block of JSON data.  What you are looking for in there are two values: the device_id and the structure_id.  Copy those values, you will need them soon.

Step 5 – Create the shell script

Now you have your Access Token, Device ID and Structure ID it’s time to create the shell script to control your Nest Thermostat. Create a file with the data below, save it in /usr/bin and make it executable:


case $1 in
curl -s -L${DEVICEID}/humidity\?auth\=${ACCESSTOKEN}

curl -s -L${DEVICEID}/ambient_temperature_c\?auth\=${ACCESSTOKEN}

curl -s -L${DEVICEID}/target_temperature_c\?auth\=${ACCESSTOKEN}

curl -s -L -X PUT "${DEVICEID}/target_temperature_c?auth=${ACCESSTOKEN}" -H "Content-Type: application/json" -d "$2"

if [ "$2" == "away" ];
curl -s -L -X PUT "${STRUCTUREID}/away?auth=${ACCESSTOKEN}" -H "Content-Type: application/json" -d '"away"'

if [ "$2" == "home" ];
curl -s -L -X PUT "${STRUCTUREID}/away?auth=${ACCESSTOKEN}" -H "Content-Type: application/json" -d '"home"'

if [ -z $2 ];
echo "Presence not set! Must be set to home or away."

echo "Parameters missing, usage:"
echo "nest read.temp Reads actual temperature from Nest"
echo "nest read.humidity Reads humidity from Nest"
echo "nest read.targettemp Reads target temperature from Nest"
echo "nest set.targettemp 20 Sets target temperature on Nest to 20"
echo "nest set.presence away Sets presence on Nest to away"
echo "nest set.presence home Sets presence on Nest to home"

Leave a Reply

Your email address will not be published. Required fields are marked *