os x

Home/Tag: os x

Control Nest Thermostat From the Command Line

I have a Nest thermostat, which is a wonderful piece of technology, however that meant that I had to get my phone out of my pocket, unlock it, launch the Nest app, wait for it to connect, and then adjust the temperature.  I wondered if it was possible to control my Nest from the command line on my laptop, which I am always working in anyhow.  The answer is YES, and this is HOW:

 

Step 1 – Create a Nest Developer 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.
Create a Nest Developer account here – https://developer.nest.com/

Then create a Product.  Mine is called “Devons Command Line Interface”.  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 "https://api.home.nest.com/oauth2/access_token?client_id=%YOUR_PRODUCT_ID%&code=%YOUR_PIN_CODE%&client_secret=%YOUR_PRODUCT_SECRET%&grant_type=authorization_code"

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 https://developer-api.nest.com/devices/thermostats\?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 Command Line Aliases

Now you have everything you need!  I use ZSH, but this should work just the same in BASH or the shell of your choice.  I created four aliases in my .zshrc (use your .bashrc or preferred file).  Each command will need your Access Token, and either your Device ID or your Structure ID.

nestset() {
curl -L -X PUT "https://developer-api.nest.com/devices/thermostats/%YOUR_DEVICE_ID%/target_temperature_f?auth=%YOUR_ACCESS_TOKEN%" -H "Content-Type: application/json" -d "$1"
}

nestget() {
curl -L https://developer-api.nest.com/devices/thermostats/%YOUR_DEVICE_ID%/target_temperature_f\?auth\=%YOUR_ACCESS_TOKEN%
}

nestaway() {
curl -L -X PUT "https://developer-api.nest.com/structures/%YOUR_STRUCTURE_ID%/away?auth=%YOUR_ACCESS_TOKEN%" -H "Content-Type: application/json" -d '"away"'
}

nesthome() {
curl -L -X PUT "https://developer-api.nest.com/structures/%YOUR_STRUCTURE_ID%/away?auth=%YOUR_ACCESS_TOKEN%" -H "Content-Type: application/json" -d '"home"'
}

 

Step 6 – Control Your Nest Thermostat From the Command Line!

Now that you’ve defined those aliases you are ready to use them!

nestget returns the current target temperature your Nest is set to:

[devon:~]$ nestget
71%

nestset takes a single argument which is the new target temperature in Fahrenheit:
[devon:~]$ nestset 72
72%

nestaway sets your Nest into Away mode:
[devon:~]$ nestaway
"away"%

nesthome sets your Nest into Home mode:
[devon:~]$ nesthome
"home"%

 

 

 

Translation into Portuguese for https://www.homeyou.com/~edu/

Why I Love Having 8 Gigs of RAM

I recently upgraded my primary computer from a 15″ MacBookPro with 4 GB of RAM to a 17″ MacBookPro with 8 GB of RAM. That probably sounds gratuitous. Here’s why it’s not:

picture-3

I’m currently running:

  • Mac OS 10.5.6
  • Adium (IM chat client)
  • Mail.app (e-mail client)
  • iCal (calendar application)
  • iTunes (music)
  • OmniFocus (GTD todo list)
  • TextMate (text editor)
  • Preview (image viewer – for looking at screenshots, scanned requirements docs)
  • PostgreSQL (CouponEngine database)
  • pgAdmin (postgreSQL client and admin app)
  • Terminal
  • Safari 4 (primary browser)
  • Firefox 3 (for testing look and feel)
  • Eclipse (development environment)
  • Windows XP (running in Parallels-for testing and Oracle)
  • Oracle 10G (ATG database)
  • JBoss 4.0 + ATG 2006.3 with full Commerce stack
  • JBoss 4.2 + Seam application
  • ANT JVMs for running builds

This is what I need to run to do my job, and it takes more than 4 GB of RAM.

Now that I have 8 GB, I’m not longer running into swapping and paging delays, and I’m much more productive.

Having close to twice the screen real estate (~70% more I think), a faster CPU, and 8 hours of battery life don’t hurt either. This is the perfect machine for me.

Huge Logs and OS X

Another reason that I love my mac: it can handle 1.3 GB log files easily with built in tools. I recently received a huge log file in zipped form from a co-worker with the warning “good luck opening it, textpad won’t open it.”

After unzipping it to the full 1.3 GB size I was able to open it using the built in Apple log viewer Console.

I ended up mostly using the terminal and tools like cat, less, grep, etc… to quickly find what I wanted and view the log lines surrounding the events I was interested in.

No problem.

Time Machine To The Rescue

I ran an ANT task to undeploy an ATG Module, but I had my build property module location set incorrectly. As a result, I inadvertently deleted my entire ATG 7.1 installation.

Whoops.

I opened the containing directly in the Finder, where my ATG 7.1 USED to be, and hit TimeMachine. My laptop connected to my Time Machine over wireless, and let me browse through the last month or so of folder states for that directory. I went to the previous backup (about half an hour ago), and clicked Restore. Like magic, my entire missing ATG installation reappeared.

Pretty sweet stuff. Thanks Apple.

YouTube Gets Stuck After 2 Seconds

I recently started having an issue with YouTube playing a video without sound for 2 seconds, then stopping. This is a new laptop, so everything is fresh and new, leaving me with a ton of potential culprits: OS X, Safari 3.1.1, Flash, network, Perian, etc….

Googling showed that other people were having this issue across many OSes and browsers. Unfortunately, most of the advice was “reboot” or “change your network buffer” or “YouTube sucks!”. None of which helped me.

What did help, is downgrading from Flash Player 9.0.124.0 to 9.0.47.0 using the Adobe archive of Flash Players. I uninstalled the 9.0.124.0, and installed 9.0.47.0, and poof, no more problems with YouTube videos.

I hope this helps someone.