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?
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.
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"]
I had to put it like this, otherwise it wouldn't return anything - at least I think so:
let name = Object.keys(msg.payload.enums)[0]
msg.payload = msg.payload.enums[name];
return msg;
With a debug node, I get this:
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
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]
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 )