Variable not updating

https://forum.athom.com/discussion/comment/61291/#Comment_61291 maybe an answer?

I do have the same issue.

It has te do with the way HomeyScript cashes the API.get for.

As long as HomeyScript is not restarted, the values of capabilities may be wrong.
I dont know why yet.

And yes, you can have scripts run for hours.
For sample, having a loop, asking every 20 seconds a question via speechInput.
The script wil run until it completes.

A possible solution could be:
var cap = device.makeCapabilityInstance(‘measure_temperature’, functionToExecute);

function functionToExecute(capabilityValue) {
//This function wil run every time the measured temperature changes,
// except changes you make with the above [cap] variable
}

Hi mate,
are you using
var cap = device.makeCapabilityInstance(‘measure_temperature’, functionToExecute);
and it works?

Yeah (sorry about late response) for me this work. Other workaround is easier: refresh the whole HomeyApi.

The HomeyApi chashes the capabilitiesvalues and update it through the makeCapabilityInstance.
But requesting a new homeyAPI wil also give you one with empty lazy loading, so get the same device again from another/new homeyAPI and it will have the correct (current) value.

The latest HomeyScript version 3.2.3 should not have this caching anymore. Because every script invocation gets it’s own API instance. You can also call:

getDevice({ id: 'someId', $skipCache: true })

Also one year later response :rofl:

1 Like