02/23/2019 Update: I fire off a 1750ms timer after the sendCommand for the first setpoint change. When the timer expires, I issue the second sendCommand for the other setpoint. Apparently, occasionally 1750ms is not long enough for the operation to complete. In the case below, it took 2.448 seconds to complete.
2019-02-23 20:49:21.030 [ItemCommandEvent] Item 'TargetTemperatureMax' received command 76.0
2019-02-23 20:49:21.041 [NestBridgeHandler] PUT content: {"target_temperature_high_f":76}
2019-02-23 20:49:21.046 [NestBridgeHandler] Re-using access token from configuration: c.'access token'
2019-02-23 20:49:23.478 [NestBridgeHandler] PUT response: {"target_temperature_high_f":76}
I have made my “delay” smarter by waiting in 250ms increments up to a maximum of 3 seconds (for now). If it hasn’t successfully made the change after 3 seconds, then I raise a warning and abort any subsequent corresponding setpoint change. This is better, but it didn’t catch every problem (see log in update below).
val Functions.Function2<String,Number,Boolean>
setTemperatureSetpoint = [ String sSetpoint,
Number nSetpointValue |
try
{
APIRateThrottled.postUpdate(ON)
setpointAdjusted.postUpdate(ON)
var itemName = "TargetTemperatureMax"
if (sSetpoint.toUpperCase.contains("MIN"))
itemName = "TargetTemperatureMin"
val setpointItem = gTempSetpoints.members.filter [ i | (i.name == itemName) ].head
setpointItem.sendCommand((nSetpointValue).doubleValue)
// Loop counter waiting for the setpoint change to complete
// 12 loops of 250ms is 3 seconds
var iSetpointWaitLoop = 12
while((iSetpointWaitLoop=iSetpointWaitLoop-1) >= 0)
{
Thread::sleep(250)
if ((nSetpointValue).doubleValue == (setpointItem.state as QuantityType<Number>).doubleValue)
{
logInfo ("myLog", "setTemperatureSetpoint - Delay loop counter down to {}.", iSetpointWaitLoop)
APIRateThrottled.postUpdate(ON)
setpointAdjusted.postUpdate(ON)
TargetSetTemperature.postUpdate((nSetpointValue).doubleValue)
TargetSet.postUpdate(sSetpoint)
return true
}
}
logWarn("myLog", "setTemperatureSetpoint - {} set unsuccessful.", sSetpoint)
return false
}
catch(Exception e)
{
logError("myLog", "Failure in setTemperatureSetpoint: {}", e.toString)
return null
}
]
This looping delay waiting for the Item value to correspond to the requested change isn’t catching all API error instances. The looping counter does vary. I’ve seen the “counter down to” values range between 5 and 11. I don’t have but a couple of instances, but I think this “wait for the requested value to match the Item value” fails when and API error occurs and the Item is “predicted to become”. The predicted events don’t always occur when a setCommand
is performed. For those instances where an API occurs and there is not “predicted” instance, the “wait for match” works fine. I have no idea how to detect the difference in how sendCommand
processes (when it’s predicted and when the Item just receives it in one step).
In the instance below, the API error did not actually come back until about a tenth after the matching detector thought it matched. Since I was not able to detect the first setpoint not being set, the second one failed due to failing the 3 degree gap.
02/24/2019 Update:
2019-02-24 15:12:31.947 [ItemCommandEvent] Item 'TargetTemperatureMin' received command 71.0
2019-02-24 15:12:31.952 [ItemStatePredictedEvent] TargetTemperatureMin predicted to become 71.0
2019-02-24 15:12:31.952 [NestBridgeHandler] Putting data to: https://firebase-apiserver35-tah01-iad01.dapi.production.nest.com:9553/devices/thermostats/,deviceID>
2019-02-24 15:12:31.957 [NestBridgeHandler] PUT content: {"target_temperature_low_f":71}
2019-02-24 15:12:31.960 [NestBridgeHandler] Re-using access token from configuration: c.<accessToken>
2019-02-24 15:12:32.198 setTemperatureSetpoint Delay loop counter down to 11.
2019-02-24 15:12:32.244 [ItemCommandEvent] Item 'TargetTemperatureMax' received command 74.0
2019-02-24 15:12:32.333 [NestBridgeHandler] PUT response: {"error":"blocked","type":"https://developer.nest.com/documentation/cloud/error-messages#blocked","message":"blocked","instance":"f9000f9b-d12e-4198-af12-5d6cc2297ec1"}
2019-02-24 15:12:32.335 [NestBridgeHandler] Nest API error: ErrorData [error=blocked, type=https://developer.nest.com/documentation/cloud/error-messages#blocked, message=blocked, instance=f9000f9b-d12e-4198-af12-5d6cc2297ec1]
2019-02-24 15:12:32.337 [NestBridgeHandler] Nest API error: blocked
2019-02-24 15:12:32.339 [NestBridgeHandler] Putting data to: https://firebase-apiserver35-tah01-iad01.dapi.production.nest.com:9553/devices/thermostats/<deviceID>
2019-02-24 15:12:32.341 [NestBridgeHandler] PUT content: {"target_temperature_high_f":74}
2019-02-24 15:12:32.343 [NestBridgeHandler] Re-using access token from configuration: c.<accessToken>
2019-02-24 15:12:32.599 [NestBridgeHandler] PUT response: {"error":"Cannot set target temperature closer than 3.0 degrees F","type":"https://developer.nest.com/documentation/cloud/error-messages#range-error","message":"Cannot set target temperature closer than 3.0 degrees F","instance":"fe3f1651-5550-4e7d-93e3-34fcd7068682","details":{"min":"3.0","scale":"F"}}
2019-02-24 15:12:32.602 [NestBridgeHandler] Nest API error: ErrorData [error=Cannot set target temperature closer than 3.0 degrees F, type=https://developer.nest.com/documentation/cloud/error-messages#range-error, message=Cannot set target temperature closer than 3.0 degrees F, instance=fe3f1651-5550-4e7d-93e3-34fcd7068682]
2019-02-24 15:12:32.605 [NestBridgeHandler] Nest API error: Cannot set target temperature closer than 3.0 degrees F
Mike