# Homescript capabilitiesObj.measure\_power.lastUpdate

**URL:** https://community.homey.app/t/homescript-capabilitiesobj-measure-power-lastupdate/31514
**Category:** Questions & Help
**Created:** [June 21, 2020, 8:21pm UTC](https://community.homey.app/t/homescript-capabilitiesobj-measure-power-lastupdate/31514 "2020-06-21T20:21:10Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Maarten](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/maarten/32/16541_2.png) [@Maarten](https://community.homey.app/u/Maarten)
#### Post date: [June 21, 2020, 8:21pm UTC](https://community.homey.app/t/homescript-capabilitiesobj-measure-power-lastupdate/31514/1 "2020-06-21T20:21:10Z")

</div>

Hello,  
I have created a script to get the lastupdated (date/time) of capabilitesObj.measure\_power of one of my devices.

The script below works fine if I run it manually in the script window. But if I run the script in a flow it does not get the measure\_power.lastupdated. It keeps using the value of the last time i ran the script manually.  
Any suggestions how to retrieve the actual capabilitiesObj.measure\_power.lastUpdate while running the script in a flow?

let device = await Homey.devices.getDevice({id : ‘8f3bc736-8121-4bf4-b277-d2b6b14cca9d’});

var lastUpdated = new Date(device.capabilitiesObj.measure\_power.lastUpdated);

let now = new Date();

let Minutes = parseInt((now - lastUpdated)/(1000\*60));

let BLApp = await Homey.apps.getApp({id:“net.i-dev.betterlogic” });  
BLApp.apiPut(“Koelkastkeuken/”+Minutes);

---

<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: [June 22, 2020, 7:28am UTC](https://community.homey.app/t/homescript-capabilitiesobj-measure-power-lastupdate/31514/2 "2020-06-22T07:28:04Z")

</div>

Can you also share your flow?

---

<div class="post-metadata">

### Author: ![Maarten](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/maarten/32/16541_2.png) [@Maarten](https://community.homey.app/u/Maarten)
#### Post date: [June 22, 2020, 8:58am UTC](https://community.homey.app/t/homescript-capabilitiesobj-measure-power-lastupdate/31514/3 "2020-06-22T08:58:48Z")

</div>

![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/7/2/723f8f00d8c5f693a0a9f2225ea6b8321089845e.png)

---

<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: [June 22, 2020, 9:33am UTC](https://community.homey.app/t/homescript-capabilitiesobj-measure-power-lastupdate/31514/4 "2020-06-22T09:33:51Z")

</div>

maybe you can try:  
`let result = await BLApp.apiPut("Koelkastkeuken/"+Minutes);`  
`return(result);`

And probably some delay the on the second Script-call if this has to be done after the first.  
Otherwise they will execute at the same time.

---

<div class="post-metadata">

### Author: ![Maarten](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/maarten/32/16541_2.png) [@Maarten](https://community.homey.app/u/Maarten)
#### Post date: [June 22, 2020, 3:18pm UTC](https://community.homey.app/t/homescript-capabilitiesobj-measure-power-lastupdate/31514/5 "2020-06-22T15:18:11Z")

</div>

Removed the second script from the flow and tried the suggestion, but still not wokrng.  
It looks like that the statement  
var lastUpdated = new Date(device.capabilitiesObj.measure\_power.lastUpdated);  
is not working if it being called in the flow.  
Because the calculation and updating the variable is working, only it is using the lastupdated date from the last time i did run the script manual.

---

<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: [June 22, 2020, 4:24pm UTC](https://community.homey.app/t/homescript-capabilitiesobj-measure-power-lastupdate/31514/6 "2020-06-22T16:24:11Z")

</div>

> [@Maarten](#):
>
> var lastUpdated = new Date(device.capabilitiesObj.measure\_power.lastUpdated);  
> is not working if it being called in the flow.

Did a test on this and that is true, have no idea how this is possible,  
maybe some JavaScript Guru can answer? @Dijker ??

---

<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: [June 22, 2020, 4:39pm UTC](https://community.homey.app/t/homescript-capabilitiesobj-measure-power-lastupdate/31514/7 "2020-06-22T16:39:13Z")

</div>

Instead of using `device.capabilitiesObj`, which is lazily updated, you should [create a capability instance](https://developer.athom.com/docs/api/HomeyAPI.ManagerDevices.Device.html#makeCapabilityInstance):

```auto
const device = await Homey.devices.getDevice({id : '8f3bc736-8121-4bf4-b277-d2b6b14cca9d'});
const capability = device.makeCapabilityInstance('measure_power');
const lastUpdated = new Date(capability.lastChanged); // not `lastUpdated` because that would be too consistent…
…

```

---

<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: [June 22, 2020, 5:12pm UTC](https://community.homey.app/t/homescript-capabilitiesobj-measure-power-lastupdate/31514/8 "2020-06-22T17:12:46Z")

</div>

That looks great, Thanks @robertklep

---

<div class="post-metadata">

### Author: ![Maarten](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/maarten/32/16541_2.png) [@Maarten](https://community.homey.app/u/Maarten)
#### Post date: [June 23, 2020, 5:54am UTC](https://community.homey.app/t/homescript-capabilitiesobj-measure-power-lastupdate/31514/9 "2020-06-23T05:54:48Z")

</div>

Thanks, it is working now!
