Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Change Mode Functionality #4

Open
youngrh opened this issue Nov 25, 2012 · 3 comments
Open

Add Change Mode Functionality #4

youngrh opened this issue Nov 25, 2012 · 3 comments

Comments

@youngrh
Copy link

youngrh commented Nov 25, 2012

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

@RandyLevensalor
Copy link

The mode is set at the structure context, not the device context. Use /v2/put/shared. for the url.

The valid modes are cool, heat, range, and off.

def set_mode(self, state):
    data = '{"target_temperature_type":"' + str(state) + '"}'
    req = urllib2.Request(self.transport_url + "/v2/put/shared." + 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

@youngrh
Copy link
Author

youngrh commented Nov 29, 2012

Randy,

Thank you so much for that hint. Not being a python programmer certainly
put me at a disadvantage!.

All I wanted to do was to create a feature that the Nest folks left out. I
like to sleep in a cool house but this time of year it really doesn't get
cold outside until very late in the evening. I wanted to switch the Nest
to cool before going to bed and have a program switch it back to heat
sometime early in the morning after the house had cooled down below a
certain temp. The result would be that the system would switch to heat
mode while I was sleeping but not actually turn on the heat until it got
down to my scheduled setpoint.

In other words, switch between my heating and cooling schedules instead of
Nest's Range mode which is useless to me. If one sits in the house all day
like my disabled wife does, a 5 degree temp range is just uncomfortable
part of the time!

smbaker and/or Randy,

I have attached the nest.py.rhy (rhy is my initials) that contains my
inexperienced hacks to your code. I have also attached the script that I
wrote to use your code. Please feel free to use, modify, include in your
repos, etc. I execute the code every 20 min and write output to a log with
the following crontab for root entry:

*/20 * * * * /root/bin/nestAPI >> /var/log/nest.log # run this every 20
minutes

Thank you so much for all the contributor's help! It was fun adding
functionality to a community project that I could actually use!!

Ron

Regards,

Ron Young
919-621-9015
http://www.linkedin.com/in/ronhyoung

+++++++++++++++++++
Little tiny dreams require little tiny thoughts and little tiny steps.
Great big dreams require great big thoughts and little tiny steps.
+++++++++++++++++++
Kosh: The avalanche has already started. It is too late for the pebbles
to vote.

On Sun, Nov 25, 2012 at 6:24 PM, RandyLevensalor
[email protected]:

The mode is set at the structure context, not the device context. Use
/v2/put/shared. for the url.

The valid modes are cool, heat, range, and off.

def set_mode(self, state):
data = '{"target_temperature_type":"' + str(state) + '"}'
req = urllib2.Request(self.transport_url + "/v2/put/shared." + 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


Reply to this email directly or view it on GitHubhttps://issues/4#issuecomment-10700319.

@abemassry
Copy link

Just submitted this pull request #10 based on this issue abemassry@89d3713

It's working just like @RandyLevensalor shows
Thanks,
Abe

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants