[{"id":"49e56cf3.3c833c","type":"debug","z":"1b5e73a9.1939fc","name":"what we want","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1820,"y":960,"wires":[]},{"id":"b2136b39.e8ad2","type":"inject","z":"1b5e73a9.1939fc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1140,"y":900,"wires":[["83be35b2.6a4a98"]]},{"id":"83be35b2.6a4a98","type":"change","z":"1b5e73a9.1939fc","name":"","rules":[{"t":"set","p":"BathroomMotion","pt":"global","to":"test","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1370,"y":900,"wires":[[]]},{"id":"82c00fc0.32f318","type":"function","z":"1b5e73a9.1939fc","name":"","func":"const key = global.get(\"BathroomMotion\");\nmsg.payload = msg.payload.ZbReceived[key];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1640,"y":960,"wires":[["49e56cf3.3c833c"]]},{"id":"b105c10f.00e18","type":"debug","z":"1b5e73a9.1939fc","name":"jsonata output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1860,"y":1040,"wires":[]},{"id":"b0b83020.838418","type":"change","z":"1b5e73a9.1939fc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$merge(\t [\t $type(payload) = \"object\" ? payload : {},\t {\t \"ZbReceived\":{$globalContext(\"BathroomMotion\"):\"a value\"}\t }\t ]\t)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1660,"y":1040,"wires":[["b105c10f.00e18"]]},{"id":"b75d775.f73cf08","type":"change","z":"1b5e73a9.1939fc","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"set","p":"payload.ZbReceived.test","pt":"msg","to":"this is what we want as the msg.payload","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1320,"y":960,"wires":[["82c00fc0.32f318","b0b83020.838418"]]},{"id":"64b63e60.f389b8","type":"inject","z":"1b5e73a9.1939fc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1140,"y":960,"wires":[["b75d775.f73cf08"]]}]
This is what is wanted i think. And your jsonata @E1cid is not doing it as you see. He only wants to set the key and dont set any values. The purpose is to set msg.payload to the value of that dynamically generated key. Maybe you know a jsonata which has exactly the same end result / function as the function node?