Could you advise me?
I don't understand, i am beginner in node-red.
I created an example. with two flows.
In the first flow I created a global variable "Test".
And in the second flow an "ui_switch" which should to change the status depending on the "Test" variable from first flow. And I don't understand how to implement this!
Code the Flow1
[{"id":"88a65a8f.890828","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"693af34c.97d5ac","type":"inject","z":"88a65a8f.890828","name":"On","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"On","payloadType":"str","x":280,"y":120,"wires":[["2b8a9837.f976d8"]]},{"id":"5922f3d9.eac7ac","type":"inject","z":"88a65a8f.890828","name":"Off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Off","payloadType":"str","x":280,"y":180,"wires":[["2b8a9837.f976d8"]]},{"id":"2b8a9837.f976d8","type":"function","z":"88a65a8f.890828","name":"","func":"\nvar Test = global.get('Test') || \"\"; \n\nif (msg.payload === \"On\") {\n global.set('Test',\"ON\");\n return [ msg ];\n} \nelse { \n global.set('Test',\"OFF\");\n return [ msg ]; \n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":160,"wires":[["405e2492.3037fc"]]},{"id":"405e2492.3037fc","type":"debug","z":"88a65a8f.890828","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":160,"wires":[]},{"id":"de74ac53.99303","type":"debug","z":"88a65a8f.890828","name":"TEST","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":260,"wires":[]},{"id":"a78bd8bc.00d7a8","type":"function","z":"88a65a8f.890828","name":"Check Test","func":"var Test = global.get('Test') || \"\"; \n\nif (msg.payload === 1 && Test != \"1\") {\n msg.payload=Test;\n return [ msg ];\n} \nelse { return [ null ]; \n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":470,"y":260,"wires":[["de74ac53.99303"]]},{"id":"e5345f39.b0f9a","type":"inject","z":"88a65a8f.890828","name":"","props":[{"p":"payload"},{"p":"topi","v":"","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":270,"y":260,"wires":[["a78bd8bc.00d7a8"]]}]
Code the Flow2
[{"id":"32f04248.f9f5ae","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"6cc2f6b3.63dbc8","type":"function","z":"32f04248.f9f5ae","name":"","func":"var Test = global.get('Test'); \n\nif (msg.payload === \"On\") {\n global.set('Test',\"ON\");\n return [ msg ];\n} \nelse { \n global.set('Test',\"OFF\");\n return [ msg ]; \n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":120,"wires":[["974f73a2.7a89b","7c508c9a.a1b584"]]},{"id":"974f73a2.7a89b","type":"change","z":"32f04248.f9f5ae","name":"Enable","rules":[{"t":"set","p":"enabled","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":60,"wires":[["a27fde93.1e289"]]},{"id":"7c508c9a.a1b584","type":"change","z":"32f04248.f9f5ae","name":"Disable","rules":[{"t":"set","p":"enabled","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":180,"wires":[["a27fde93.1e289"]]},{"id":"a27fde93.1e289","type":"ui_switch","z":"32f04248.f9f5ae","name":"","label":"Test","tooltip":"","group":"45b1bd44.270cf4","order":3,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"{\"state\":\"ON\"}","onvalueType":"json","onicon":"fa-lightbulb-o fa-3x","oncolor":"red","offvalue":"{\"state\":\"OFF\"}","offvalueType":"json","officon":"fa-lightbulb-o fa-3x","offcolor":"gray","x":690,"y":120,"wires":[[]]},{"id":"45b1bd44.270cf4","type":"ui_group","z":"","name":"A1","tab":"181108e9.fe4277","order":1,"disp":true,"width":"6","collapse":false},{"id":"181108e9.fe4277","type":"ui_tab","z":"","name":"TEST","icon":"dashboard","order":1,"disabled":false,"hidden":false}]