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
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
So ignore the info below pls
It’s sort of viewable in my.homey.app and go to insights
Result:
Result:
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:
Ah great news!
Aaaaahh yes ofcourse, I had not enough coffee appearantly.
We even have a flow to check on sensors last_changed value
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.
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, and look for your device
// [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
(For the device names, I had to replace numbers, dots, whitespaces etc. and make text lowercase)