Node -red filtering

hi guys
i am not so good in NodeJs,
please how can i filter the the messages so that i will only debug few of the messages
the messages are {"timestamp":"2021-11-22T22:40:00","load_state":"ON","load_w":148.946,"output_wh_total":4003,"output_wh_delta":49,"solar_w":0,"solar_v":3.832,"input_wh_total":0,"bat_v":25.258,"state_of_charge":100,"full_charges_count":1,"deep_discharges_count":0,"bat_chg_total_wh":0,"bat_dis_total_wh":4003,"bat_usable_ah":0,"bat_temp":36.148,"restart_detected":false,"signal_strength":-59,"error_flag":0}

i want to display these values

1."load_state"
2."bat_v"
3."load_w"
3. "bat_temp"

i did this

const values = [
  {
    "load": `${msg.payload.load_w}`
  }
  ]
  msg.payload=values;
  return msg;

but my result is load: "undefined"
thanks fro your help !

@knolleary

Please try to not tag individual users in posts - particular when bumping a post that hasn't been replied to as quickly as you'd like.

Given your previous question about parsing the JSON to a JavaScript object, are you sure you're passing the parsed object into this function node?

Add a debug node next to the function node so you can check exactly what the message looks like that is being passed into the Function - is msg.payload an object or string?

Thank you very much.
i will not next time.
both string and object

A single property cannot be both things. Can you share a screenshot of the debug sidebar showing us what you are passing into the Function node.

thanks Knolleary,

here are the screenshots

the message i got from the debug node
image

the function node before the debug node

image

the node all together

image

You have shown a screenshot of the Debug sidebar for the message coming out the Function node - that doesn't help us. You've already told us it isn't what you want.

What we need to see is the message you are passing in to the Function node. That's the only way we can help you get the Function code right.

oh ok
this is the message passing through the node

{"timestamp":"2021-11-22T22:40:00","load_state":"ON","load_w":148.946,"output_wh_total":4003,"output_wh_delta":49,"solar_w":0,"solar_v":3.832,"input_wh_total":0,"bat_v":25.258,"state_of_charge":100,"full_charges_count":1,"deep_discharges_count":0,"bat_chg_total_wh":0,"bat_dis_total_wh":4003,"bat_usable_ah":0,"bat_temp":36.148,"restart_detected":false,"signal_strength":-59,"error_flag":0}

image

There’s a great page in the docs 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.

BX00Cy7yHi

https://nodered.org/docs/user-guide/messages

Once you get the path then you can use that in a Change node to Move that item To msg.payload.

1 Like

thanks alot.
so useful !!!!

You have posted two things there, the first is a copy/paste of a javascript object containing the data, the second is a screenshot supposedly of that same data. However the screenshot shows that the data is in the first element of an array in msg.payload. The copy/paste object is not in an array. You need to decide which one of those is the real data.

this is the real data

{"timestamp":"2021-11-22T22:40:00","load_state":"ON","load_w":148.946,"output_wh_total":4003,"output_wh_delta":49,"solar_w":0,"solar_v":3.832,"input_wh_total":0,"bat_v":25.258,"state_of_charge":100,"full_charges_count":1,"deep_discharges_count":0,"bat_chg_total_wh":0,"bat_dis_total_wh":4003,"bat_usable_ah":0,"bat_temp":36.148,"restart_detected":false,"signal_strength":-59,"error_flag":0}

In that case why did it show as in an array in the screenshot

image

i am not so sure i just copied the value from debugged message.

[{"timestamp":"2021-11-22T22:40:00","load_state":"ON","load_w":148.946,"output_wh_total":4003,"output_wh_delta":49,"solar_w":0,"solar_v":3.832,"input_wh_total":0,"bat_v":25.258,"state_of_charge":100,"full_charges_count":1,"deep_discharges_count":0,"bat_chg_total_wh":0,"bat_dis_total_wh":4003,"bat_usable_ah":0,"bat_temp":36.148,"restart_detected":false,"signal_strength":-59,"error_flag":0}]

Now you are showing it in an array (it has the [...] around it). Presumably you missed those out when copying it the first time.

oh i see.

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