How is it possible to get the historic value of a variable in HomeyScript?
I have a numeric variable and I want to know what its value was two weeks ago.
I can see the value in the graphs of insights but I cannot reproduce the value in HomeyScript.
How is it possible to get the historic value of a variable in HomeyScript?
I have a numeric variable and I want to know what its value was two weeks ago.
I can see the value in the graphs of insights but I cannot reproduce the value in HomeyScript.
Was happy to find this existing Q, but still unlucky to find it with zero replies.
Currently (with my newbee knowledge) if I want to adjust some control parameters based on historical data, I need to export those from Insights-data with suitable time scale to get ready made e.g. daily averages (one-by-one only).
Obviously building counters / collecting separate JSON would also be possible, but feels bit stupid when data exists alreadyâŠ
If other ways to do it, hints appreciated
With a little D-tour:
The Device Capabilities app has the perfect flowcard, and you can emulate it in Hscript
Explained:
You can emulate most AND & THEN flowcards in Homeyscript.
Check example-flowcard-run on how to do that.
Now, when you havenât already, install Device Capabilities app first
When you run example-flowcard-list it will return all And & Then cards available on your Homey â you can search for the Device Capabilities card âThenâ âRetrieve the insights value fromâ
(this script can take quite a while to finish, remove the âAndâ part in order to show the âThenâ part results way more quicker)
Thanks for fast and very relevant hints!
As my main interest (at this point) is some average values (e.g. outside temperature in last 7 days), âInsight Trends Reloadedâ seems 1st app to start.
After finalized other part of coding, and finally realized what you tried to propose ![]()
I looked at flowcard emulation examples, but seems that still cannot get agrs right.
e.g. flowcard (same trouble with Device Cap app emulation)
Calculate trend for [[insight]] based on the last [[range]] [[unit]]
{
âidâ: âhomey:app:com.spkes.insightTrendsReloaded:calculateTrendWithoutTokenâ,
âargsâ: [
{
âtypeâ: âautocompleteâ,
ânameâ: âinsightâ,
âtitleâ: âInsightâ,
âplaceholderâ: null
},
{
âtypeâ: ânumberâ,
ânameâ: ârangeâ,
âtitleâ: âTime rangeâ,
âminâ: 1,
âvalueâ: 15,
âplaceholderâ: null
},
{
âtypeâ: âdropdownâ,
ânameâ: âunitâ,
âtitleâ: âTime unitâ,
âvaluesâ: [
{
âidâ: â1â,
âtitleâ: âMinutesâ
},
{
âidâ: â60â,
âtitleâ: âHoursâ
},
{
âidâ: â1440â,
âtitleâ: âDaysâ
}
],
âplaceholderâ: null
}
],
âdroptokenâ: null,
âdurationâ: false
}
Would like to emulate this card:
where sensor data in Insights:
result = await Homey.flow.runFlowCardAction({
uri: âhomey:app:com.spkes.insightTrendsReloadedâ,
id: âhomey:app:com.spkes.insightTrendsReloaded:calculateTrendWithoutTokenâ,
args: {
insight: âXXXXXXXXX-467d-47ad-845d-0b248f66bf3a.measure_temperatureâ,
range: 1,
unit: 1440,},
});log (result);
or others like
insight: âEteinen LĂ€mpö.Temperature °Câ,
insight: âEteinen LĂ€mpö.Temperatureâ,
with same error:
Error: Timed out after 30000ms.
Any advice how to figure out what should I put in or where to look for?
Now realized that on sensor I can see
insight: âhomey:device:XXXXXX-467d-47ad-845d-0b248f66bf3a:measure_temperatureâ
even if changing to that still not working ![]()
I had the same question, but i managed to do it in a HomeyScript without using any additional flows or Apps.
Eventually i needed an average and wrote this function to obtain it:
async function calculateLastHourAverage(deviceId, capabilityId) {
const logId = `homey:device:${deviceId}:${capabilityId}`;
const logData = await Homey.insights.getLogEntries({
id: logId,
resolution: 'lastHour'
});
let total = 0;
for (const value of logData.values) {
total += value.v;
}
return total / logData.values.length;
}
// Usage
const weatherStationDeviceId = '9a2053b8-a961-4d25-82c7-808ae82af2aa';
const windspeedCapabilityId = 'measure_wind_strength';
const averageWindspeed = await calculateLastHourAverage(weatherStationDevice.id, windspeedCapabilityId);
I know itâs a bit late, but it may help you or others ![]()