# Compare data from one hour ago with current

**URL:** https://discourse.nodered.org/t/compare-data-from-one-hour-ago-with-current/85940
**Category:** General
**Created:** [26 February 2024 21:25 UTC](https://discourse.nodered.org/t/compare-data-from-one-hour-ago-with-current/85940 "2024-02-26T21:25:23Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![RedRobin132](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@RedRobin132](https://discourse.nodered.org/u/RedRobin132)
#### Post date: [26 February 2024 21:25 UTC](https://discourse.nodered.org/t/compare-data-from-one-hour-ago-with-current/85940/1 "2024-02-26T21:25:24Z")

</div>

Hello!  
I have a project where i collect the water level of a river with a sensor. When a predefined height is surpassed, the node red flow send a push message to my phone. Now i want to also compare the current level with the one, i detected on hour ago, so i can see the development over time. Is there a way i can buffer the collected data and compare it? New Data is collected every 10 Minutes.

Thanks in advance!  
Robin

---

<div class="post-metadata">

### Author: ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)
#### Post date: [26 February 2024 21:50 UTC](https://discourse.nodered.org/t/compare-data-from-one-hour-ago-with-current/85940/2 "2024-02-26T21:50:29Z")

</div>

Hi and welcome.

You can use [context storage](https://nodered.org/docs/user-guide/context) to store data for use later.  
One simple way would be store the new data in an array.  
Set new data to array[6] and then delete array[0]. This would result in a 6 element array. With array[0] holding the reading from an hour ago, and array[5] holding the newest.  
e.g.

```auto
[{"id":"9dc7bc361d7f57e2","type":"inject","z":"b779de97.b1b46","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":4840,"wires":[["af9dc0530e9f3f77"]]},{"id":"af9dc0530e9f3f77","type":"change","z":"b779de97.b1b46","name":"","rules":[{"t":"set","p":"sensor_data[6]","pt":"flow","to":"payload","tot":"msg"},{"t":"delete","p":"sensor_data[0]","pt":"flow"},{"t":"set","p":"payload","pt":"msg","to":"sensor_data","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":4840,"wires":[["06aabbd7aa405c1f"]]},{"id":"06aabbd7aa405c1f","type":"debug","z":"b779de97.b1b46","name":"debug 2483","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":4840,"wires":[]}]

```

[How to import/export a flow](https://nodered.org/docs/user-guide/editor/workspace/import-export)

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [26 February 2024 22:21 UTC](https://discourse.nodered.org/t/compare-data-from-one-hour-ago-with-current/85940/3 "2024-02-26T22:21:15Z")

</div>

> [@RedRobin132](#):
>
> Now i want to also compare the current level with the one, i detected on hour ago, so i can see the development over time. Is there a way i can buffer the collected data and compare it?

You could also use a database to store the data. SQLite might be appropriate, or MySQL.  
That way it's available if you decide you want to correlate the trend with rainfall records, etc.

---

<div class="post-metadata">

### Author: ![RedRobin132](https://avatars.discourse-cdn.com/v4/letter/r/5f9b8f/32.png) [@RedRobin132](https://discourse.nodered.org/u/RedRobin132)
#### Post date: [27 February 2024 12:21 UTC](https://discourse.nodered.org/t/compare-data-from-one-hour-ago-with-current/85940/4 "2024-02-27T12:21:16Z")

</div>

Thank you both for your answers!  
I think i will use both. The context storage for the problem i explained above and the database for future use.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [12 March 2024 12:21 UTC](https://discourse.nodered.org/t/compare-data-from-one-hour-ago-with-current/85940/5 "2024-03-12T12:21:51Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
