# Extract same data from different objects

**URL:** <https://discourse.nodered.org/t/extract-same-data-from-different-objects/72755>\
**Category:** General\
**Created:** [27 December 2022 07:39 UTC](https://discourse.nodered.org/t/extract-same-data-from-different-objects/72755 "2022-12-27T07:39:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Statler](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/statler/32/32541_2.png) [@Statler](https://discourse.nodered.org/u/Statler)\
**Post date:** [27 December 2022 07:39 UTC](https://discourse.nodered.org/t/extract-same-data-from-different-objects/72755/1 "2022-12-27T07:39:50Z")

</div>

Hi all,

Nodered subscribes to a topic of a Zbridge which delivers Sensor data in its message:

{"ZbReceived":{"0xB342":{"Device":"0xB342","Name":"OFIC","Temperature":24.57,"Humidity":83.39,"Endpoint":1,"LinkQuality":81}}}

If I rightclick to copy the path to extract "Temperature", it will just extract the humidty value of this specific device but I would like to extract "Name" and "Humidity" of all devices, so the payload I wish to extract is not

payload.ZbReceived["0xB342"].Temperature

but

payload.ZbReceived["0xAB23"].Temperature

I manage to change the payload of each device to the desired values and extract them, but unfortunately, the device ID changes often and I need to adjust the code.

Is there a way to change any of these incoming messages to name and humidity independently?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 December 2022 08:12 UTC](https://discourse.nodered.org/t/extract-same-data-from-different-objects/72755/2 "2022-12-27T08:12:28Z")

</div>

Does each ZbReceived have other keys, or is the one of interest the only one? If it has others, how do you know which is the one of interest?

---

<div class="post-metadata">

**Author:** ![M-a-r-t-i-n](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/m-a-r-t-i-n/32/52391_2.png) [@M-a-r-t-i-n](https://discourse.nodered.org/u/M-a-r-t-i-n)\
**Post date:** [27 December 2022 08:26 UTC](https://discourse.nodered.org/t/extract-same-data-from-different-objects/72755/3 "2022-12-27T08:26:48Z")

</div>

From that data structure I am guessing that you have tasmota running on the bridge. If so, take a look at the setoption83 command in tasmota. When enabled tasmota will replace that ID number with the ‘friendly’ name of the zb device.

(Edit) I’ve just managed to take a look at how my bridge at home is configured. You may find the setoption119 a better option. It removes the ID from that part of the message.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [27 December 2022 09:23 UTC](https://discourse.nodered.org/t/extract-same-data-from-different-objects/72755/4 "2022-12-27T09:23:32Z")

</div>

You need to identify the msg.payload.ZbReceived 1 and only property, which will be the name, then use that to extract the info.  
e.g.

```auto
const name = Object.keys(msg.payload.ZbReceived)[0];
const temp = msg.payload.ZbReceived[name].Temperature;
const hum = msg.payload.ZbReceived[name].Humidity
msg.payload = {name, hum, temp};
return msg;

```

Example flow

```auto
[{"id":"1b26608e566196d3","type":"inject","z":"da8a6ef0b3c9a5c8","name":"0xB342","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"ZbReceived\":{\"0xB342\":{\"Device\":\"0xB342\",\"Name\":\"OFIC\",\"Temperature\":24.57,\"Humidity\":83.39,\"Endpoint\":1,\"LinkQuality\":81}}}","payloadType":"json","x":230,"y":600,"wires":[["f6f3a0abdfcdd0ea"]]},{"id":"f6f3a0abdfcdd0ea","type":"function","z":"da8a6ef0b3c9a5c8","name":"function 19","func":"const name = Object.keys(msg.payload.ZbReceived)[0];\nconst temp = msg.payload.ZbReceived[name].Temperature;\nconst hum = msg.payload.ZbReceived[name].Humidity\nmsg.payload = {name, hum, temp};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":600,"wires":[["22e0d6e0318685cd"]]},{"id":"06fa988581035686","type":"inject","z":"da8a6ef0b3c9a5c8","name":"0xAB23","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"ZbReceived\":{\"0xAB23\":{\"Device\":\"0xB342\",\"Name\":\"OFIC\",\"Temperature\":25.57,\"Humidity\":73.39,\"Endpoint\":1,\"LinkQuality\":81}}}","payloadType":"json","x":230,"y":640,"wires":[["f6f3a0abdfcdd0ea"]]},{"id":"22e0d6e0318685cd","type":"debug","z":"da8a6ef0b3c9a5c8","name":"debug 86","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":560,"y":600,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Statler](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/statler/32/32541_2.png) [@Statler](https://discourse.nodered.org/u/Statler)\
**Post date:** [27 December 2022 09:47 UTC](https://discourse.nodered.org/t/extract-same-data-from-different-objects/72755/5 "2022-12-27T09:47:42Z")

</div>

Thanks for the speedy reply. Yes, that is the problem. Each ZbReceived has a different key and if this was not enough: they are changing. They are all of interest as they all send climate data: temperature and humidity. And although the the ZbReceived ID changes, the name does not.

@M-a-r-t-i-n  
You have seen this correctly, I am using Tasmota and thanks a lot for those two solutions. Indeed, this will sort my problem.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 January 2023 09:48 UTC](https://discourse.nodered.org/t/extract-same-data-from-different-objects/72755/6 "2023-01-10T09:48:29Z")

</div>

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