let volt = app.getSelfPath('electrical.batteries.Mo.voltage');
the payload looks like
{"meta":{"units":"V","description":"Voltage measured at or as close as possible to the device"},"value":13.2,"$source":"jbd-overkill-bms-plugin","timestamp":"2025-04-08T10:14:51.566Z"}
but i only want "value":13.2
how does it work?
thx/christian
When you say the payload looks like that object, do you mean the value returned by app.getSelfPath?
Assuming that is the case, and assuming its an Object and not a String, then it looks like volt.value will get you to 13.2.
However, if it is a String and not an Object, you will need to parse it to an Object first. You can do that by passing it through a JSON node, or if you want to stay inside a Function node, you can do const data = JSON.parse(volt) - then you can use data.value.
There's a section in the docs that gives some tips for working with messages - Working with messages : Node-RED
This includes how to pass messages to the debug sidebar and work out how to access individual properties.
its an openplotter image for raspi4. inside openplotter there is Signal K. and inside Signal K there is Node Red and KIP. KIP is my UI, there is a button and when i click the button Node Red should write something in a file. electrical.batteries.Mo.voltage is a Signal K path coming from a signal k plugin and how it looks the only chance to work with this signal k path in node red is with a function like this.
msg.filename ="/home/pi/test/hello.txt";
let app = global.get('app');
let volt = app.getSelfPath('electrical.batteries.Mo.voltage');
msg.payload = volt;
return msg;
the
const data = JSON.parse(volt)
dont work:
function : (error)
"SyntaxError: Unexpected token o in JSON at position 1"