# Get historic variable value

**URL:** <https://community.homey.app/t/get-historic-variable-value/79120>\
**Category:** Questions & Help\
**Tags:** homeyscript, insights\
**Created:** [April 10, 2023, 3:15pm UTC](https://community.homey.app/t/get-historic-variable-value/79120 "2023-04-10T15:15:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sander\_Arends](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/sander_arends/32/70900_2.png) [@Sander\_Arends](https://community.homey.app/u/Sander_Arends)\
**Post date:** [April 10, 2023, 3:15pm UTC](https://community.homey.app/t/get-historic-variable-value/79120/1 "2023-04-10T15:15:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Eko\_taas](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/eko_taas/32/74256_2.png) [@Eko\_taas](https://community.homey.app/u/Eko_taas)\
**Post date:** [November 16, 2023, 4:34am UTC](https://community.homey.app/t/get-historic-variable-value/79120/3 "2023-11-16T04:34:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Dijker](https://avatars.discourse-cdn.com/v4/letter/d/b9bd4f/32.png) [@Dijker](https://community.homey.app/u/Dijker)\
**Post date:** [November 16, 2023, 5:46am UTC](https://community.homey.app/t/get-historic-variable-value/79120/4 "2023-11-16T05:46:57Z")

</div>

> [@\[APP\]\[Pro\] Insight Trends Reloaded](https://community.homey.app/t/app-pro-insight-trends-reloaded/71307):
>
> Insight Trends With the help of Homey’s insightful features, you can view all sensor measurements and their historical evolution. Take it a step further and do more than just observe the insights; act accordingly or even glimpse the future a little. You can choose an insight (a device and a capacity, such as the outside temperature), as well as a timeframe to analyze. The outcomes will then be computed as follows: Trend a number between -1 and 1 that indicates whether the sensors’…

---

<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:** [November 16, 2023, 5:58pm UTC](https://community.homey.app/t/get-historic-variable-value/79120/5 "2023-11-16T17:58:06Z")

</div>

With a little D-tour:  
The [Device Capabilities app](https://community.homey.app/t/app-pro-device-capabilities-enhance-the-capabilities-of-devices/43287) has the perfect flowcard, and you can emulate it in Hscript

> ![Screenshot_20231116-184340_Chrome](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/b/d/bdfc15567f1dc7caa23d826d2c35c39cfc197255.jpeg)

Explained:

> ![Screenshot_20231116-184424_Chrome](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/9/5/957c068cd887d5c6135e4ac77abe0850c13bc88b.jpeg)

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_)

 ![Screenshot_20231116-184922_Firefox](https://us1.discourse-cdn.com/flex025/uploads/athom/original/3X/a/2/a2818a6d1e5a8a3afbde90c4c13c94a443e1451c.jpeg)

---

<div class="post-metadata">

**Author:** ![Eko\_taas](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/eko_taas/32/74256_2.png) [@Eko\_taas](https://community.homey.app/u/Eko_taas)\
**Post date:** [November 18, 2023, 4:48am UTC](https://community.homey.app/t/get-historic-variable-value/79120/6 "2023-11-18T04:48:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Eko\_taas](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/eko_taas/32/74256_2.png) [@Eko\_taas](https://community.homey.app/u/Eko_taas)\
**Post date:** [February 18, 2024, 7:09am UTC](https://community.homey.app/t/get-historic-variable-value/79120/7 "2024-02-18T07:09:08Z")

</div>

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:

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

where sensor data in Insights:

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

> 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?

---

<div class="post-metadata">

**Author:** ![Eko\_taas](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/eko_taas/32/74256_2.png) [@Eko\_taas](https://community.homey.app/u/Eko_taas)\
**Post date:** [February 19, 2024, 6:03am UTC](https://community.homey.app/t/get-historic-variable-value/79120/8 "2024-02-19T06:03:50Z")

</div>

> [@Eko\_taas](#):
>
> Calculate trend for [[insight]] based on the last [[range]] [[unit]]

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 🤒

---

<div class="post-metadata">

**Author:** ![pbruining](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/pbruining/32/120823_2.png) [@pbruining](https://community.homey.app/u/pbruining)\
**Post date:** [January 2, 2026, 11:34am UTC](https://community.homey.app/t/get-historic-variable-value/79120/9 "2026-01-02T11:34:14Z")

</div>

> [@Peter\_Kawa](#):
>
> Device Capabilities app

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:

```auto
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 🙂
