Get historic variable value

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 :face_with_peeking_eye:

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:

image

where sensor data in Insights:

image

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:

:warning: 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 :face_with_thermometer: