# 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:** 20\
**Page:** 1

<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:** [December 27, 2019, 9:44pm UTC](https://community.homey.app/t/variable-not-updating/23230/1 "2019-12-27T21:44:04Z")

</div>

Hello,

My homeyscript is executed every 1 minute, its purpose is to control all my thermostat valves for heating. I will just show a little code here where my ‘problem’ is.  
i’ve got this code in my homeyscript:

Virtuele\_Thermostaat\_Badkamer=await Homey.devices.getDevice({id: ‘92d39e69-b6f3-4886-ba60-739b3967b01a’});  
var badkamer\_set=Virtuele\_Thermostaat\_Badkamer.capabilitiesObj[‘target\_temperature’].value;  
console.log("badkamer\_set: "+badkamer\_set);

The device Virtuele\_Thermostaat\_Badkamer is a virtual thermostat.  
When i set this device to 20degrees and i check in the log, it is set at 20 .

But when i change the virtual thermostat again, to for example 16, badkamer\_set stays at 20 in the log file and so all my thermostat valves staying at 20degrees instead of 16

when i check the information at the developer page for this device, there it is set at 16, so correct.  
So i wonder, am i’m doing something wrong with declaring my variables?

Can someone point me in the correct direction please? THank you!!

---

<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:** [December 28, 2019, 4:56pm UTC](https://community.homey.app/t/variable-not-updating/23230/2 "2019-12-28T16:56:35Z")

</div>

> [@ropske](#):
>
> Virtuele\_Thermostaat\_Badkamer=await Homey.devices.getDevice({id:

didn’t you forget to start this line with “ **let** ”

---

<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:** [December 28, 2019, 5:23pm UTC](https://community.homey.app/t/variable-not-updating/23230/3 "2019-12-28T17:23:08Z")

</div>

Hi mate, i need to declare every variable with let?  
So no need to use var or nothing, but use let?

Because i tried this before with let, but it remained the same, i will try agian, just to see.

---

<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:** [December 28, 2019, 5:41pm UTC](https://community.homey.app/t/variable-not-updating/23230/4 "2019-12-28T17:41:02Z")

</div>

I just tried by putting let to declare every variable, but the problem remains.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 28, 2019, 8:39pm UTC](https://community.homey.app/t/variable-not-updating/23230/5 "2019-12-28T20:39:45Z")

</div>

From what I know, `capabilitiesObj` is updated lazily, so it may not reflect the actual current value of the capability.

It might work better like this (untested and no idea if it works):

```auto
const Virtuele_Thermostaat_Badkamer=await Homey.devices.getDevice({id: '92d39e69-b6f3-4886-ba60-739b3967b01a'});
const capability = await Homey.devices.getCapability({
  id: Virtuele_Thermostaat_Badkamer.capabilitiesObj.target_temperature.id,
  uri: Virtuele_Thermostaat_Badkamer.capabilitiesObj.target_temperature.uri
});
const badkamer_set = capability.values[0];

```

---

<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:** [December 28, 2019, 11:16pm UTC](https://community.homey.app/t/variable-not-updating/23230/6 "2019-12-28T23:16:38Z")

</div>

Hi mate, could it be that getCapability does not exist anymore?  
I’m receiving an error in my script when i use your code.  
Script Error:  
Missing required parameter: uri

Also when i check :  
[https://apps.developer.athom.com/Device.html#getCapabilityValue](https://apps.developer.athom.com/Device.html#getCapabilityValue)  
i don’t see it.

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 29, 2019, 6:28am UTC](https://community.homey.app/t/variable-not-updating/23230/7 "2019-12-29T06:28:27Z")

</div>

Wrong API 🙂 The code I posted uses the [Web API](https://developer.athom.com/docs/api/HomeyAPI.ManagerDevices.html#getCapability).

If it says that `uri` is missing, the method obviously still exists, but perhaps `Virtuele_Thermostaat_Badkamer.capabilitiesObj.target_temperature` doesn’t contains the correct data.

Can you post the results of this?

```auto
console.log(Virtuele_Thermostaat_Badkamer.capabilitiesObj.target_temperature);

```

---

<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:** [December 29, 2019, 8:35am UTC](https://community.homey.app/t/variable-not-updating/23230/8 "2019-12-29T08:35:40Z")

</div>

Hi, i just tried your suggestion; but the problems remains the same ☹

I’ve got the same problem for all my devices it seems (not updating) My measured temperatures from my smoke detectors are also not updating in Homeyscript, only in Homescript.

I’m using the measured\_temperature from all my smoke sensors in my house to measure the temperature in every room. Every room has its own Eurotronic heating valves for the ‘radiators’ and with the Virtual Thermostat i can adjust the temperature in every room.  
Before my system was running on a Raspberry Pi with Domoticz and i wrote my program completely in PHP and it worked fine; but i had problems with zwave range and raspberry pi, thats why i made the switch to Homey; but i hope i’m not getting stuck on this updating variable stuff, because it would be an very expensive switch ☹

Now, back to this topic:  
So i’m running a flow that is running every 1minute the Homeyscript  
7minutes have passed and the console.log still show this:  
first line is the date/time i’m printing so i now when the log has been ‘updated’  
value in homeydash shows 21, in log below still 25

**Homeyscript:**

console.clear;  
let tijdvar1=new Date();  
console.log(tijdvar1);  
const Virtuele\_Thermostaat\_Badkamer=await Homey.devices.getDevice({id: ‘92d39e69-b6f3-4886-ba60-739b3967b01a’});  
console.log(Virtuele\_Thermostaat\_Badkamer.capabilitiesObj.target\_temperature);

log:  
2019-12-29T08:34:00.848Z  
{ value: 25,  
lastUpdated: ‘2019-12-29T08:26:28.622Z’,  
type: ‘number’,  
getable: true,  
setable: true,  
title: ‘Ingestelde temperatuur’,  
desc: null,  
units: ‘°C’,  
decimals: 2,  
min: 4,  
max: 50,  
chartType: ‘stepLine’,  
id: ‘target\_temperature’,  
options: { max: 50 },  
values: undefined }

* * *

Script returned:  
undefined

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 29, 2019, 8:39am UTC](https://community.homey.app/t/variable-not-updating/23230/9 "2019-12-29T08:39:13Z")

</div>

It doesn’t seem to have a `uri` property, which explains why `getCapability` isn’t working.

However, you can probably exchange a lot of your code by using regular flows and tokens. Is there a reason you’re not using those?

---

<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:** [December 29, 2019, 8:43am UTC](https://community.homey.app/t/variable-not-updating/23230/10 "2019-12-29T08:43:15Z")

</div>

Can you point my in a direction please?  
I’m still new to Homey and need to discover a still a lot; i think ?

---

<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:** [December 29, 2019, 8:47am UTC](https://community.homey.app/t/variable-not-updating/23230/11 "2019-12-29T08:47:22Z")

</div>

Also, in Homeyscript, everytime i press: Save&Test button  
then it is updated, but when the Flow(that is running every 1minute) is running the Homeyscript, then the variables are not updated

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 29, 2019, 9:11am UTC](https://community.homey.app/t/variable-not-updating/23230/12 "2019-12-29T09:11:21Z")

</div>

What exactly is it that you’re trying to do? If you can explain what you’re trying to accomplish, I (or likely other people 😉 ) might be able to help you set up flows that will accomplish your goal.

---

<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:** [December 29, 2019, 9:41am UTC](https://community.homey.app/t/variable-not-updating/23230/13 "2019-12-29T09:41:24Z")

</div>

well, i have 7rooms i want to control the heating seperatly.  
So i had before was:

- virtual button Manual Heating On/Off for every room
- virtual thermostat for every room

I have any every room a temperature sensor (mostly it are smoke detectors from Fibaro who have temperature sensor also) So with this i know what i need to do

Every room has Eurotronic controlled valves (8° =\> closed ; 28° =\> completely open)  
And my Vaillant heater is switched on/off with a zwave Fibaro relay

So an example:  
actual temperature in room x =\> 15°C  
So i want to switch on the heating manually for room x to 21°C (this is the virtual thermostat) for 2h (kids studying or something), so i push the manual button and then the heater switches on and the electronic valves are opening only in that room to maximum. all other valves are closed.  
When the temperature has reached 21°C, the heater must switch off (unless another room is asking to be heated ofcourse)  
When after 15min, the temperatures drops again to 20.5°C and it is still in range of the 2h limit, heater must switch on again.  
This is the manual button heating.  
Automatic heating:  
i setup for example on weekdays: heating must switch on from 4:00 - 6:40 to 22°C on room x,a,b (all other rooms not needed)  
after 6:40 heating must be switched off, because we are gone to work.

It’s something big 🙂

---

<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:** [December 29, 2019, 9:42am UTC](https://community.homey.app/t/variable-not-updating/23230/14 "2019-12-29T09:42:39Z")

</div>

but with flows, i think this will need to have a huge amount of flows?  
Like for just switching on/off my light after x minutes, i already need 3flows 😐

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 29, 2019, 10:07am UTC](https://community.homey.app/t/variable-not-updating/23230/15 "2019-12-29T10:07:48Z")

</div>

Hmm yeah, Homeyscript sounds like a better solution for this, with flows it would get too complicated.

I use `capabilitiesObj` in the Homeykit app, where it works, but the difference with that and your code is that Homeykit listens to capability change events before it reads out the value.

I don’t think you can run Homeyscript scripts continously, so listening to events won’t work. And like I said, `capabilitiesObj` is updated lazily, but I don’t know at which point Homey’s core decides to update it (perhaps _only_ when there’s an event handler listener for changes, but stuff like this simply isn’t documented).

Maybe @JeroenVollenbrock can shed some light on this issue?

---

<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:** [December 30, 2019, 4:23pm UTC](https://community.homey.app/t/variable-not-updating/23230/16 "2019-12-30T16:23:14Z")

</div>

So, I’m just wondering. Am I the only person who is using Homey that want to ‘read’ the variables from its devices in Homeyscript? Because everyone must have the same problem like me that the variables are not updating? 🙄 😁

---

<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:** [December 30, 2019, 4:36pm UTC](https://community.homey.app/t/variable-not-updating/23230/17 "2019-12-30T16:36:37Z")

</div>

If i could use the measured\_temperature from my Fibaro smoke detectors in a Flow, i could continue a little bit, but for what i see i cant use the temperature

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [December 30, 2019, 8:45pm UTC](https://community.homey.app/t/variable-not-updating/23230/18 "2019-12-30T20:45:10Z")

</div>

Pass the temperature token as an argument to your script?

---

<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 1, 2020, 3:01pm UTC](https://community.homey.app/t/variable-not-updating/23230/19 "2020-01-01T15:01:28Z")

</div>

First of all, happy new year 🙂

Second: you rock 😁  
Is it also possible to pass multiple arguments to the same script?  
So i can pass all the current temperatures from my smoke detectors?  
I’ve now passed 1 current temperature as an argument and i can use it now in my script, so very good

---

<div class="post-metadata">

**Author:** ![robertklep](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/robertklep/32/160628_2.png) [@robertklep](https://community.homey.app/u/robertklep)\
**Post date:** [January 1, 2020, 3:03pm UTC](https://community.homey.app/t/variable-not-updating/23230/20 "2020-01-01T15:03:12Z")

</div>

Not sure if you can pass multiple arguments, you’d have to try 😃

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