-
Notifications
You must be signed in to change notification settings - Fork 79
Description
I am trying to periodically run with cron a script that will change my Nest from heat to cool and back based on logic using current set point and current temp.
I can read the current temp and change the set point with this code but cannot get the mode change working with the hacked code that I am trying. I have added this section to the code I downloaded:
def set_mode(self, state):
data = '{"target_change_pending":true,"target_temperature_type":"' + str(state) + '"}'
req = urllib2.Request(self.transport_url + "/v2/put/device." + self.serial,
data,
{"user-agent":"Nest/1.1.0.10 CFNetwork/548.0.4",
"Authorization":"Basic " + self.access_token,
"X-nl-protocol-version": "1"})
res = urllib2.urlopen(req).read()
print res
I get this when I try to run it from the command line on my CentOS box that does have curl installed as a module and with yum:
./nest.py --user [email protected] --password notmypassword setmode off
Traceback (most recent call last):
File "./nest.py", line 261, in ?
main()
File "./nest.py", line 245, in main
n.set_mode(args[1])
File "./nest.py", line 157, in set_mode
res = urllib2.urlopen(req).read()
File "/usr/lib64/python2.4/urllib2.py", line 130, in urlopen
return _opener.open(url, data)
File "/usr/lib64/python2.4/urllib2.py", line 364, in open
response = meth(req, response)
File "/usr/lib64/python2.4/urllib2.py", line 471, in http_response
response = self.parent.error(
File "/usr/lib64/python2.4/urllib2.py", line 402, in error
return self._call_chain(_args)
File "/usr/lib64/python2.4/urllib2.py", line 337, in _call_chain
result = func(_args)
File "/usr/lib64/python2.4/urllib2.py", line 480, in http_error_default
raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 400: Bad Request
Can you help me get this working from the command line please?
Ron