Home » Android » android – Nest Thermostat temperature not getting updated

android – Nest Thermostat temperature not getting updated

Posted by: admin May 14, 2020 Leave a comment

Questions:

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

How to&Answers:

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.)