# Variable not updating

**URL:** <https://community.homey.app/t/variable-not-updating/23230>\
**Category:** Questions & Help\
**Created:** [December 27, 2019, 9:44pm UTC](https://community.homey.app/t/variable-not-updating/23230 "2019-12-27T21:44:04Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![JPe4619](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jpe4619/32/9017_2.png) [@JPe4619](https://community.homey.app/u/JPe4619)\
**Post date:** [January 2, 2020, 4:32pm UTC](https://community.homey.app/t/variable-not-updating/23230/21 "2020-01-02T16:32:36Z")

</div>

[https://forum.athom.com/discussion/comment/61291/#Comment\_61291](https://forum.athom.com/discussion/comment/61291/#Comment_61291) maybe an answer?

---

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [January 2, 2020, 10:24pm UTC](https://community.homey.app/t/variable-not-updating/23230/22 "2020-01-02T22:24:06Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [January 7, 2020, 2:37pm UTC](https://community.homey.app/t/variable-not-updating/23230/23 "2020-01-07T14:37:55Z")

</div>

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  
}

---

<div class="post-metadata">

**Author:** ![ropske](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ropske/32/16716_2.png) [@ropske](https://community.homey.app/u/ropske)\
**Post date:** [January 12, 2020, 7:23pm UTC](https://community.homey.app/t/variable-not-updating/23230/24 "2020-01-12T19:23:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Arie\_J\_Godschalk](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/arie_j_godschalk/32/63027_2.png) [@Arie\_J\_Godschalk](https://community.homey.app/u/Arie_J_Godschalk)\
**Post date:** [February 25, 2021, 11:03pm UTC](https://community.homey.app/t/variable-not-updating/23230/25 "2021-02-25T23:03:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Jero](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/jero/32/17556_2.png) [@Jero](https://community.homey.app/u/Jero)\
**Post date:** [February 25, 2021, 11:42pm UTC](https://community.homey.app/t/variable-not-updating/23230/26 "2021-02-25T23:42:07Z")

</div>

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 🤣

[Previous page](https://community.homey.app/t/variable-not-updating/23230.md?page=1)
