Skip to content

Instantly share code, notes, and snippets.

@benwtr
Last active November 4, 2015 20:21
Show Gist options
  • Save benwtr/123fd39b8134d30e89ea to your computer and use it in GitHub Desktop.
Save benwtr/123fd39b8134d30e89ea to your computer and use it in GitHub Desktop.
Ever wish your thermostat had a "turn heat on for x minutes" feature? Me too, but not enough to spend more than 5 minutes writing a script to do it
#!/usr/bin/env ruby
# Tell a nest thermostat to kick the heat on for n minutes
require 'nest_thermostat'
unless ARGV[0]
puts 'Usage: warmup.rb <minutes>'
exit 1
end
nest = NestThermostat::Nest.new(
email: ENV['NEST_EMAIL'],
password: ENV['NEST_PASS'],
temperature_scale: :celsius
)
seconds_to_warm = (ARGV[0].to_i * 60) + 30
before_temp = nest.temperature
warm_temp = nest.current_temperature + 1
nest.temperature = warm_temp
sleep seconds_to_warm
# reset to previous temp unless the thermostat has been changed by something else
nest.temperature = before_temp unless nest.temperature != warm_temp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment