Detect if temperature is rising, falling or is stable

Hello, I have made a display that shows the temprature inside my house however I would like to be able to see if the temperature is rising, falling or if it's stable. The temperature is sent to node-red through MQTT via Zigbee temperature sensors which means that the temperature isn't sent at fixed intervals.

What I would want to do is have Node-Red check if the temperature has risen/fell with 0,5 C/h between the last two measurements. If it has this means that the temperature is changing and if not then it is stable. Any idea on how I could implement this?

Hi, you could store the last temp and time, Then work out the the rise per hour.
Here is a test flow.
have a play, hope it helps.

[{"id":"67943901.df7ea8","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"19.4","payloadType":"num","x":130,"y":4600,"wires":[["c044f43f.c9ad98"]]},{"id":"c044f43f.c9ad98","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"riseFall","pt":"msg","to":"($time := ($millis()-$flowContext(\"riseFallTime\"))/3600000;\t$ratio := $round(($$.payload - $flowContext(\"lastTemp\")) / $time, 1) ;\t($abs($ratio) >= 0.5 ? ($ratio >= 0 ? \"rising \" : \"falling \") : \"stable \") & $ratio & \" Per/Hour\"\t)","tot":"jsonata"},{"t":"set","p":"riseFallTime","pt":"flow","to":"","tot":"date"},{"t":"set","p":"lastTemp","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":4620,"wires":[["4e1f0f54.aa3c3"]]},{"id":"4e1f0f54.aa3c3","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":570,"y":4560,"wires":[]},{"id":"aaf3c426.aea458","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20","payloadType":"num","x":130,"y":4640,"wires":[["c044f43f.c9ad98"]]},{"id":"b5f96a31.e669b","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20.6","payloadType":"num","x":130,"y":4680,"wires":[["c044f43f.c9ad98"]]},{"id":"58be9bb5.dbcdb4","type":"inject","z":"c74669a0.6a34f8","name":"set test time 1 hour in past","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":230,"y":4480,"wires":[["be7e191.ad93268"]]},{"id":"be7e191.ad93268","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"riseFallTime","pt":"flow","to":"$millis()-3600000","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":4480,"wires":[[]]}]
1 Like

hi @calania , you could use a flow variable to store the value, then use the switch node to compare it, all with a inject node to activate the flow every hour.

for example!!

This is a classical topic for trend analysis

You could do it in the simplest form by creating two calculations of moving averages, commonly used method in various disciplines like stock trading etc. Make one long and one shorter. When their value crosses you have a change in trend direction. You can use the Smooth node for this, configure one for the latest 15 readings, the other for 5. Then add some logik to compare when the values make the crossovers

Just comparing a single value with previous does not say anything about the trend

A crossover between the two will signal a reversal in trend, or a breakout or breakdown. A breakout would be indicated by the five-period moving average crossing up through the 15-period. This is also indicative of an uptrend, which is made of higher highs and lows.

2 Likes

Thanks all three of you! I will have a look and see if I can I get it working.

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