Hi
I'm dead sure it's because I'm newbie, I hope someone will help me out here - here is my problem:
I'm trying to calculate where if have power to start other things in the house, this is done by looking at the value: (payload.data.PO - payload.data.P) comming on MQTT, this part works.
My problem is in the node: "Calculate power diff" here I keep getting the error: TypeError: Cannot read properties of undefined (reading 'data')
My code is:
var value = msg.payload["power"]
msg.payload = value.data.PO - value.data.P
return msg;
There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path to any data item.
Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.
in short var value = msg.payload["power"] means value is now pointing to msg.payload.power and value.data.PO is pointing to msg.payload.power.data.PO
But again - use the tools provided to avoid simple mistakes (use the "Copy Path" button)
Clearly you have not (or clicked something else further off screen) - where did msg.payload["power"] come from - its not in that image.
Try again - hover over the item of interest (e.g. PO) and click the "copy path" item. When you paste it in a function you need to suffix it with msg. e.g. msg.payload.x.y.x