I'm trying to build a Home Automation Project for my Masters and using the Nest thermostat as part of the project. I'm trying to write an android app to change the target temperature of the thermostat. My thermostat is set to cool. From the original Nest App, I can change the temperature from 50 - 90 F with ease. Following the Nest SDK sample code, I'm trying to change the target temperature. When I build my project, changing the temperature works fine for the first 10 times and then stops working at all. If I change, the target value from the Nest App, the value in my app is updated instantly. I have two TextView on click listeners as in sample code. Here's my onClick code -
@Override
public void onClick(View v) {
if (mThermostat == null || mStructure == null) {
return;
}
String thermostatID = mThermostat.getDeviceId();
//System.out.println("ThermoID " + thermostatID);
String mode = mThermostat.getHvacMode();
System.out.println("Mode " + mode);
String awayState = mStructure.getAway();
long temp = mThermostat.getTargetTemperatureF();
//System.out.println("Temp "+temp);
switch (v.getId()) {
case R.id.temp_incr:
++temp;
System.out.println("Temp Incr " + temp);
mTargetTemp.setText(String.format(DEG_F, temp));
mNest.thermostats.setTargetTemperatureF(mThermostat.getDeviceId(), temp);
break;
case R.id.temp_decr:
--temp;
System.out.println("Temp Decr " + temp);
mTargetTemp.setText(String.format(DEG_F, temp));
mNest.thermostats.setTargetTemperatureF(mThermostat.getDeviceId(), temp);
break;
}
}
From my Debug statements, I can see that the temperature value is being updated in the console but not written to the thermostat. The permissions of my product are set to Thermostat read/write v4. My question is why does it only work for a few times? Has anyone else faced a similar issue? Is there any workaround which works consistently?