Having trouble converting Javascript-format to JSON-format

Does any one know how to use a value from an input_text helper in the Change node?

I’ve spent a lot of time and did not find a correct version.
I did find a working version using the Function-node, though.
I enclosed both versions:


Thanks in advance!


You are mixing two technologies. If you want to include code in a change node, Node Red supports JSONata. However using {{ states(...) }} is Home Assistant’s templating format, which is unrelated. The only time you can use HA templates in NR is within the “render template” node, which you could use, but is unnecessary.

While you could do it in a function node using global state, it’s not very visual.

The visual programming way to do this would be to have a “current state” node before the change node which loads the sensor state into the message somewhere - by default it would load into “msg.payload”. Let’s say you instead store the state in “msg.watermeter”, then you would use that in the change node as follows (after changing from “{}” to “J”):

  { "value": watermeter }

Indeed I was looking for a (NR-stylish) more visual way than with the function node.

And both your solutions work! Kermit’s being the shortest.

1 Like