Send array into a call service node?

Hey there!

I am trying to input an array onto a call service Data as I would like to change an rgb color. I was advised to use {“brightness”: {{data.attributes.brightness}}} to interactively change brightness values. And it works. Whenever I send a message formated like this msg.data.attributes.brightness the brightness changes

What about changing rgb_color with has 3 values?

I tried { “rgb_color”: {{data.attributes.rgb_color}}} and also {“rgb_color”: {{data.attributes.rgb_color[0,1,2]}}}. They don’t seem to work.

This is the code I am using for testing:

[{"id":"7dc4784b.6f2608","type":"inject","z":"7503cb14.1c6134","name":"color temp up","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"bang","payloadType":"str","x":330,"y":800,"wires":[["301221b9.b1bf8e"]]},{"id":"301221b9.b1bf8e","type":"api-call-service","z":"7503cb14.1c6134","name":"Turn ON Light","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lab_color_bulb","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":600,"y":760,"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":760,"wires":[["6b744a99.331bb4","500f6918.995108"]]},{"id":"6b744a99.331bb4","type":"function","z":"7503cb14.1c6134","name":"Color Switch Left","func":"// Get the actual color\nvar colors = new Array (254, 0, 0); \nmsg.data.attributes.rgb_color =  colors;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":990,"y":760,"wires":[["a7d9acbd.764e5","baeb31ae.01244","754568a7.1ee2d8"]],"info":"min brightness 0\nmax brightness 255\n\nmin color_temp 0 \nmax color_temp 250"},{"id":"754568a7.1ee2d8","type":"api-call-service","z":"7503cb14.1c6134","name":"Light Brightness","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lab_color_bulb","data":"{ \"rgb_color\": {{data.attributes.rgb_color}}}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1400,"y":740,"wires":[[]],"info":"{\"brightness\": {{data.attributes.brightness}}}"},{"id":"122f5e5a.528e42","type":"inject","z":"7503cb14.1c6134","name":"brightness up","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"bang","payloadType":"str","x":350,"y":480,"wires":[["b09c6110.5bd75"]]},{"id":"b09c6110.5bd75","type":"api-call-service","z":"7503cb14.1c6134","name":"Turn ON Light","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lab_color_bulb","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":600,"y":360,"wires":[["392c2534.62f7aa"]]},{"id":"392c2534.62f7aa","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":360,"wires":[["c5594516.62d738"]]},{"id":"c5594516.62d738","type":"function","z":"7503cb14.1c6134","name":"Brightness up","func":"// add actual brightness value\nvar brightness =  msg.data.attributes.brightness;\n\nbrightness = brightness + 15;\n \n\nif(brightness >= 255){\n   brightness = 254;\n    }\n        \nif(brightness < 0){\n   brightness = 0;\n\t} \n    \nmsg.data.attributes.brightness = brightness\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":980,"y":360,"wires":[["c3ceaec4.05648","e3c3e7aa.84efd8"]],"info":"min brightness 0\nmax brightness 255\n\nmin color_temp 0 \nmax color_temp 250"},{"id":"c3ceaec4.05648","type":"api-call-service","z":"7503cb14.1c6134","name":"Light Brightness","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lab_color_bulb","data":"{            \"brightness\": {{data.attributes.brightness}},           \"rgb_color\": {{data.attributes.rgb_color}}    }","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1260,"y":360,"wires":[["872dfdd2.ac1e8"]],"info":"{\"brightness\": {{data.attributes.brightness}}}"},{"id":"872dfdd2.ac1e8","type":"debug","z":"7503cb14.1c6134","name":"light brightness","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1460,"y":360,"wires":[]},{"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}]

And this is the js code from the function node used to send data

var colors = new Array (254, 0, 0); 
msg.data.attributes.rgb_color =  colors;
return msg;

Any suggestions?
Thank you so much!

brightness

if it’s any help, this is how my json looks to set the brightness and color name.

{
    "entity_id": "light.67704348b4e62d791631",
    "color_name": "red",
    "brightness": 120
}

I don’t know for sure whether you can pass an array, but I just break out parts of the array. Here’s an example of a change node I’m using with the H_S color array:

Are you using zigbee2mqtt nodes or are you also using a call service node for the light?

In case of the 2nd option, did you input anything into Data like I did?

I don’t know how to use this information :frowning:

This is only a call service node.
I have that as the json of the node.
I use color name instead of rgb. But the principle should be the same

I have another automation that uses hs_color but that is done in normal automation.

1 Like

If you inject JSON into a call service node and leave the call service data field blank, the call service node will parse the JSON as the service call parameters. Injecting the JSON below into a call service node works to turn on my LIFX lights:
image

1 Like

It might be helpful if you describe what you are trying to do with your example flow.

  • You have an inject node into a call service node, which will call the service listed.
  • You then have a current state node which may be redundant. The output of the call service node will have the parameters from the service call which will have all the information the current state node would give you.
  • It looks like you’re trying to set new light service call parameters in the function node? If so, it may work better to pass the entire service call data. This works in a function node with a blank service call connected to the function output:
var service_data = {
    "power": "true",
    "rgb_color": [
        "254",
        "0",
        "0"
    ],
    "brightness": "127",
    "infrared": 255,
    "entity_id": "light.front_yard_south"
}
return service_data;

You can replace any of the static values with mustache templates to reference properties from the call service or current state nodes.

I am trying to replicate how an Ikea remote and an Ikea color light bulb communicate via the Ikea Tradfri Bridge

This is what I got so far. If I push the middle button I get to toggle on/off the light bulb. If I short press the upper button, I get to move the brightness up 15 points on each press and if I long press, I get to move the brightness up continuously until I stop pressing. The opposite for the lower button.

Now for the left and right button, I checked the Ikea Tradfri app while pushing the buttons and it seems there are 20 color presets that I randomly cycle through whenever I press the left or right button. Of course if I press left once and then right once, I should be going back to the same color.

Now I was trying to figure out how to send the list of rgb values into a call service node. And you helped me with that (Hurray!!!), but I would want to figure out how to do the rest (make an array of arrays, cycle through it randomly (if possible, but not necessary), go back to the last color used (also if possible), and then send it to the call service for the color light bulb. :smiley:

These are the first 3 pairs as starters

234, 182, 62
239, 210, 118
241, 224, 181

I will try to use the info gave to see where it’s gonna take me ;))

[{"id":"5d7be55b.f6039c","type":"server-events","z":"7503cb14.1c6134","name":"","server":"3ed2660b.f6d8ba","event_type":"zha_event","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"x":310,"y":360,"wires":[["40f182d9.20278c"]]},{"id":"40f182d9.20278c","type":"switch","z":"7503cb14.1c6134","name":"Remote Commands","property":"payload.event.command","propertyType":"msg","rules":[{"t":"eq","v":"toggle","vt":"str"},{"t":"eq","v":"step_with_on_off","vt":"str"},{"t":"eq","v":"step","vt":"str"},{"t":"eq","v":"move_with_on_off","vt":"str"},{"t":"eq","v":"move","vt":"str"},{"t":"eq","v":"stop","vt":"str"},{"t":"eq","v":"press","vt":"str"},{"t":"eq","v":"hold","vt":"str"},{"t":"eq","v":"release","vt":"str"},{"t":"eq","v":"move_to_level_with_on_off","vt":"str"}],"checkall":"true","repair":false,"outputs":10,"x":320,"y":520,"wires":[["e12ab7d0.f3ebc8"],["b09c6110.5bd75"],["bfb6151c.7b4478"],["7a567951.447498","5676108d.f0dfd"],["bcf002be.218b3","5ef6a19f.a5bf9"],["3fbcd8d.43d8d28","ca7965f.8711b98"],["2b9a28b8.a5d628"],["636227e2.7d1ea8"],["3db29909.5835f6","8b943136.803fb"],[]],"info":"Normal presses\n\n1 Middle - toggle\n2 Up - step_with_on_off\n3 Down - step\n4 Left - press (args: 257, 13, 0)\nRight - press (args: 256, 13, 0)\n\n\nLong presses\n\n5, 6 Middle - toggle, then release then move_to_level_with_on_off, then press (arg 2, 0, 0)\n\n7 Up - move_with_on_off and then stop (when unpressing the button)\n\n8, 9 Down - move and then stop (when unpressing the button)\n\n10 Left - hold (args: 3329, 0) and then release (arg: 3742)\n\nRight - hold (args: 3328, 0) and then release (arg: 2696)\n\n\n\n\n1 toggle\n2 step_with_on_off\n3 step\n7 move_with_on_off\n8 move\n9 stop\n4 press\n10 hold\n5 release\n6 move_to_level_with_on_off\n\n"},{"id":"416c3892.19a9f8","type":"inject","z":"7503cb14.1c6134","name":"on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":370,"y":660,"wires":[["8b53bc2a.fb39f"]]},{"id":"a736255f.2d2278","type":"inject","z":"7503cb14.1c6134","name":"off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":370,"y":700,"wires":[["2bf65be1.e30844"]]},{"id":"8b53bc2a.fb39f","type":"api-call-service","z":"7503cb14.1c6134","name":"Turn ON Light","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lab_color_bulb","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1260,"y":520,"wires":[["f144fb51.2307d8"]]},{"id":"2bf65be1.e30844","type":"api-call-service","z":"7503cb14.1c6134","name":"Turn OFF Light","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.lab_color_bulb","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1260,"y":580,"wires":[["f144fb51.2307d8"]]},{"id":"c5594516.62d738","type":"function","z":"7503cb14.1c6134","name":"Brightness up","func":"// add actual brightness value\nvar brightness =  msg.data.attributes.brightness;\n\nbrightness = brightness + 15;\n \n\nif(brightness >= 255){\n   brightness = 254;\n    }\n        \nif(brightness < 0){\n   brightness = 0;\n\t} \n    \nmsg.data.attributes.brightness = brightness\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":980,"y":640,"wires":[["c3ceaec4.05648"]],"info":"min brightness 0\nmax brightness 255\n\nmin color_temp 0 \nmax color_temp 250"},{"id":"392c2534.62f7aa","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":640,"wires":[["c5594516.62d738"]]},{"id":"5f79d746.ba18c8","type":"function","z":"7503cb14.1c6134","name":"Brightness down","func":"// add actual brightness value\nvar brightness =  msg.data.attributes.brightness;\n\nbrightness = brightness - 15;\n \n\nif(brightness >= 255){\n   brightness = 254;\n    }\n        \nif(brightness < 1){\n   brightness = 1;\n\t} \n    \nmsg.data.attributes.brightness = brightness\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1000,"y":700,"wires":[["c3ceaec4.05648"]],"info":"min brightness 0\nmax brightness 255\n\nmin color_temp 0 \nmax color_temp 250"},{"id":"fd53b136.0f8d4","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":700,"wires":[["5f79d746.ba18c8"]]},{"id":"c3ceaec4.05648","type":"api-call-service","z":"7503cb14.1c6134","name":"Light Brightness","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lab_color_bulb","data":"{            \"brightness\": {{data.attributes.brightness}},           \"rgb_color\": {{data.attributes.rgb_color}}    }","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1260,"y":640,"wires":[["872dfdd2.ac1e8"]],"info":"{\"brightness\": {{data.attributes.brightness}}}"},{"id":"122f5e5a.528e42","type":"inject","z":"7503cb14.1c6134","name":"brightness up","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"bang","payloadType":"str","x":350,"y":760,"wires":[["b09c6110.5bd75"]]},{"id":"7befef54.a0fe8","type":"inject","z":"7503cb14.1c6134","name":"brightness down","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"bang","payloadType":"str","x":340,"y":800,"wires":[["bfb6151c.7b4478"]]},{"id":"e959ed01.4977f","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":780,"wires":[["b732e44b.522c08"]]},{"id":"b732e44b.522c08","type":"function","z":"7503cb14.1c6134","name":"Brightness up (continous)","func":"// add actual brightness value\nvar brightness =  msg.data.attributes.brightness;\n\nbrightness = brightness + 15;\n \n\nif(brightness >= 255){\n   brightness = 254;\n    }\n        \nif(brightness < 0){\n   brightness = 0;\n\t} \n    \nmsg.data.attributes.brightness = brightness\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1010,"y":780,"wires":[["c3ceaec4.05648","b9b9e9cf.ebe548"]],"info":"min brightness 0\nmax brightness 255\n\nmin color_temp 0 \nmax color_temp 250"},{"id":"b9b9e9cf.ebe548","type":"delay","z":"7503cb14.1c6134","name":"","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1270,"y":780,"wires":[["7c61ace6.58ea64"]]},{"id":"7c61ace6.58ea64","type":"gate","z":"7503cb14.1c6134","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":1450,"y":780,"wires":[["e959ed01.4977f"]]},{"id":"3fbcd8d.43d8d28","type":"change","z":"7503cb14.1c6134","name":"close","rules":[{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1290,"y":700,"wires":[["7c61ace6.58ea64"]]},{"id":"52cf825b.58ea6c","type":"inject","z":"7503cb14.1c6134","name":"open","props":[{"p":"payload","v":"open","vt":"str"},{"p":"topic","v":"control","vt":"string"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"open","payloadType":"str","x":1450,"y":700,"wires":[["7c61ace6.58ea64"]]},{"id":"80c6f7a4.645af8","type":"inject","z":"7503cb14.1c6134","name":"close","props":[{"p":"payload","v":"close","vt":"str"},{"p":"topic","v":"control","vt":"string"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"close","payloadType":"str","x":1450,"y":740,"wires":[["7c61ace6.58ea64"]]},{"id":"7a567951.447498","type":"change","z":"7503cb14.1c6134","name":"open","rules":[{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1290,"y":740,"wires":[["7c61ace6.58ea64"]]},{"id":"b0d76094.de4f","type":"inject","z":"7503cb14.1c6134","name":"brightness up (cont.)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"bang","payloadType":"str","x":330,"y":900,"wires":[["7a567951.447498","5676108d.f0dfd"]]},{"id":"dee30c28.e5fdf","type":"inject","z":"7503cb14.1c6134","name":"brightness stop","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"bang","payloadType":"str","x":340,"y":860,"wires":[["3fbcd8d.43d8d28","ca7965f.8711b98"]]},{"id":"872dfdd2.ac1e8","type":"debug","z":"7503cb14.1c6134","name":"light brightness","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1460,"y":640,"wires":[]},{"id":"f144fb51.2307d8","type":"debug","z":"7503cb14.1c6134","name":"light on/off","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1450,"y":520,"wires":[]},{"id":"6cc68035.f2b4f","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":920,"wires":[["641611f3.c4328"]]},{"id":"641611f3.c4328","type":"function","z":"7503cb14.1c6134","name":"Brightness down (continous)","func":"// add actual brightness value\nvar brightness =  msg.data.attributes.brightness;\n\nbrightness = brightness - 15;\n \n\nif(brightness >= 255){\n   brightness = 254;\n    }\n        \nif(brightness < 0){\n   brightness = 0;\n\t} \n    \nmsg.data.attributes.brightness = brightness\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1000,"y":920,"wires":[["d28c63b4.e75fa","c3ceaec4.05648"]],"info":"min brightness 0\nmax brightness 255\n\nmin color_temp 0 \nmax color_temp 250"},{"id":"d28c63b4.e75fa","type":"delay","z":"7503cb14.1c6134","name":"","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1270,"y":920,"wires":[["f162388f.fec128"]]},{"id":"f162388f.fec128","type":"gate","z":"7503cb14.1c6134","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":1450,"y":920,"wires":[["6cc68035.f2b4f"]]},{"id":"ca7965f.8711b98","type":"change","z":"7503cb14.1c6134","name":"close","rules":[{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1290,"y":840,"wires":[["f162388f.fec128"]]},{"id":"1b89e3cd.7cde0c","type":"inject","z":"7503cb14.1c6134","name":"open","props":[{"p":"payload","v":"open","vt":"str"},{"p":"topic","v":"control","vt":"string"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"open","payloadType":"str","x":1450,"y":840,"wires":[["f162388f.fec128"]]},{"id":"f996addd.7811","type":"inject","z":"7503cb14.1c6134","name":"close","props":[{"p":"payload","v":"close","vt":"str"},{"p":"topic","v":"control","vt":"string"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"close","payloadType":"str","x":1450,"y":880,"wires":[["f162388f.fec128"]]},{"id":"bcf002be.218b3","type":"change","z":"7503cb14.1c6134","name":"open","rules":[{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1290,"y":880,"wires":[["f162388f.fec128"]]},{"id":"2bc0dcde.20e164","type":"inject","z":"7503cb14.1c6134","name":"brightness down (cont.)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"bang","payloadType":"str","x":320,"y":940,"wires":[["bcf002be.218b3","5ef6a19f.a5bf9"]]},{"id":"b5620a4d.3ea0c8","type":"comment","z":"7503cb14.1c6134","name":"Brightness","info":"","x":580,"y":580,"wires":[]},{"id":"b09c6110.5bd75","type":"api-call-service","z":"7503cb14.1c6134","name":"Turn ON Light","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lab_color_bulb","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":600,"y":640,"wires":[["392c2534.62f7aa"]]},{"id":"bfb6151c.7b4478","type":"api-call-service","z":"7503cb14.1c6134","name":"Turn ON Light","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lab_color_bulb","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":600,"y":700,"wires":[["fd53b136.0f8d4"]]},{"id":"5676108d.f0dfd","type":"api-call-service","z":"7503cb14.1c6134","name":"Turn ON Light","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lab_color_bulb","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":600,"y":780,"wires":[["e959ed01.4977f"]]},{"id":"5ef6a19f.a5bf9","type":"api-call-service","z":"7503cb14.1c6134","name":"Turn ON Light","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lab_color_bulb","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":600,"y":920,"wires":[["6cc68035.f2b4f"]]},{"id":"e12ab7d0.f3ebc8","type":"api-call-service","z":"7503cb14.1c6134","name":"Light Toggle","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"light","service":"toggle","entityId":"light.lab_color_bulb","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1250,"y":460,"wires":[["1572e956.47cea7"]]},{"id":"1572e956.47cea7","type":"debug","z":"7503cb14.1c6134","name":"light toggle","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1450,"y":460,"wires":[]},{"id":"6991393c.28a9e8","type":"inject","z":"7503cb14.1c6134","name":"light toggle","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"bang","payloadType":"str","x":360,"y":620,"wires":[["e12ab7d0.f3ebc8"]]},{"id":"6b744a99.331bb4","type":"function","z":"7503cb14.1c6134","name":"Color Switch Left","func":"msg.payload = {\n domain: \"light\",\n service: \"turn_on\",\n data: {\n entity_id: \"light.lab_color_bulb\",\n rgb_color: msg.data.attributes.rgb_color\n }\n};\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":990,"y":1040,"wires":[["754568a7.1ee2d8"]],"info":"min brightness 0\nmax brightness 255\n\nmin color_temp 0 \nmax color_temp 250"},{"id":"290bf86c.154fc8","type":"function","z":"7503cb14.1c6134","name":"Color Switch Right","func":"\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":990,"y":1160,"wires":[["754568a7.1ee2d8"]],"info":"min brightness 0\nmax brightness 255\n\nmin color_temp 0 \nmax color_temp 250"},{"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":"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":[["301221b9.b1bf8e"]]},{"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":[["2f0e3533.aa549a"]]},{"id":"2f0e3533.aa549a","type":"api-call-service","z":"7503cb14.1c6134","name":"Turn ON Light","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lab_color_bulb","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":600,"y":1160,"wires":[["9c611585.784688"]]},{"id":"ceb52def.1c308","type":"comment","z":"7503cb14.1c6134","name":"Color Switch","info":"Ikea Tradfri Bridge and App offer the possibility to switch between a set of colors. So we replicate that here.\n\nThis is the list of the 20 RGB values pairs","x":590,"y":980,"wires":[]},{"id":"84a95494.728308","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":1240,"wires":[["95bf648d.3d3bf8"]]},{"id":"95bf648d.3d3bf8","type":"function","z":"7503cb14.1c6134","name":"Color Switch Left (continous)","func":"\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1020,"y":1240,"wires":[["ebcd13f5.ca897","754568a7.1ee2d8"]],"info":"min brightness 0\nmax brightness 255\n\nmin color_temp 0 \nmax color_temp 250"},{"id":"ebcd13f5.ca897","type":"delay","z":"7503cb14.1c6134","name":"","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1270,"y":1240,"wires":[["52352259.3c9f1c"]]},{"id":"52352259.3c9f1c","type":"gate","z":"7503cb14.1c6134","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":1450,"y":1240,"wires":[["84a95494.728308"]]},{"id":"3db29909.5835f6","type":"change","z":"7503cb14.1c6134","name":"close","rules":[{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1290,"y":1160,"wires":[["52352259.3c9f1c"]]},{"id":"10f966ff.ecdb59","type":"inject","z":"7503cb14.1c6134","name":"open","props":[{"p":"payload","v":"open","vt":"str"},{"p":"topic","v":"control","vt":"string"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"open","payloadType":"str","x":1450,"y":1160,"wires":[["52352259.3c9f1c"]]},{"id":"a81ce50.89cc618","type":"inject","z":"7503cb14.1c6134","name":"close","props":[{"p":"payload","v":"close","vt":"str"},{"p":"topic","v":"control","vt":"string"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"close","payloadType":"str","x":1450,"y":1200,"wires":[["52352259.3c9f1c"]]},{"id":"7714f2db.6199ac","type":"change","z":"7503cb14.1c6134","name":"open","rules":[{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1290,"y":1200,"wires":[["52352259.3c9f1c"]]},{"id":"1699fcd7.036323","type":"inject","z":"7503cb14.1c6134","name":"color switch left (cont.)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"bang","payloadType":"str","x":320,"y":1300,"wires":[["7714f2db.6199ac","962699a1.9df568"]]},{"id":"d4b09b6a.a69aa8","type":"inject","z":"7503cb14.1c6134","name":"color switch stop","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"bang","payloadType":"str","x":340,"y":1260,"wires":[["8b943136.803fb","3db29909.5835f6"]]},{"id":"1b1aa9b3.4c43a6","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":1380,"wires":[["ea67884b.b152f8"]]},{"id":"ea67884b.b152f8","type":"function","z":"7503cb14.1c6134","name":"Color Switch Right (continous)","func":"\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1010,"y":1380,"wires":[["45f78569.cfc09c","754568a7.1ee2d8"]],"info":"min brightness 0\nmax brightness 255\n\nmin color_temp 0 \nmax color_temp 250"},{"id":"45f78569.cfc09c","type":"delay","z":"7503cb14.1c6134","name":"","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1270,"y":1380,"wires":[["556655f6.96b7bc"]]},{"id":"556655f6.96b7bc","type":"gate","z":"7503cb14.1c6134","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":1450,"y":1380,"wires":[["1b1aa9b3.4c43a6"]]},{"id":"8b943136.803fb","type":"change","z":"7503cb14.1c6134","name":"close","rules":[{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1290,"y":1300,"wires":[["556655f6.96b7bc"]]},{"id":"7dca0d46.f243a4","type":"inject","z":"7503cb14.1c6134","name":"open","props":[{"p":"payload","v":"open","vt":"str"},{"p":"topic","v":"control","vt":"string"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"open","payloadType":"str","x":1450,"y":1300,"wires":[["556655f6.96b7bc"]]},{"id":"13ebf9cc.579116","type":"inject","z":"7503cb14.1c6134","name":"close","props":[{"p":"payload","v":"close","vt":"str"},{"p":"topic","v":"control","vt":"string"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"control","payload":"close","payloadType":"str","x":1450,"y":1340,"wires":[["556655f6.96b7bc"]]},{"id":"348462b6.16bdee","type":"change","z":"7503cb14.1c6134","name":"open","rules":[{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1290,"y":1340,"wires":[["556655f6.96b7bc"]]},{"id":"25746a05.125116","type":"inject","z":"7503cb14.1c6134","name":"color switch right (cont.)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"bang","payloadType":"str","x":320,"y":1340,"wires":[["348462b6.16bdee","f805bf5.cd4c64"]]},{"id":"962699a1.9df568","type":"api-call-service","z":"7503cb14.1c6134","name":"Turn ON Light","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lab_color_bulb","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":600,"y":1240,"wires":[["84a95494.728308"]]},{"id":"f805bf5.cd4c64","type":"api-call-service","z":"7503cb14.1c6134","name":"Turn ON Light","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lab_color_bulb","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":600,"y":1380,"wires":[["1b1aa9b3.4c43a6"]]},{"id":"2b9a28b8.a5d628","type":"switch","z":"7503cb14.1c6134","name":"Remote Commands","property":"payload.event.args[0]","propertyType":"msg","rules":[{"t":"eq","v":"257","vt":"str"},{"t":"eq","v":"256","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":320,"y":1020,"wires":[["301221b9.b1bf8e"],["2f0e3533.aa549a"]],"info":"Normal presses\n\n1 Middle - toggle\n2 Up - step_with_on_off\n3 Down - step\n4 Left - press (args: 257, 13, 0)\nRight - press (args: 256, 13, 0)\n\n\nLong presses\n\n5, 6 Middle - toggle, then release then move_to_level_with_on_off, then press (arg 2, 0, 0)\n\n7 Up - move_with_on_off and then stop (when unpressing the button)\n\n8, 9 Down - move and then stop (when unpressing the button)\n\n10 Left - hold (args: 3329, 0) and then release (arg: 3742)\n\nRight - hold (args: 3328, 0) and then release (arg: 2696)\n\n\n\n\n1 toggle\n2 step_with_on_off\n3 step\n4 press\n5 release\n6 move_to_level_with_on_off\n7 move_with_on_off\n8 move\n9 stop\n10 hold\n"},{"id":"636227e2.7d1ea8","type":"switch","z":"7503cb14.1c6134","name":"Remote Commands","property":"payload.event.command.args","propertyType":"msg","rules":[{"t":"eq","v":"3329","vt":"str"},{"t":"eq","v":"3328","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":300,"y":1400,"wires":[["962699a1.9df568"],["f805bf5.cd4c64"]],"info":"Normal presses\n\n1 Middle - toggle\n2 Up - step_with_on_off\n3 Down - step\n4 Left - press (args: 257, 13, 0)\nRight - press (args: 256, 13, 0)\n\n\nLong presses\n\n5, 6 Middle - toggle, then release then move_to_level_with_on_off, then press (arg 2, 0, 0)\n\n7 Up - move_with_on_off and then stop (when unpressing the button)\n\n8, 9 Down - move and then stop (when unpressing the button)\n\n10 Left - hold (args: 3329, 0) and then release (arg: 3742)\n\nRight - hold (args: 3328, 0) and then release (arg: 2696)\n\n\n\n\n1 toggle\n2 step_with_on_off\n3 step\n4 press\n5 release\n6 move_to_level_with_on_off\n7 move_with_on_off\n8 move\n9 stop\n10 hold\n"},{"id":"301221b9.b1bf8e","type":"api-call-service","z":"7503cb14.1c6134","name":"Turn ON Light","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lab_color_bulb","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":600,"y":1040,"wires":[["77e09144.04c91"]]},{"id":"e842f2b4.64dd8","type":"comment","z":"7503cb14.1c6134","name":"Remote for lab color bulb","info":"","x":330,"y":420,"wires":[]},{"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":[["6b744a99.331bb4"]]},{"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}]

119768992_10159308890505961_6891577429410263801_n

Array of arrays is a multidimensional array.
In a function node it’s probably just:

var arr = [
[234, 182, 62],
[239, 210, 118],
[241, 224, 181]
];

and you can access the arrays with arr[0] as an example.
I suggest using a flow variable as the “0” that way it will be preserved and you can go to “1” and back to “0” if you want.

You will need to store the array of colours somewhere else. Commonly this is done with a flow variable that gets set by an inject node set to run when NR starts. Then you could use another flow variable to store the current array index. When you pick the next colour, you increment the current array index and save it back to the flow.

For this to work as expected across restarts, you would have to use persistent context in settings.js as described here.

And wow, that flow is difficult to follow. Link-out and link-in might help tidy it up.

As others have also said, using variables in Node Red might be very helpful. My only comment on NR variables is that they you have to create a persistent context store before you can store variables in a way that survives a Node Red restart. After doing that, you can specify which context store will store the variable. I have been unable to reference persistent context stores using mustache templates in call service nodes, but maybe I’m doing something wrong. Regardless, variables help a ton.

Thank you all, @strikeir13, @michaelblight and @Hellis81!

With your advice and with the help of a great guy on the Node-RED forum, I finally got this working. For sure I have to understand how context works as I don’t understand everything that is going on here yet. :slight_smile:

I am trying to figure out how to switch this list. Meaning I should go through this list if I press the right button, but I should go backwards if I press the left button.


// 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]];

//            
let rgbindex = context.get('rgbindex')
if(!rgbindex){
    rgbindex = rgbPairs.length 
}

rgbindex ++
if(rgbindex > rgbPairs.length){
    rgbindex = 1
}

context.set('rgbindex',rgbindex);

let result = rgbPairs[rgbindex -1];

msg.payload = {
 domain: "light",
 service: "turn_on",
 data: {
 entity_id: "light.lab_color_bulb",
 rgb_color: result
 }
};
return msg;

This is the flow:

[{"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":"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//            \nlet rgbindex = context.get('rgbindex')\nif(!rgbindex){\n    rgbindex = rgbPairs.length \n}\n\nrgbindex ++\nif(rgbindex > rgbPairs.length){\n    rgbindex = 1\n}\n\ncontext.set('rgbindex',rgbindex);\n\nlet result = rgbPairs[rgbindex -1];\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;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":990,"y":1160,"wires":[["754568a7.1ee2d8"]],"info":"min brightness 0\nmax brightness 255\n\nmin color_temp 0 \nmax color_temp 250"},{"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":"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//            \nlet rgbindex = context.get('rgbindex')\nif(!rgbindex){\n    rgbindex = rgbPairs.length \n}\n\nrgbindex ++\nif(rgbindex > rgbPairs.length){\n    rgbindex = 1\n}\n\ncontext.set('rgbindex',rgbindex);\n\nlet result = rgbPairs[rgbindex -1];\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;","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":"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":"301221b9.b1bf8e","type":"api-call-service","z":"7503cb14.1c6134","name":"Turn ON Light","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lab_color_bulb","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":600,"y":1040,"wires":[["77e09144.04c91"]]},{"id":"2f0e3533.aa549a","type":"api-call-service","z":"7503cb14.1c6134","name":"Turn ON Light","server":"3ed2660b.f6d8ba","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.lab_color_bulb","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":600,"y":1160,"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":[["301221b9.b1bf8e"]]},{"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":[["2f0e3533.aa549a"]]},{"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}]

This is the end solution. Thank you all!!

[{"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}]

Very nice! If you end up with multiple bulbs you want to control like this, you could use the trigger state node with a substring to capture all changes from those particular lights and change the hardcoded entity id in the function node to use a mustache template referencing the entity id for the light that triggered the flow.

Glad you got it working!

2 Likes

I realize this is an old thread, but I would be really interested in figuring out how to eliminate the hard coding for scalability!

What exactly do you want.
It’s better if you post what you have and what you need in a new thread.