I am new to NodeRED. I am trying to create a very simple routine. I am injecting 2 types of RGB values: reading and set RGB values. I am trying to compare the reading RGB values to the actual/expected RGB values and get the difference between where I will then add the difference to the reading values and display the correction made.
For example: if set values are 250,251,252 and reading values are 240,245,242 then after comparing the difference would be 10,6,10 which then will add to the reading values to correct the RGB values to match the set values and display the correction made.
the reading values can be different numbers, but set values will stay the same (think of the set values as in if they are stored in database).
Here is my flow:
[{"id":"7d082d1a.9093f4","type":"inject","z":"350d0535.68069a","name":"Reading_Red ","props":[{"p":"red","v":"240","vt":"num"},{"p":"green","v":"235","vt":"num"},{"p":"blue","v":"245","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":40,"wires":[["cda5c480.719bd8"]]},{"id":"cda5c480.719bd8","type":"function","z":"350d0535.68069a","name":"Reading input ","func":"msg.red = {\"getRed\":msg.payload};\nmsg.green = {\"getGreen\":msg.payload};\nmsg.blue = {\"getBlue\":msg.payload};\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":380,"y":40,"wires":[["e67c519.4adb1b"]]},{"id":"40865fae.d521d","type":"function","z":"350d0535.68069a","name":"Actual_RGB","func":"msg.red1 = {\"getRed1\":msg.payload};\nmsg.green1 = {\"getGreen1\":msg.payload};\nmsg.blue1 = {\"getBlue1\":msg.payload};\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":390,"y":120,"wires":[["e67c519.4adb1b"]]},{"id":"9372e14b.293ac","type":"inject","z":"350d0535.68069a","name":"Expected_Values","props":[{"p":"red1","v":"250","vt":"num"},{"p":"green1","v":"251","vt":"num"},{"p":"blue1","v":"252","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":220,"y":120,"wires":[["40865fae.d521d"]]},{"id":"2e7f2f7b.0712a","type":"function","z":"350d0535.68069a","name":"Comparison ","func":"var rred = context.get(\"rred\");\nvar red_1 = context.get(\"red_1\");\nvar ggreen = context.get(\"ggreen\");\nvar green_1 = context.get(\"green_1\");\nvar bblue = context.get(\"bblue\");\nvar blue_1 = context.get(\"blue_1\");\nvar correction = 0;\n\n// msg.red get the red value then \nif (msg.red(\"getRed\")){\n // rred will be equla to the getRed value\n rred = msg.red.getRed;\n // and it will set the rred to that value\n context.set(\"rred\", rred);\n}\nif (msg.green(\"getGreen\")){\n ggreen = msg.green.getGreen;\n context.set(\"ggreen\", ggreen);\n}\nif (msg.blue(\"getBlue\")){\n bblue = msg.blue.getBlue;\n context.set(\"bblue\", bblue);\n}\n// for the expected value\nif (msg.red1(\"getRed1\")){\n // red_1 will be equal to the getRed1 value\n red_1 = msg.red1.getRed1;\n // and it will set the red_1 to that value\n context.set(\"red_1\", red_1);\n}\nif (msg.green1(\"getGreen1\")){\n green_1 = msg.green1.getGreen1;\n context.set(\"green_1\", green_1);\n}\nif (msg.blue1(\"getBlue1\")){\n blue_1 = msg.blue1.getBlue1;\n context.set(\"blue_1\", blue_1);\n}\n\n// if else to compare\n\nif (rred < red_1){\n correction = getRed1 - getRed;\n msg.red = correction + getRed;\n return msg;\n}\n\nif (ggreen < green_1){\n correction = getGreen1 - getGreen;\n msg.green = correction + getGreen;\n return msg;\n}\nif (bblue < blue_1){\n correction = geBlue1 - getBlue;\n msg.blue = correction + getBlue;\n return msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":730,"y":80,"wires":[["68033f6b.5746"]]},{"id":"68033f6b.5746","type":"debug","z":"350d0535.68069a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":80,"wires":[ ]},{"id":"e67c519.4adb1b","type":"split","z":"350d0535.68069a","name":"","splt":",","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":530,"y":80,"wires":[["2e7f2f7b.0712a"]]}]
Any help would be appreciated because I am super confused.