Last active
August 29, 2015 14:12
-
-
Save davemasse/5f32e895b38a232fec46 to your computer and use it in GitHub Desktop.
Check the away temperature of Nest thermostats and send an SMS notification via Twilio if the difference is greater than the defined number of degrees Fahrenheit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nest_thermostat as nest | |
import twilio | |
import twilio.rest | |
from nest_thermostat import utils as nest_utils | |
import settings | |
def main(): | |
sent_message_count = 0 | |
client = twilio.rest.TwilioRestClient(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN) | |
napi = nest.Nest(settings.NEST_USERNAME, settings.NEST_PASSWORD) | |
for structure in napi.structures: | |
if structure.away: | |
for device in structure.devices: | |
current_temp = nest_utils.c_to_f(device.temperature) | |
current_temp = int(round(current_temp)) | |
away_temp = nest_utils.c_to_f(device._device.get('away_temperature_low')) | |
away_temp = int(round(away_temp)) | |
# Notify if away temp is TRIGGER_TEMP_DIFF degrees above current | |
if (current_temp <= (away_temp - settings.TRIGGER_TEMP_DIFF)): | |
result = '%s (%s): Current temp is %sF, but it should be %sF' % (structure.name, device.name, current_temp, away_temp,) | |
print message | |
try: | |
for number in settings.TWILIO_TO_NUMBERS: | |
print 'Notifying %s\n' % (number,) | |
message = client.messages.create( | |
body = message, | |
to=number, | |
from_=settings.TWILIO_FROM_NUMBER | |
) | |
sent_message_count += 1 | |
except twilio.TwilioRestException as e: | |
print e | |
else: | |
message = '%s (%s): Temp OK\nCurrent: %sF | Set: %sF\n' % (structure.name, device.name, current_temp, away_temp,) | |
print message | |
print 'Sent message count: %s' % (sent_message_count,) | |
if __name__ == '__main__': | |
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-e git+https://github.com/jkoelker/nest_thermostat.git#egg=nest | |
twilio |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NEST_USERNAME = '' | |
NEST_PASSWORD = '' | |
TWILIO_ACCOUNT_SID = '' | |
TWILIO_AUTH_TOKEN = '' | |
TWILIO_FROM_NUMBER = '' | |
TWILIO_TO_NUMBERS = [] | |
# Temperature difference (in degrees F) after which to send notification | |
TRIGGER_TEMP_DIFF = 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment