# See how old a value is?

**URL:** https://community.homey.app/t/see-how-old-a-value-is/77438
**Category:** Questions & Help
**Created:** [March 10, 2023, 12:35pm UTC](https://community.homey.app/t/see-how-old-a-value-is/77438 "2023-03-10T12:35:42Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![janrikard](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/janrikard/32/34785_2.png) [@janrikard](https://community.homey.app/u/janrikard)
#### Post date: [March 10, 2023, 12:35pm UTC](https://community.homey.app/t/see-how-old-a-value-is/77438/1 "2023-03-10T12:35:42Z")

</div>

Hello

Is it possible in a flow to se how old a value is?  
I need to loadbalance my car charger but that works really bad if the loadvalues are old.

/Rikard

---

<div class="post-metadata">

### Author: ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)
#### Post date: [March 10, 2023, 10:52pm UTC](https://community.homey.app/t/see-how-old-a-value-is/77438/2 "2023-03-10T22:52:43Z")

</div>

~~There’s no ‘last\_updated’ or ‘last\_changed’ info available AFAIK. This would make a great Feature Request though!~~  
Edit: Turns out there definately is a last\_changed value available 🙃  
So ignore the info below pls

* * *

It’s sort of viewable in my.homey.app and go to insights

 ![Screenshot from 2023-03-11 01-13-40](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/e/a/ea17477fb409926e043bbf4387d396442f2c246c.png)

- You can create a flow to **store** the last changed time.  
You have to create a text variable;  
Flow example:

Result:

 ![Screenshot_20230310-235129_Homey](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/a/ba97068ed7e615acbd1aa4e3130f3616e42f260f.jpeg)

- Or you can create a flow which starts or restarts a **stopwatch**  
I use [Chronograph](https://homey.app/en-gb/app/nl.fellownet.chronograph/Chronograph/), to create this:  
 ![Screenshot from 2023-03-11 01-38-14](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/c/e/ce19b71847fd685de761d85c3c6632e06dd148c5.png)

Result:  
 ![Screenshot from 2023-03-11 01-37-01](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/1/0/106b4540c5a3943db3b0da44bd4112670744a5aa.png)

---

<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: [March 12, 2023, 6:55am UTC](https://community.homey.app/t/see-how-old-a-value-is/77438/3 "2023-03-12T06:55:44Z")

</div>

What kind of value is is Janrikard?  
Are there insights for them"?

If there are insights, you can use the [Device Capabilities](https://homey.app/a/nl.qluster-it.DeviceCapabilities/) flowcard: Retrieve insights from 0 minutes ago.

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/e/0/e07b780c08df7348b9e95db89fc824f35ad2e5c1.png)

This works for Yes/No and for Numbers.

If you need it for text or there are no insights, you need to wait till next week till i create the new flowcard: Get Capability info, which will work for text also and fields without inisghts.

> [@Peter\_Kawa](#):
>
> There’s no ‘last\_updated’ or ‘last\_changed’ info available AFAIK.

All Capabilities have a last\_changed field, you can see those through HomeyScript for instance:

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/d/8/d836c801c55fb2b1c7e1093b57252121525972c8.png)

Those numbers are UTC ticks and with the BLL format card, you can read and format its value:

 ![image](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/d/b/db95413672d42c28042baf5bc270bd03b67c7d9f.png)

---

<div class="post-metadata">

### Author: ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)
#### Post date: [March 12, 2023, 7:53am UTC](https://community.homey.app/t/see-how-old-a-value-is/77438/4 "2023-03-12T07:53:51Z")

</div>

> [@Arie\_J\_Godschalk](#):
>
> new flowcard: Get Capability info, which will work for text also and fields without inisghts.

Ah great news!

> [@Arie\_J\_Godschalk](#):
>
> All Capabilities have a last\_changed field,

Aaaaahh yes ofcourse, I had not enough coffee appearantly.  
We even have [a flow](https://community.homey.app/t/the-flow-exchange-r-exchange-your-flows-with-others/68981/13) to check on sensors last\_changed value

---

<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: [March 12, 2023, 9:52am UTC](https://community.homey.app/t/see-how-old-a-value-is/77438/5 "2023-03-12T09:52:04Z")

</div>

I’ve also thought of (finally) a Time format function, which i wil build into BLL and its codings and expressions.  
That function, however it will look like when done, will allow input which is converted into a time format.  
Plainly said: it will allow large numbers to be converted into timestamps like 125hours, 10 minutes, 20 sec, results in a stamp like 125:10:20.

That will make it easy to use large millesecond numbers into usable stamps, kinda like i added to the chronograph apps.

---

<div class="post-metadata">

### Author: ![Peter\_Kawa](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/peter_kawa/32/173848_2.png) [@Peter\_Kawa](https://community.homey.app/u/Peter_Kawa)
#### Post date: [March 12, 2023, 11:34am UTC](https://community.homey.app/t/see-how-old-a-value-is/77438/6 "2023-03-12T11:34:53Z")

</div>

OK @janrikard and @Arie_J_Godschalk ,  
Arie gave me some ideas 🙃 , and I couldn’t resist, in the meantime I made it possible to retreive the last\_changed time in a tag, with a HomeyScript code and the flow below.

The script takes a capability as argument, and returns all [a\_capability] values as JSON (_yes I know, it should be limited to a device somehow, but it runs fine up til now_)

In this example, I chose `meter_power` as argument  
_To find the correct capability, go to [https://tools.developer.homey.app/tools/devices](https://tools.developer.homey.app/tools/devices), and look for your device_

#### - flow

 ![Screenshot from 2023-03-12 12-17-47](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/8/b/8be244dfbb3d0064125d97c4992a19ecc0a0ae6a.png)

#### - code

```auto
// [code to get last_changed times from a capability (as JSON), with a capability as argument]
let array = [];
const myArgument = args[0];

const devices = await Homey.devices.getDevices({ filter: {capabilities: myArgument} });
_.forEach(devices, device => {
array.push('"' + device.name.replace(/Σ|\/|\(|\)|\ |\.|1|2|3|4|5|6|7|8|9|0|€/gi, "_") + '":"' + device.capabilitiesObj[myArgument]?.lastUpdated?.substring(0,25) + '"');
});
// NOTE: the device.name.replace() is for JSON format and is done here, while the UTC timestamp has a decimal point which must not be replaced

//oldest date on top sort array = ["time_stamp device", "time_stamp device", "time_stamp device"]
const array_sorted = array.slice().sort(function(time_stamp, device) { 
 const firsttime_stamp = time_stamp.split(" ")[0];
 const secondtime_stamp = device.split(" ")[0];
 if(firsttime_stamp < secondtime_stamp) return -1;
 if(firsttime_stamp > secondtime_stamp) return 1;
 return 0;
});

//console.log(myArgument + " last_changed time:\n{" + array_sorted.join(',') + "}");

let myResult = ("{" + array_sorted.join(",") + "}");
let myresult = myResult.toLowerCase();
return myresult.toString();

// Thanks to Robert Klep for the initial code

```

#### - code result, JSON with my matching power meters and UTC timestamps

(For the device names, I had to replace numbers, dots, whitespaces etc. and make text lowercase)

 ![Screenshot from 2023-03-12 12-13-24](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/8/c/8cf6caf81ba3ff27d4521380afa8367c582767a6.png)

#### - one sensor value selected from the JSON result, it returns it’s UTC timestamp

 ![Screenshot from 2023-03-12 12-13-38](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/5/7/57f57313daf165e9fdf4e94900c9995923f2afbb.png)

#### BLL convert UTC to local time

 ![Screenshot from 2023-03-12 12-13-47](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/2/1/21a161182197ebd055373a184ac8ad4363eee5c1.png)

#### - result

 ![Screenshot from 2023-03-12 12-34-16](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/e/5/e52b25c8b01211aa419f4f2705192148a2361771.png)
