See how old a value is?

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

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 :upside_down_face:
So ignore the info below pls


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



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

Result:


Result:
Screenshot from 2023-03-11 01-37-01

1 Like

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

If there are insights, you can use the Device Capabilities flowcard: Retrieve insights from 0 minutes ago.

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.

All Capabilities have a last_changed field, you can see those through HomeyScript for instance:

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

3 Likes

Ah great news!

Aaaaahh yes ofcourse, I had not enough coffee appearantly.
We even have a flow to check on sensors last_changed value

1 Like

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.

2 Likes

OK @janrikard and @Arie_J_Godschalk ,
Arie gave me some ideas :upside_down_face: , 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, and look for your device

- flow

- code

// [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

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

Screenshot from 2023-03-12 12-13-38

BLL convert UTC to local time

Screenshot from 2023-03-12 12-13-47

- result

Screenshot from 2023-03-12 12-34-16

2 Likes