I am not sure about how onChangeRequest manages changes in a device, I mean whether the device is updated just after the call or after some delay? What I am seeing is that some of the attributes are not changed immediately, so what I do is calling onPoll() at the end of onChangeRequest() to accelerate the device update of all its attributes, which is not efficient. Is there a way to only update the device which is being changed or doing it faster? Many thanks!
I would like to know what @bill says too, but would you mind sharing your code for calling onPoll() at the end of onChangeRequest()? That would be helpful to me.
Greg, I just call onPoll() at the end of onChangeRequest(). The point is that when changing the Nest thermostat ECO mode to HEAT, for example, you need to wait until the thermostat updates the values since they are not available in the variables… So once the mode is changed, from ECO for example, you will need to wait until the thermostat updates all the values, i.e. “HeatingSetpoint” and/or “CoolingSetpoint”. These values are null when ECO mode is on and you cannot change them in the onChangeRequest() when changing the mode, because it is too early for the thermostat which is changing its mode… I guess it is clear? I will post the plugin and forms once I find a way to update or refresh the thermostat after changing its mode…
Many thanks Greg!
Yes it is clear and you don’t need to post. I understand now. I was calling for App.refreshDevice but your way is better. I’m going to try it until we have a better option, thanks!
Well, calling onPoll() does the job but it updates all the devices and in the case of the Nest thermostats if you have several of them you will be making too many calls to the API and then it will be disconnected for a while unfortunately, so at the end I am not using it for this reason…
Ohh yes, ok good call. I’ll stay with App.refreshDevice.
What does App.refreshDevice do? If it updates only the device being changed its very good, that is what I am looking for…
Greg, I succeeded to make it work!, although I had to add a delay of 300 to allow the thermostat to update the attributes. Since it is a ComboBox I am using the SelectionChanged event.
Now I need to find a way to either clear the form or postpone the clearing in a way so as not to show some empty controls…
What I do a lot of the time is update the device object immediately after sending the HTTP request. I probably would not recommend calling onPoll in onChangeRequest. This should work better.
The device
object is a parameter to the function, so you can update it there just like what’s being done in that example “virtual” plugin example in the docs.
function onChangeRequest(device, attribute, value) {
switch (attribute) {
case "Switch":
// Send your HTTP request here
// Then update the value immediately
device.Switch = value;
break;
default:
break;
}
}
Bill, this is exactly what I always do, but in the specific case of the thermostat mode this strategy does not work because you need to update other parameters, like the “HeatingSetpoint” or “CoolingSetpoint” which, for example, are null if the mode is ECO. And if you try to update them after changing the mode from ECO to HEAT it will not work because the thermostat takes care of managing these values and it will be too early. It does work in case you manually want to raise the temperatures though, through the details template once the mode is in HEAT or COOL. So the only alternative is to speed up the changes/updates of the device, but just in the case where you are changing the thermostat modes, not in the rest of the cases… I hope it is clear… Would you recommend another strategy? Many thanks Bill!