That payload is a valid JSON string. That means you can pass it to a JSON node which will convert it to the JavaScript object equivalent. That allows you to address the individual properties of the object directly.
Then you will be able to use a Change node to set msg.payload to the value of msg.payload.power.
In fact if, in the mqtt node settings, you select the Output as Parsed JSON, then the node will automatically convert it from JSON to a javascript object, which you can feed straight into the Change node. However you may not even need to do that. What are you going to do with it after you have passed on the message with it in the payload.
Thanks ok have got working with the change node. I have built a ESP32 Smart Power Meter from GitHub. Issue is I cant figure how to slow down the MQTT state changes as they are very sec and this is loading my PI running Home Assistant. I use Node Red on this PI and want to delay (added a delay node/limiting) the Power reading to 1 every 30s. So I created a NR MQTT flow and now want to end up with just the numeric numbers as they change but 1 reading every 30s.
You can use the Delay node to do this. Configure it to be in "rate limiting" mode and pick the rate for the messages. Make sure you click the "drop intermediate messages" box.
Thanks sorry I have completed that its working. I need now to only have the returned message as a numeric number example 3463 from {"power":3463} with the understanding that the number can range from 0 to 7200.
Dropping 29 out of 30 samples is not that nice.
You can miss vital information. What if sample 18-23 is a current peak?
Better feed the 30 samples in the calculator node and release the mean value after 30 samples. You get then 1 output in 30 sec with the average of the last 30sec.
node-red-contrib-calculate
Sorry I'm on my tablet and can't give you a example now.
Passing it to a JSON node gives me the following 4002 but in the debug is power:4002 and the flow debug reports Topic removed, non numerical value found. if I copy the path I see payload.power and the value is 4002 but the flow reports non numerical value found. Watched the video and I still dont see what I am doing wrong?
Without a screenshot or your flow it is difficult to tell but I suspect where ever you're sending it to wants the value to be in payload. So add a change node after the JSON node, set msg.payload to msg.palyload.power then send it to where it needs to go.
Ps, that video is part of a series. They are nice short 2m easily digestible & hugely beneficial to watch. Honestly, invest 20mins watching the series. All of what I said above just clicks into place.
Top flow works with change node
Bottom flow with delay / json node path payload and value is 3671 which is correct. So I want to replace the change node with the json which throws the error of non numerical value found which I suspect is power: portion. Will also watch the videos...
You can use a change node with a jsonata round function. This gives you the option to round it to any precision you would like just with a change node and no function or additional node needed.