Variable not updating

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!!

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

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.

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

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):

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];

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
i don’t see it.

Wrong API :slight_smile: The code I posted uses the Web API.

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?

console.log(Virtuele_Thermostaat_Badkamer.capabilitiesObj.target_temperature);

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

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 :frowning:

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

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?

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

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

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 :wink: ) might be able to help you set up flows that will accomplish your goal.

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 :slight_smile:

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 :neutral_face:

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?

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? :roll_eyes: :grin:

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

Pass the temperature token as an argument to your script?

First of all, happy new year :slight_smile:

Second: you rock :grin:
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

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