Wiki source code of nest_set.py
Last modified by Richard Johnson on 2018/08/01 00:47
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | {{{#! /usr/bin/env python | ||
2 | |||
3 | import requests | ||
4 | import sys | ||
5 | |||
6 | my_token = 'my_nest_access_token' | ||
7 | |||
8 | everything = requests.get('', | ||
9 | headers={'Authorization': 'Bearer ' + my_token, 'Content-Type': 'application/json'}) | ||
10 | |||
11 | for x in everything.json()['thermostats']: | ||
12 | device_id = x | ||
13 | break | ||
14 | |||
15 | if sys.argv[1] == 'off': | ||
16 | print 'off' | ||
17 | cmd = 'off' | ||
18 | elif sys.argv[1] == 'on': | ||
19 | print 'on' | ||
20 | cmd = 'heat-cool' | ||
21 | |||
22 | set = requests.put('' + | ||
23 | device_id + | ||
24 | '?auth=my_nest_access_token', | ||
25 | headers={'Authorization': 'Bearer ' + my_token, 'Content-type': 'application/json'}, | ||
26 | data='{"hvac_mode": cmd}') | ||
27 | }}} |