Getting a value from json for a gauge

I'm new to this, so much to learn with Home Assistant, Tasmota, Grafana and now Node Red.

I'm trying to construct a Node Red Dashboard to display and control my Owl Intuition Electricity monitor and Central Heating system.

Stuck on how to get the "current power" value out of the json payload to feed into a gague.

The message comes in OK via UDP Multicast node which then goes through a switch node to separate the flows for the 3 different message types. Each then goes through a XML node which puts it into a jsons format (I think).
Originally I had that output going to the gauge with the path to the element I wanted copied from that element in the debug window. Although the gauge showed the right level the text was the whole thing so I read somewhere to get just the value I wanted by a function node.
So I put the path into the function but I get the error that it is returning a string.
What am I doing wrong?
My line in the function is:

return msg.payload.electricity.chan[0].curr[0]._;

The payload it's trying to read is:


Welcome to the forum.

Have a look here:

A function needs to return an object as the debug node by default wants to read from msg.payload, a string was given, hence the error.

return {payload:msg.payload.electricity.chan[0].curr[0]._};

Personally i find it cleaner with a change node in combination with jsonata (can directly parse it as a number as well), or just extract it like "normal"

Brilliant. The first method worked on the example i gave, and on another feeding a graph. Thanks. I will try the second method too as i have many more values to extract.
So much to learn, and i like to learn by setting myself a project; it would be a lot harder without people like you showing us newbies the way.

By the way, that isn't JSON, it is a javascript object. JSON is always a string, that can be converted to a js object by feeding it through a JSON node (or vice versa).

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