Ok. I believe I got it. This is how the code looks like for when I want to go backwards on the array. I put a flow.get and flow.set instead of context.set and get so that the 2 function flows can communicate.
Thank you so so much for all your help!!!
// Add an array of arrays
rgbPairs = [[234, 182, 62], [239, 210, 118], [241, 224, 181], [241, 236, 206], [245, 250, 246],
[231, 136, 52], [228, 145, 175], [231, 190, 220], [213, 228, 75], [235, 246, 252],
[230, 115, 70], [217, 51, 123], [201, 132, 187], [168, 214, 43], [220, 240, 247],
[218, 93, 65], [220, 74, 49], [143, 38, 133], [75, 65, 138], [108, 131, 185]];
// define variable that holds current set (array index) (if doesn't exist, make it the lenght of the array)
let rgbindex = flow.get('rgbindex')
if(!rgbindex){
rgbindex = rgbPairs.length
}
// add 1 to the index
rgbindex ++
// if index is > then the lenght of the array, then make index = 1
if(rgbindex > rgbPairs.length){
rgbindex = 1
}
// update the current set with the new value of the index
flow.set('rgbindex',rgbindex);
// substract 1 from index so it is from 0 to index-1
let result = rgbPairs[rgbindex -1];
// create payload to include the new rgb color
msg.payload = {
domain: "light",
service: "turn_on",
data: {
entity_id: "light.lab_color_bulb",
rgb_color: result
}
};
return msg;
[{"id":"e206a6b6.416668","type":"inject","z":"7503cb14.1c6134","name":"color switch right","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"bang","payloadType":"str","x":340,"y":1200,"wires":[["9c611585.784688"]]},{"id":"7dc4784b.6f2608","type":"inject","z":"7503cb14.1c6134","name":"color switch left","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"bang","payloadType":"str","x":340,"y":1140,"wires":[["77e09144.04c91"]]},{"id":"77e09144.04c91","type":"api-current-state","z":"7503cb14.1c6134","name":"Light State","server":"3ed2660b.f6d8ba","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.lab_color_bulb","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":790,"y":1040,"wires":[["77c075dc.9fe4dc","c0678e0b.382d6"]]},{"id":"9c611585.784688","type":"api-current-state","z":"7503cb14.1c6134","name":"Light State","server":"3ed2660b.f6d8ba","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.lab_color_bulb","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":790,"y":1160,"wires":[["290bf86c.154fc8"]]},{"id":"c0678e0b.382d6","type":"function","z":"7503cb14.1c6134","name":"Color Switch Left","func":"\n// Add an array of arrays\nrgbPairs = [[234, 182, 62], [239, 210, 118], [241, 224, 181], [241, 236, 206], [245, 250, 246], \n [231, 136, 52], [228, 145, 175], [231, 190, 220], [213, 228, 75], [235, 246, 252], \n [230, 115, 70], [217, 51, 123], [201, 132, 187], [168, 214, 43], [220, 240, 247],\n [218, 93, 65], [220, 74, 49], [143, 38, 133], [75, 65, 138], [108, 131, 185]];\n\n// define variable that holds current set (array index) (if doesn't exist, make it the lenght of the array) \nlet rgbindex = flow.get('rgbindex')\nif(!rgbindex){\n rgbindex = rgbPairs.length \n}\n\n// substract 1 from the index\nrgbindex --\n// if index is < then 1, then make the lenght of the array\nif(rgbindex < 1){\n rgbindex = rgbPairs.length\n}\n\n// update the current set with the new value of the index\nflow.set('rgbindex',rgbindex);\n\n// substract 1 from index so it is from 0 to index-1\nlet result = rgbPairs[rgbindex -1];\n\n// create payload to include the new rgb color\nmsg.payload = {\n domain: \"light\",\n service: \"turn_on\",\n data: {\n entity_id: \"light.lab_color_bulb\",\n rgb_color: result\n }\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":990,"y":1000,"wires":[["754568a7.1ee2d8","8e4932b4.e3656"]],"info":"// Create an array of arrays\nrgbPairs = [[234, 182, 62], [239, 210, 118], [241, 224, 181]];\n\nvar arrayIndex = 0;\n\nlet result = rgbPairs[arrayIndex];\n\narrayIndex = arrayIndex + 1;\nprocessedArrayIndex = arrayIndex;\n\nmsg.payload = {\n domain: \"light\",\n service: \"turn_on\",\n data: {\n entity_id: \"light.lab_color_bulb\",\n rgb_color:result\n }\n};\nreturn msg;"},{"id":"290bf86c.154fc8","type":"function","z":"7503cb14.1c6134","name":"Color Switch Right","func":"\n// Add an array of arrays\nrgbPairs = [[234, 182, 62], [239, 210, 118], [241, 224, 181], [241, 236, 206], [245, 250, 246], \n [231, 136, 52], [228, 145, 175], [231, 190, 220], [213, 228, 75], [235, 246, 252], \n [230, 115, 70], [217, 51, 123], [201, 132, 187], [168, 214, 43], [220, 240, 247],\n [218, 93, 65], [220, 74, 49], [143, 38, 133], [75, 65, 138], [108, 131, 185]];\n\n// define variable that holds current set (array index) (if doesn't exist, make it the lenght of the array) \nlet rgbindex = flow.get('rgbindex')\nif(!rgbindex){\n rgbindex = rgbPairs.length \n}\n\n// add 1 to the index\nrgbindex ++\n// if index is > then the lenght of the array, then make index = 1\nif(rgbindex > rgbPairs.length){\n rgbindex = 1\n}\n\n// update the current set with the new value of the index\nflow.set('rgbindex',rgbindex);\n\n// substract 1 from index so it is from 0 to index-1\nlet result = rgbPairs[rgbindex -1];\n\n// create payload to include the new rgb color\nmsg.payload = {\n domain: \"light\",\n service: \"turn_on\",\n data: {\n entity_id: \"light.lab_color_bulb\",\n rgb_color: result\n }\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":990,"y":1160,"wires":[["754568a7.1ee2d8","8e4932b4.e3656"]],"info":"min brightness 0\nmax brightness 255\n\nmin color_temp 0 \nmax color_temp 250"},{"id":"8e4932b4.e3656","type":"debug","z":"7503cb14.1c6134","name":"complete","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1420,"y":1040,"wires":[]},{"id":"754568a7.1ee2d8","type":"api-call-service","z":"7503cb14.1c6134","name":"Light Brightness","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1200,"y":1040,"wires":[[]],"info":"{\"brightness\": {{data.attributes.brightness}}}"},{"id":"3ed2660b.f6d8ba","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]