Get graph function

Hello, I have been working on a project where I have a meat thermometer hooked up to Node-Red with a nice dashboard etc. One thing I would want to do (because why not) is for me to be able to set the desired temperature and then have node-red tell me how long it will take until the meat is at that temperature. I'm thinking that the easiest way to make this is for node-red to make a graph(not linear) with the time and the temperature, get the function for this graph and then just solve the function with the set temperature. I know how I would make a graph and get the function of that graph in Excel but I don't know how I should go about doing it in node-red. I know that the dashboard plugin comes with a chart node but from my understanding, I can't get it to generate a function. Does anybody know a good way of doing this?

How would you get the function in Excel?

Sorry, maybe used the wrong name. What I mean is the trendline

Isn't a trendline a linear fit?

Screenshot 2020-06-12 17.41.13

Sorry, this might be me being stupid, but in the attached picture I have added a trendline to a graph in Excel and gotten it to tell me the function of that trendline (y=x^3). This is basically what I would want to do in Node-Red.

OK, I think you don't actually want to know that it is x^3, what you want to be able to do is to use the data as set of values and be able to interpolate intermediate values. Looking in the flows site I see https://flows.nodered.org/node/node-red-contrib-interpolate which might do what you want.

That's almost what I want. That flow seems to only work with linear interpolation and since the speed the temperature is rising is slowing down when it gets hotter I don't think a linear would work. Will have a look at the flows and see if I find another one.

Trend lines can be all sorts of different fits.

I didn't look in detail but I assumed that it did linear interpolation, but between individual adjacent points, so provided you have about 10 or so points up the curve it should be perfectly good enough. Why would that not meet your requirement?

Conventionally the term trend line is used to mean a linear fit.

@calania I have had a look at the code for node-red-contrib-interpolate and it does indeed interpolate between individual pairs of points, so should be perfect for your needs.

Thanks a lot for helping and looking at the code, I misunderstood. I just saw another thing in the flow description it says

The node only performs interpolation, not extrapolation. If one would e.g. calculate the temperature at a height of 200 meters in our example above, the node would just return the last available value of the grid (i.e. the temperature at 100 meters height.)

If I want to look into the future and see the how hot something is at a selected time isn't that extrapolation?

I don't think that is what you want to do. I think you want a graph (actually a table of values) showing the time taken to get from ambient to get to a particular temperature. Then you ask it to lookup the time taken (according to the graph) to get to the current temperature (say t1) the time that it would expect to take to get to the desired temperature (say t2) and difference (t2-t1) will give you how long it should take to get from now to the desired temperature.

To add a bit more detail, having done some experiments you might end up with a graph something like this, though you would need more points.

image

So then if you have a current temperature of, say 50 that will give you t1 of 7.5, and you know you want to get to for example 100 that is t2=50 so you can estimate that will happen in about 50-7.5 = 42.5 minutes.

Thank you, I understand what you mean. The thing is that the graph will look very different each time I run it. I am assuming that you are using the same graph each time. If you, for example, would have something in the oven at 170C it would take longer for it to reach the same temperature compared to if the oven would be 250C, meaning that I can't use the same graph and that I will need to make a new graph every time I run it.

Let's take your graph as an example, each time the temperature changes a point is added to the graph with the temperature and time when it changed. This point would be sent into the interpolate node.
This will create a graph like the one you showed. Let's say it's currently 110 degrees and I have created a nice graph up to 110 degrees(like your graph). I now want to know how long it would take for it to reach 120 degrees. I can't know that since I don't have any data point for values above 110 and I can't look at past measurements because the temperature or the thickness of whatever I'm measuring will create a very different graph.

I don't think that technique has any hope of working, unless you do a number of experiments in advance to work out the shape of the graph for a number of different sizes of joint and with a range of oven temperatures. Suppose, for example, if you were to put a bowl of water in a hot oven and measure the temperature of that as it heated up. I imagine you would find it was not too far off linear a it progressed up. Imagine that it took 10 minutes to get from 70C to 90C, so that is a rate of 0.5 degrees/minute. How long do think it might take to go the next 20 degrees? The extrapolation technique would suggest that it would take another ten minutes, but would be quite a long way from the right answer.
Now a joint of meat is not a bowl of water but I am sure there will be very significant non-linearities in the response. However the only way to know is to keep the data for a number of runs and plot the graphs and see what it looks like.

Hello, sorry for the late answer. I did a bit of reading and found this javascript script https://stackoverflow.com/questions/11796810/calculate-trendline-and-predict-future-results
do you think that would work and if so how should I add that in node reds function node? I am not that familiar with coding but from my understanding, I need to change the code so it inputs msg.payload but I don't know where to write that.

If that doesn't works I am like you also alluded to, starting to think that a linear graph might be accurate enough. I am thinking about using the CSV node a few time to have a look at a few graphs and see what it shows.

I would start by monitoring the temperature under real conditions. Send the values to a database (such as influxdb) and use Grafana (or similar) for charting, so you can easily go back and look at historical results. That will allow you to see what shape the graph actually is and determine what method of prediction might work.

Okay, thank you will try that.

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