Set change-node Payloadpath to msg.payload.+global

Thanks. I will read about it

I have read about the hasownproperty thing, but my knowledge was not deep enough to understand it complety.

I tried your modified version and even added after getting error messages nevertheless my part to:
const key = global.get("ZBB_BMotion");
if (msg.payload.ZbReceived.hasOwnProperty(key) !== null && msg.payload !== '') {
msg.payload = msg.payload.ZbReceived[key];
return msg;
}

But that doesnt solved the error messages also.

If you want it the other way try

  $lookup(payload.ZbReceived, $globalContext("test"))
2 Likes

If you take the exact function i posted it should never get to the part that creates the error at least if your input messages always have the msg.payload.ZBreceived object.

Thats the one, nice :+1: now on to add the other tests as below :see_no_evil:

Yes, i understand. i found out there are more messages send like ...ZbBind, ZBStatus. Is there a way to filter that out?

Yes add the other conditions to the if statement:

const key = global.get("BathroomMotion");
if (typeof msg.payload === "object" && msg.payload.hasOwnProperty("ZbReceived") && msg.payload.ZbReceived.hasOwnProperty(key)) {
    msg.payload = msg.payload.ZbReceived[key];
    return msg;
} else {
    return null;
}

This checks if the payload is an object, has the ZbReceived property and the right key

Awesome. Thaks for offering me your time and knowledge. Now its working flawless. Great Community.

1 Like

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