# How to get value from iobroker object

**URL:** https://discourse.nodered.org/t/how-to-get-value-from-iobroker-object/53539
**Category:** General
**Created:** [10 November 2021 23:14 UTC](https://discourse.nodered.org/t/how-to-get-value-from-iobroker-object/53539 "2021-11-10T23:14:03Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Schmtterfliege](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@Schmtterfliege](https://discourse.nodered.org/u/Schmtterfliege)
#### Post date: [10 November 2021 23:14 UTC](https://discourse.nodered.org/t/how-to-get-value-from-iobroker-object/53539/1 "2021-11-10T23:14:03Z")

</div>

Hi,

I tried a bunch of things, but I'm not able to get the value from the enums object.  
I'm using the iobroker list node to get all values from a zigbee sensor.  
In iobroker the sensor is assigned to a room, which creates the enums.rooms.gästezimmer "value" in this case.  
I'm trying to get the room name (in this case "Gästezimmer"), but somehow I'm only able to get the path instead of the value.  
msg.payload.enums[0] or msg.payload.enums.val results in "undefined".  
What's strange is that when I click "copy value" in the debug window, I get the correct value "Gästezimmer".  
How can I get this via the function node?

I hope this screenshot makes it more clear 😃

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/f/9f5190d04b2a1df550287469971365606be5ab33.png)

Thanks in advance!

---

<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: [10 November 2021 23:26 UTC](https://discourse.nodered.org/t/how-to-get-value-from-iobroker-object/53539/2 "2021-11-10T23:26:21Z")

</div>

If you use the copy path button in the debug, you will get the path `payload.enums["enums.rooms.gästezimmer"]`  
In the function node you would use `msg.payload.enums["enums.rooms.gästezimmer"]` to access the value.

read this page and watch the videos here for more info on paths and messages  
[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<div class="post-metadata">

### Author: ![Schmtterfliege](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@Schmtterfliege](https://discourse.nodered.org/u/Schmtterfliege)
#### Post date: [11 November 2021 00:03 UTC](https://discourse.nodered.org/t/how-to-get-value-from-iobroker-object/53539/3 "2021-11-11T00:03:01Z")

</div>

Hey,

thanks alot for your feedback again!

I feared that would be the way to go, but the problem with that is that for each room this will change.  
So for one sensor it will be `msg.payload.enums["enums.rooms.gästezimmer"]`, for the next one `msg.payload.enums["enums.rooms.wohnzimmer"]` and so on.

Is there a way to use this with a "placeholder"?  
Like:  
`msg.payload.enums["enums.rooms.PLACEHOLDER"]`

---

<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: [11 November 2021 00:13 UTC](https://discourse.nodered.org/t/how-to-get-value-from-iobroker-object/53539/4 "2021-11-11T00:13:54Z")

</div>

You could possibly do

```auto
let name = Object.keys(msg.payload.enums)[0]
msg.payload.enums[name];

```

---

<div class="post-metadata">

### Author: ![Schmtterfliege](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@Schmtterfliege](https://discourse.nodered.org/u/Schmtterfliege)
#### Post date: [11 November 2021 14:13 UTC](https://discourse.nodered.org/t/how-to-get-value-from-iobroker-object/53539/5 "2021-11-11T14:13:17Z")

</div>

It works! But also doesn't 😃

I had to put it like this, otherwise it wouldn't return anything - at least I think so:

```auto
let name = Object.keys(msg.payload.enums)[0]
msg.payload = msg.payload.enums[name];
return msg;

```

With a debug node, I get this:  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f67864abef4d91accf9c51d802feefe18da9700e.png)  
I mean... I get the payload I want. But what is the error above? And why does it still work? 😃

And I just noticed that it might be more complicated.  
For some room names IoBroker had a default name. E.g. Kitchen is a default name.  
For these rooms I don't get one value (the name I gave it) but 10 - for 10 translations 😃  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/8/5871f38c17d6dc4e701efd5ed39f5b7c1636100e.png)  
But I'm sure I'll find a workaround 🙂

---

<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: [11 November 2021 14:40 UTC](https://discourse.nodered.org/t/how-to-get-value-from-iobroker-object/53539/6 "2021-11-11T14:40:56Z")

</div>

> [@Schmtterfliege](#):
>
> otherwise it wouldn't return anything

You all ways have to return a function node, I thought that was obvious.

As to error are you certain it is coming from that function node. Export an example flow that shows the issue, don't forget to add example input data in an inject node.  
As to last problem check that payload is an array, if so the move msg.payload.en to msg.payload, Or do `msg.payload = msg.payload.enums[name].en || msg.payload.enums[name]`

---

<div class="post-metadata">

### Author: ![Schmtterfliege](https://avatars.discourse-cdn.com/v4/letter/s/b9bd4f/32.png) [@Schmtterfliege](https://discourse.nodered.org/u/Schmtterfliege)
#### Post date: [11 November 2021 14:51 UTC](https://discourse.nodered.org/t/how-to-get-value-from-iobroker-object/53539/7 "2021-11-11T14:51:15Z")

</div>

It was indeed another function node that was connected to the one I was testing.  
The error didn't come from the debug node I had added, but from the "system" I guess.  
The function creating the error wasn't connected to the debug node (or anything else via it's output).

Another problem solved - thank you so very much!!  
(and sorry for my noob skills 😃 )

---

<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: [25 November 2021 14:51 UTC](https://discourse.nodered.org/t/how-to-get-value-from-iobroker-object/53539/8 "2021-11-25T14:51:47Z")

</div>

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