Extract object value

Hello, can me someone explain me how i can extract the value temperature from the following payload?

I tried with a change node but it doesnt work. I can extract the value from the array meters, but not the temperature value. Can someone give me a example for a syntax please?

msg : Object
object
payload: object
topic: ""
_msgid: "84c5eb0c.4365a8"
status: object
wifi_sta: object
cloud: object
mqtt: object
time: "20:42"
serial: 1
has_update: false
mac: "xxxxxxxxxx"
relays: array[1]
meters: array[1]
temperature: 25.23
overtemperature: false
update: object
ram_total: 50832
ram_free: 39616
fs_size: 233681
fs_free: 171684
uptime: 10387

Thx for help

As you have not used the copy value button in the debug side panel, the object you have shown is confusing.
I believe the correct path is msg.temperature.

If you use the debug panel and hover to side of object name 2 icons appear, one is copy value, the other copy path. Both very helpful.
The copy value icon/button would give you a correctly formated object, and it would be easier to see the correct object structure.

Hi and thanks at first

I tried to copy the hole object with the button in the debug panel

i hope it`s better now

{"_msgid":"5e7881f7.f5cd2","payload":{"relays":[{"ison":false,"has_timer":false,"overpower":false}],"meters":[{"power":0,"is_valid":true,"timestamp":1662756933,"counters":[0,0,0],"total":2397}]},"topic":"","status":{"wifi_sta":{"connected":true,"ssid":"xxxxxxx","ip":"xxxxxx","rssi":-68},"cloud":{"enabled":false,"connected":false},"mqtt":{"connected":false},"time":"20:55","serial":1,"has_update":false,"mac":"xxxxxxx","relays":[{"ison":false,"has_timer":false,"overpower":false}],"meters":[{"power":0,"is_valid":true,"timestamp":1662756933,"counters":[0,0,0],"total":2397}],"temperature":25.23,"overtemperature":false,"update":{"status":"unknown","has_update":false,"new_version":"","old_version":"20190516-073020/master@ea1b23db"},"ram_total":50832,"ram_free":40224,"fs_size":233681,"fs_free":171684,"uptime":11191}}

If i try msg.temperature i`ve got this.....

{"_msgid":"35ed5510.63a5ba","topic":"","status":{"wifi_sta":{"connected":true,"ssid":"xxxxxxxxx","ip":"xxxxxxxx","rssi":-68},"cloud":{"enabled":false,"connected":false},"mqtt":{"connected":false},"time":"21:01","serial":1,"has_update":false,"mac":"xxxxxxxx","relays":[{"ison":false,"has_timer":false,"overpower":false}],"meters":[{"power":0,"is_valid":true,"timestamp":1662757279,"counters":[0,0,0],"total":2397}],"temperature":25.23,"overtemperature":false,"update":{"status":"unknown","has_update":false,"new_version":"","old_version":"20190516-073020/master@ea1b23db"},"ram_total":50832,"ram_free":40064,"fs_size":233681,"fs_free":171684,"uptime":11537}}

but i wan`t only the value

It is msg.status.temperature
which you can find using the copy path button, and appending msg. to the front


hover mouse near where is says copy value and the copy value and path buttons will appear, use the path button to get the path to the adjacent property value.

And here is an example of moving the temperature value to msg.payload, using a change node.

[{"id":"28100460.a4b09c","type":"inject","z":"30af2d3e.d94ea2","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":150,"y":2660,"wires":[["7bbe61b3.327768","1fd9e3b8.9d6dec"]]},{"id":"1fd9e3b8.9d6dec","type":"function","z":"30af2d3e.d94ea2","name":"simulate object","func":"msg={\n    \"_msgid\": \"5e7881f7.f5cd2\",\n    \"payload\": {\n        \"relays\": [\n            {\n                \"ison\": false,\n                \"has_timer\": false,\n                \"overpower\": false\n            }\n        ],\n        \"meters\": [\n            {\n                \"power\": 0,\n                \"is_valid\": true,\n                \"timestamp\": 1662756933,\n                \"counters\": [\n                    0,\n                    0,\n                    0\n                ],\n                \"total\": 2397\n            }\n        ]\n    },\n    \"topic\": \"\",\n    \"status\": {\n        \"wifi_sta\": {\n            \"connected\": true,\n            \"ssid\": \"WLAN-99D921\",\n            \"ip\": \"192.168.178.53\",\n            \"rssi\": -68\n        },\n        \"cloud\": {\n            \"enabled\": false,\n            \"connected\": false\n        },\n        \"mqtt\": {\n            \"connected\": false\n        },\n        \"time\": \"20:55\",\n        \"serial\": 1,\n        \"has_update\": false,\n        \"mac\": \"E868E7C507FA\",\n        \"relays\": [\n            {\n                \"ison\": false,\n                \"has_timer\": false,\n                \"overpower\": false\n            }\n        ],\n        \"meters\": [\n            {\n                \"power\": 0,\n                \"is_valid\": true,\n                \"timestamp\": 1662756933,\n                \"counters\": [\n                    0,\n                    0,\n                    0\n                ],\n                \"total\": 2397\n            }\n        ],\n        \"temperature\": 25.23,\n        \"overtemperature\": false,\n        \"update\": {\n            \"status\": \"unknown\",\n            \"has_update\": false,\n            \"new_version\": \"\",\n            \"old_version\": \"20190516-073020/master@ea1b23db\"\n        },\n        \"ram_total\": 50832,\n        \"ram_free\": 40224,\n        \"fs_size\": 233681,\n        \"fs_free\": 171684,\n        \"uptime\": 11191\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":410,"y":2640,"wires":[["84810f46.52a128"]]},{"id":"84810f46.52a128","type":"change","z":"30af2d3e.d94ea2","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"msg.status.temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":2640,"wires":[["2e310c13.5e5c1c"]]},{"id":"2e310c13.5e5c1c","type":"debug","z":"30af2d3e.d94ea2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":750,"y":2680,"wires":[]}]

Ignore the function node it is just simulating your msg object.

I`ve got still this result

{"_msgid":"1c16882.1c3f878","payload":25.23,"topic":"","status":{"wifi_sta":{"connected":true,"ssid":"xxxxxx","ip":"xxxxxxxx","rssi":-68},"cloud":{"enabled":false,"connected":false},"mqtt":{"connected":false},"time":"21:08","serial":1,"has_update":false,"mac":"xxxxxxxxx","relays":[{"ison":false,"has_timer":false,"overpower":false}],"meters":[{"power":0,"is_valid":true,"timestamp":1662757714,"counters":[0,0,0],"total":2397}],"overtemperature":false,"update":{"status":"unknown","has_update":false,"new_version":"","old_version":"20190516-073020/master@ea1b23db"},"ram_total":50832,"ram_free":39888,"fs_size":233681,"fs_free":171684,"uptime":11972}}

this ist the actual flow i use for testing, maybe it helps you

[{"id":"10dd93ba.077dec","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"a9a4cecf.d695d","type":"debug","z":"10dd93ba.077dec","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":830,"y":400,"wires":[]},{"id":"475a1574.c2a66c","type":"inject","z":"10dd93ba.077dec","name":"Poll Status","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":240,"y":200,"wires":[["404f5a7d.fb0f4c"]]},{"id":"404f5a7d.fb0f4c","type":"shelly-gen1","z":"10dd93ba.077dec","hostname":"xxxxxxxxxx","description":"","mode":"polling","server":"","outputmode":"event","uploadretryinterval":5000,"pollinginterval":5000,"pollstatus":false,"getstatusoncommand":true,"devicetype":"Relay","outputs":1,"x":610,"y":420,"wires":[["a9a4cecf.d695d","9665bd31.67ea"]]},{"id":"931b878e.b08448","type":"debug","z":"10dd93ba.077dec","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":930,"y":580,"wires":[]},{"id":"9665bd31.67ea","type":"change","z":"10dd93ba.077dec","name":"","rules":[{"t":"move","p":"status.temperature","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":500,"wires":[["931b878e.b08448"]]}]

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.

BX00Cy7yHi

Sorry, but maybe i didn`t understand

i copied the path directly behind the temperature value but i`ve still got the hole object and not the single value

grafik

and this is my configuration from the change node

grafik

It still doesn`t work - maybe a bug in nodes?

I have no idea anymore

Nobody`s here with any solution?

You will always get the msg object. But you have moved the temp value now to msg.payload.
if you moved msg.status.temperature to msg, node-red would produce an error, as msg has to be returned as an object.
Your debug is set to see the complete object, not just msg.payload.

We can not give a solution as nothing is wrong, You are not understanding message objects and there construction correctly.

There is no msg.status.temperature in that object. How ever in the first object you provided that value does exist.

Is it possible you are getting different data, some with msg.status.temperature and some without??

Where is the data coming from?

As said before, the change node is working properly , moving the temperature in the payload property of the message but not creating a new message that would contain only the temperature….
The tricky thing is that you did not noticed that debug node was configure to display the complete message…

To recreate a new message with the temperature only, you can use a function node.
I recommend this video that will show you clearly how to https://youtube.com/watch?v=bovIZtgL68E&feature=share

Pierre RUWET

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