Homey Community Forum

Device CapabilitiesObj in HomeyScript stays the same value when triggered in a flow

I have a problem with constantly updated values from a device which i’m trying to get in a script.

var device_data = await Homey.devices.getDevice({ id: '45f27858-c506-4d3c-a800-1954d803e3e3' });

console.log(device_data);

When i “Save & Test” in homeyScript the data is constantly updated, more specific the capabilitiesObj

 capabilitiesObj: 
{ measure_power: 
   { value: 498,
    lastUpdated: '2019-06-17T17:41:16.803Z',
    type: 'number',
    getable: true,
    setable: false,
    title: 'Energie',
    desc: 'Vermogen in Watt (W)',
    units: 'W',
    decimals: 2,
    chartType: 'stepLine',
    id: 'measure_power',
    options: {},
    values: undefined },
 meter_offPeak: 

etc…

but then i use the script in a flow to execute (flow executes every time the powermeter changes) I constantly get “Cached” values (it looks like it)

so the value: 498 stays every flow execution the same.

Any ideas?

Moved to developers.

Looks like you need a workaround:

const device = await Homey.devices.getDevice({ id: '45f27858-c506-4d3c-a800-1954d803e3e3' });
const cap    = device.makeCapabilityInstance('measure_power');

console.log(cap.value);

I think it has to do with lazy evaluation, where capability values are only updated when explicitly required.

Thanks! @robertklep, i’ve also found another way: via the insights api. because (luckily) the data is also put into the insights.

I will try this method as well!