Hello,
I'm a beginner to node red. I'm trying to create subflow and its environment variables. I have problem with extracting value from json payload. The flow is as follow:
[{"id":"9b706329.bc293","type":"subflow","name":"Subflow 1","info":"","category":"","in":[{"x":60,"y":80,"wires":[{"id":"70ccbc5b.6212d4"}]}],"out":[{"x":340,"y":80,"wires":[{"id":"70ccbc5b.6212d4","port":0}]}],"env":[{"name":"msgTopic","type":"str","value":"MBLightTopic"},{"name":"msgValue","type":"env","value":"msg.paylad.MBLight"}],"color":"#DDAA99"},{"id":"70ccbc5b.6212d4","type":"function","z":"9b706329.bc293","name":"MBLight","func":"var msgTopic = env.get(\"msgTopic\");\nvar val_MBLight = msg.payload.MBLight; // <-- How to decleare in Environment Variables\n\nif(msg.topic == msgTopic) { msg.payload = val_MBLight; return msg; }\nelse { return null; } ","outputs":1,"noerr":0,"x":200,"y":80,"wires":[[]]},{"id":"fc8310a7.85ada","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"dd849f09.d85a9","type":"inject","z":"fc8310a7.85ada","name":"","topic":"MBLightTopic","payload":"{\"MBLight\":12}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":220,"wires":[["ef283d9c.701cc"]]},{"id":"ef283d9c.701cc","type":"function","z":"fc8310a7.85ada","name":"MBLight","func":"var msgTopic = \"MBLightTopic\";\nvar val_MBLight = msg.payload.MBLight;\nif(msg.topic == msgTopic) { msg.payload = val_MBLight; return msg; }\nelse { return null; } \n\n","outputs":1,"noerr":0,"x":440,"y":220,"wires":[["e97c1575.5e9718"]]},{"id":"e97c1575.5e9718","type":"debug","z":"fc8310a7.85ada","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":640,"y":220,"wires":[]},{"id":"d1a4c569.e21068","type":"inject","z":"fc8310a7.85ada","name":"","topic":"MBLightTopic","payload":"{\"MBLight\":12}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":380,"wires":[["9b5eba1f.eef108"]]},{"id":"6bfdad95.bf0a64","type":"debug","z":"fc8310a7.85ada","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":640,"y":380,"wires":[]},{"id":"9b5eba1f.eef108","type":"subflow:9b706329.bc293","z":"fc8310a7.85ada","name":"","env":[],"x":440,"y":380,"wires":[["6bfdad95.bf0a64"]]},{"id":"f35567a5.940118","type":"inject","z":"fc8310a7.85ada","name":"","topic":"CRLightTopic","payload":"{\"CRLight\":15}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":180,"wires":[["ef283d9c.701cc"]]},{"id":"af85c38.08a914","type":"inject","z":"fc8310a7.85ada","name":"","topic":"CRLightTopic","payload":"{\"CRLight\":15}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":340,"wires":[["9b5eba1f.eef108"]]}]
How to declare "msg.payload.MBLight" in environment variable of subflow?
Best regards,
Aung