We have a few Nest (formerly Dropcam) cameras that we’ve had pointed at the construction site of our new building. We’re paying for the lowest of the subscription services, the one that gets you 10 days of video storage but not the full “Nest Aware” package. The time lapse videos we were getting from the service were ok, but the cameras are capable of higher resolution than the videos we were getting. (1080 vs 720, I believe.) And there were some pretty unpleasant compression artefacts showing up, mainly in the sky and clouds, which make up a large portion of the frame with some of the cameras. Also, we want to be able to make time lapse videos covering months, maybe a year. I think you can do some of that with the higher priced subscriptions, but you definitely can’t with the cheap one, at least not easily. (The previous idea was to have someone download a daily time lapse every day and then assemble them in Final Cut as needed. That’s a lot of manual work for something which ought to be eminently automatable.)
Here’s what I did to get us the ability to make full resolution time lapse videos of arbitrary duration, over any period of time the cameras were running. I’m using an iMac running OS X, but this should work from a linux system or a Windows system with the right tools installed.
Step 1: Sign up for a Nest Developers account at https://developers.nest.com/
Step 2: Create a new “product” using your developer account. It’s only ever going to have one user — you — so you don’t need to worry about complying with the requirements of the product review phase. I called my product “Still grabber” and put it in the “Education and hobbyist” category. For the support URL, I entered our public web site. For permissions, I enabled “Camera + Images Read”, since it doesn’t need to write to the service. (When I wrote this, it was v3; I’ve done it again with v4 and it still works for me.)
Step 3: Get an authorization code
In your product details page, at the right, there are three pieces of information: Client ID, Client Secret, and Authorization URL. (“Client” used to be “Product”.) Copy the Authorization URL and load it in a browser. That should get you a page asking you to accept your product’s request to read still images from your camera. Click “Accept”, and you’ll get a PIN code to use later. Copy that down somewhere.
Step 4: Use curl to get a security token for your product
From a command line on a system where the utility “curl” is installed, run this command:
curl -o auth.txt -X POST -d 'code=AUTH_CODE&client_id=PRODUCT_ID&client_secret=PRODUCT_SECRET&grant_type=authorization_code' "https://api.home.nest.com/oauth2/access_token"
Where AUTH_CODE is the PIN you got in step 3, and PRODUCT_ID and PRODUCT_SECRET are the values from your product details page.
Once the command has run, you should have a file named auth.txt which contains a JSON string like this:
Keep that access_token value (the bit highlighted in yellow) safe; you’re going to be using it to authorize API requests next, and you don’t want other people to be able to do that for your account. Incidentally, that “315360000” means that this token is good for ten years. If you’re going to be doing this for longer, you’ll want to come back and generate a new token somewhere in year nine.
Step 5: Get the snapshot URL(s) for your camera(s)
From the command line again, run this command:
curl -o info.json --location-trusted -v -L -H "Content-Type: application/json" -H "Authorization: Bearer YOUR_ACCESS_TOKEN" -X GET "https://developer-api.nest.com/"
Use the access_token you got in step 4 in place of “YOUR_ACCESS_TOKEN”. That should get you a file named info.json with a whole lot of information about your devices. It’s hard to read, so you can make it prettier with the following command:
python -m json.tool < info.json > info.txt
Now open that info.txt in your text editor of choice and look for the string “snapshot_url”. If you have multiple cameras, there should be “name” and “name_long” values right above the snapshot_url value telling you which camera it means. “snapshot_url” is the URL you can use to get a full resolution still image from your camera at the time you make the request. Keep this URL safe, because you don’t want anyone else using it. Don’t, for example, use it directly to provide a live image on your public web site. There are rate limits on these kinds of requests, but I don’t know what the limits are. I’m requesting a snapshot from each camera once per minute, and that seems to be fine.
Step 6: Save a snapshot once per minute and assemble them into videos.
I’ll write this up in Part Two.
I’m adding some screenshots here, so people can double check what they’re doing against what I’m doing:
I’ve added the --location-trusted argument to the curl command to get the info.json file, as suggested in the comments; newer versions of curl require that.