In template(not the dashboard one), payload not refresh

with a debug node, I can see the function node is outputting different values, but in the template's JS, every time it comes with same value.

Hi @kihararuntu

The Template node generates text using the message it is given. It then passes that text on to the next node in the flow. That is all.

In your flow, you are using the Template node to generate some text that happens to be HTML/JavaScript that gets returned in response to an HTTP request to /test. When the Template node receives the message from the Function node it will generate that text and {{payload.gasPct}} will get replaced with the value of msg.payload.gasPct at that point in time.

Once that text is returned to the browser, there is no connection at all between what the browser does with that text and Node-RED. When the setInterval runs, the code inside it will have the value of payload.gasPct already hardcoded to that one value - nothing will change.

If you want a page to update with the latest value, then you can:

  1. create a separate HTTP flow that just returns the data value, which you then poll using JavaScript on your page
  2. create a WebSocket from your page back to another flow that can send the new value whenever it changes

The ability to just wire a flow into a page is one of the features provided by things like Node-RED Dashboard or UIBuilder. They do that work for you, to save you having to do the plumbing yourself. Of course they both come with other trade-offs in return for that convenience.

Thank you! I also felt like it only hardcodes once, but can't find a way to solve it, thank you for your advice

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