How to track temperature trend

Actually the place where I'm getting stuck is how to hold a changing variable at a specific point in time. My fridge temp is constantly updating and I can't figure out how to pull, say, the 9am reading and ignore all changes until 11am so I can compare the two.

If your incoming data does not provide a timestamp you have to generate one. Then compare the stored timestamp with the incoming. If none existent (1st measurement) store both (value and timestamp) in the context you prefer (i suggest flow) else determine the delta and if it exceed the duration you like to measure you are done.

I would solve this with a single function node but there are certainly solutions for this by using pure core nodes.

Maybe I'm not understanding something about how variables are stored. Let's say the following:
global.temp is updated every 5 minutes from a sensor reading
I set a change node setting flow.temp equal to global.temp
I link that change node to a delay node where I set a day for 120 minutes.
At the end of that 120 minutes, will flow.temp be what it was 120 minutes ago or, because global.temp is updated every 5 minutes and flow.temp is set to global.temp, will flow.temp simply equal the current global.temp?

Basically I'm looking for a way to capture an ever-changing variable (temperature in my case) at a particular moment in time so I can compare it down the line.

Perhaps you can share the flow how far you got up to now. Quite difficult to help on a descriptive text.

Sure:

[{"id":"e49a6050.5ee198","type":"inject","z":"9fb28e31.fdea6","name":"Check Fridge Temp","topic":"","payload":"FridgeTemp","payloadType":"global","repeat":"7200","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":320,"wires":[["28f695e0.321042"]]},{"id":"28f695e0.321042","type":"switch","z":"9fb28e31.fdea6","name":"Less then 40?","property":"FridgeTemp","propertyType":"global","rules":[{"t":"lte","v":"40","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":420,"y":200,"wires":[["69c427f3.962e38"],["9f586fc8.613798"]]},{"id":"9f586fc8.613798","type":"change","z":"9fb28e31.fdea6","name":"","rules":[{"t":"set","p":"FridgeTemp","pt":"flow","to":"FridgeTemp","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":400,"wires":[["741faea.899cad"]]},{"id":"741faea.899cad","type":"delay","z":"9fb28e31.fdea6","name":"Delay 119 minutes","pauseType":"delay","timeout":"119","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":450,"y":500,"wires":[["2d7e3761.bf6db"]]},{"id":"2d7e3761.bf6db","type":"switch","z":"9fb28e31.fdea6","name":"Did the temp go down?","property":"FridgeTemp","propertyType":"global","rules":[{"t":"lt","v":"FridgeTemp","vt":"flow"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":610,"y":400,"wires":[["69c427f3.962e38"],["953f1916.505778","cba2eaf.6ad3918"]]},{"id":"69c427f3.962e38","type":"change","z":"9fb28e31.fdea6","name":"","rules":[{"t":"set","p":"FridgeStatus","pt":"global","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":300,"wires":[["57a908e7.7f39c"]]},{"id":"953f1916.505778","type":"change","z":"9fb28e31.fdea6","name":"","rules":[{"t":"set","p":"FridgeStatus","pt":"global","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":720,"y":480,"wires":[["57a908e7.7f39c"]]},{"id":"57a908e7.7f39c","type":"change","z":"9fb28e31.fdea6","name":"","rules":[{"t":"set","p":"FridgeStatus","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":880,"y":420,"wires":[["7b672fa3.77cb3"]]},{"id":"7b672fa3.77cb3","type":"ui_text","z":"9fb28e31.fdea6","group":"12015f39.142781","order":8,"width":0,"height":0,"name":"Fridge OK?","label":"Fridge Ok?","format":"{{msg.payload}}","layout":"row-spread","x":1100,"y":420,"wires":[]},{"id":"12015f39.142781","type":"ui_group","z":"","name":"Lights","tab":"8e0b5c7a.424a48","disp":true,"width":"6","collapse":false},{"id":"8e0b5c7a.424a48","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

perhaps like this? But be aware this is only a first layout to give you a little kickstart.

[{"id":"caf032d7.6095a","type":"function","z":"9684985b.d608d8","name":"30-50Ā°","func":"msg.topic=msg.payload;  \nmsg.label=msg.payload;\nmsg.payload=40+(20*Math.random()-10);\nreturn msg;","outputs":1,"noerr":0,"x":271,"y":102,"wires":[["52e5a428.3e305c"]]},{"id":"d2da1ba2.346478","type":"inject","z":"9684985b.d608d8","name":"","topic":"","payload":"inside","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":118,"y":102,"wires":[["caf032d7.6095a"]]},{"id":"5e871ac3.39f914","type":"switch","z":"9684985b.d608d8","name":"Less then 40?","property":"payload","propertyType":"msg","rules":[{"t":"lte","v":"40","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":624,"y":102,"wires":[["fa00994.be95b68"],["223c3640.aaca4a"]]},{"id":"fa00994.be95b68","type":"change","z":"9684985b.d608d8","name":"below 40Ā°","rules":[{"t":"set","p":"FridgeStatus","pt":"flow","to":"all fine (<40)","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"below 40Ā°","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":978,"y":68,"wires":[["6981ae15.47cb8","2bf4750a.98e8ea"]]},{"id":"223c3640.aaca4a","type":"delay","z":"9684985b.d608d8","name":"Delay 2 minutes","pauseType":"delay","timeout":"2","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":845,"y":170,"wires":[["38b05bc3.587cd4"]]},{"id":"52e5a428.3e305c","type":"change","z":"9684985b.d608d8","name":"save","rules":[{"t":"set","p":"recent","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":441,"y":102,"wires":[["5e871ac3.39f914"]]},{"id":"38b05bc3.587cd4","type":"switch","z":"9684985b.d608d8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"recent","vt":"flow"},{"t":"gte","v":"recent","vt":"flow"}],"checkall":"true","repair":false,"outputs":2,"x":1019,"y":170,"wires":[["90758b69.0e0678"],["175cc3f6.0e514c"]]},{"id":"90758b69.0e0678","type":"change","z":"9684985b.d608d8","name":"falling","rules":[{"t":"set","p":"FridgeStatus","pt":"flow","to":"temp falling","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"falling","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1155,"y":136,"wires":[["6981ae15.47cb8","2bf4750a.98e8ea"]]},{"id":"175cc3f6.0e514c","type":"change","z":"9684985b.d608d8","name":"rising","rules":[{"t":"set","p":"FridgeStatus","pt":"flow","to":"temp rising","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"rising","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1155,"y":204,"wires":[["6981ae15.47cb8","2bf4750a.98e8ea"]]},{"id":"6981ae15.47cb8","type":"ui_text","z":"9684985b.d608d8","group":"203494fb.e2be2c","order":8,"width":0,"height":0,"name":"Fridge OK?","label":"Fridge Ok?","format":"{{msg.payload}}","layout":"row-spread","x":1362,"y":68,"wires":[]},{"id":"2bf4750a.98e8ea","type":"debug","z":"9684985b.d608d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1362,"y":119,"wires":[]},{"id":"203494fb.e2be2c","type":"ui_group","z":"","name":"Lights","tab":"612f702e.cc40e","disp":true,"width":"6","collapse":false},{"id":"612f702e.cc40e","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

I'm not really 100% up to speed in the thread. It has got away on me.

Sorry, but I'll play "devil's advocate" in that if the data arrives at given intervals and you want to see if it has changed in 2 hours (120 minutes).... It is just simple maths.

Though I guess it could get difficult if there are 6 readings in 2 hours. (Every 20 minutes.)
But time stamps are not really needed.

Certainly not that simple layout flow I got and replied. But I even donā€™t think that this will do the job very well, especially the false alarms will make the HFSD (human fan smacking device) going out of business very soon :crazy_face:

:slight_smile: Yeah. It isn't I meant to say you are/were wrong.

Sorry if that was how it sounded.

Believe me I am having lots of fun recently - as you may see by my posts.

No problem on my side :smiley: We need more fun these days :snowflake::snowflake::snowflake:

I was trying to track trend over time rather than temperature at a given moment in order to avoid false alarms. In other words, if it's dropping from 50 to 48 over the two hour period, there should be no alarm even though the temp is above 40 because the trend is downward.

That's what I can't figure out how to do in Node Red - trend tracking.

And thanks for your flow but I'm pulling temp data from a sensor which updates itself every few minutes and I couldn't see where in the flow I'd insert that data to test it. Thanks.

Oh and the reason the HFSD can work :slight_smile: is because the F only conks out maybe once or twice a year. Believe me if the HFSD has to S on a regular basis the HFSD will be getting a new fridge or calling the repair person!

Hi there, I use the avarage node to detect trends over a time periode. So I don't see spikes in the end result, just the trend.

I don't mean to derail this topic, but out of interest what sensor are you using? I naively assumed a sensor in the fridge would struggle with signal quality.

The Xiaomi Aqara. Haven't had a problem with the connection.

A bit late to the party but I'd like to throw my two cents into the ring.

You seem to be interested more in the differential than the value. I'd store measurements in an InfluxDB and query and compare values from x minutes ago with the current value. To make sure I do not hit two short drops with normal behavior in between I'd do two or three such comparisons with minutes between them.

1 Like

Could it be as simple as set the msg.payload to the global Fridge Temp variable, send the msg.payload to a Delay node which waits 2 hours, then, 2 hours later, compare the msg.payload to the current global Fridge Temp?

It is easier than that. If you are only interested in looking every two hours then every two hours send the temperature to a function node. In the function node you will save the current value to a node context variable. That means that also in the function node you can pick up the previous value and do the comparisons required to decide what to do. Look at the docs on writing functions to see how to save a value to the node context.

Is the flow I posted a while ago not doing that? Even without the need of a function node?