11

I am trying to change the temperature of my Nest programmatically (Android), without any luck. Requests work maybe 1 in 30-50 tries.

I have tried doing it through the Firebase Nest SDK, and the NestAPI.CompletionListener doesn't get called at all. Seeing how that doesn't work, I tried it with the REST api, where it worked twice, and then again 1 in 30 tries. I also tried it with curl from the command line, with the same results, until I finally got "blocked" because of the rate limiting. Before being blocked, requests were returning the full thermostat object, just like doing a GET request instead of PUT.

When the temperature actually did get updated, the response contained just the new target_temperature_high_c and target_temperature_high_c values.

Has anyone else seen similar behavior ?

Edit: added some code below

Here's my code using the Nest Android API (based on Firebase):

NestAPI.CompletionListener completionListener = new NestAPI.CompletionListener() {
    public void onComplete() {
        Debug.d("NEST", "request complete");
    }
    public void onError(int errorCode) {
        Debug.e("NEST", "error: "+errorCode);
    }
};
NestAPI.getInstance().setTargetTemperatureHighC(myNest.getDeviceID(), 25, completionListener);

This only works if I make that call once an hour. If I even try to do it twice, the second try doesn't work.

Next, I tried with the REST interface. This seems work more often (worked 5-6 times, after which it the API started acting like I was doing GET requests instead of PUT.

JSONObject dataToSend = new JSONObject();
dataToSend.put("target_temperature_low_c", 23);
dataToSend.put("target_temperature_high_c", 26);

HttpPut httpost = new HttpPut("https://developer-api.nest.com/devices/thermostats/"+myNest.getDeviceID()+"?auth="+myAuthToken);
httpost.setHeader("Content-type", "application/json");

httpost.setEntity(new StringEntity(dataToSend.toString()));
HttpResponse response = defaultHttpClient.execute(httpost);
HttpEntity entity = response.getEntity();

String response = convertStreamToString(entity.getContent());

Edit 2: Just tested this with the Nest Home Simulator, and it works perfectly fine. The real hardware is problematic though

zrgiu
  • 6,200
  • 1
  • 33
  • 35
  • Can you post exactly what call you were making? The URL plus the payload? I'm assuming these were all PUT requests? – urman Dec 15 '15 at 18:05
  • added my code samples. Again: these work a few times, after which .. they don't – zrgiu Dec 15 '15 at 21:15

1 Answers1

4

From the javadocs for setTargetTemperatureHighC it says https://github.com/nestlabs/android-NestDK/blob/master/NestLib/src/main/java/com/nestapi/lib/API/NestAPI.java#L111

This value is only relevant when in "Heat and Cool" mode. Otherwise, see {@link #setTargetTemperatureC(String, Long, com.nestapi.lib.API.NestAPI.CompletionListener)}

You can check the mode using Thermostat.getHVACMode()

and if it is not in Heat and Cool mode you should use:

NestAPI.setTargetTemperatureC

i.e. if you where telling the Nest device to go to a temperature of 50deg's when it's current temp was 30deg and it was in "cool" mode - it would ignore you.

(This maybe why it worked once, as you asked it to warm up, when it was in heat mode - once it hits this temperature it could go into cool mode and asking it to heat more will be ignored.)

Blundell
  • 75,855
  • 30
  • 208
  • 233
  • Sorry, I should have been more clear. The thermostat **is** in Heat & Cool mode. – zrgiu Dec 20 '15 at 17:09
  • doesn't look like that from your example, you use `NestAPI.getInstance()` explicitly without a check for the mode? – Blundell Dec 20 '15 at 17:51
  • If I were to put the full Activity I would have filled a few pages. – zrgiu Dec 20 '15 at 18:09
  • 1
    just saying what I've described is pretty intrinisic to your problem and not putting it in the question makes me wonder what else you've missed out, in that we have to guess the answer. You should always attempt to create the minimal working prototype that reproduces your problem, with all avenues covered that you have explored. – Blundell Dec 20 '15 at 18:42
  • Just tested this with the simulator, where it works perfectly fine. As for the sample code: you are right, could have added more at first. Now that the test with the simulator confirms the code itself is ok, I have to start looking for other possible sources. – zrgiu Dec 20 '15 at 19:04