# Adding values but more like \`AND\` than \`+\`

**URL:** <https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723>\
**Category:** General\
**Created:** [4 December 2021 22:47 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723 "2021-12-04T22:47:16Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [4 December 2021 22:47 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/1 "2021-12-04T22:47:16Z")

</div>

This is a recent thing I got working. Thanks to all who helped me with the syntax error I made.

The _problem_ now is it is _a bit too good_ at doing what I want it to do.

The idea is the `R` `G` and `B` values may be used for different things and so if the LED is showing a RED event and a BLUE event comes in, it becomes RED **AND** BLUE.

The problem is that if another RED value comes in: the RED value is added.  
This can quickly go over the allowed 255 for maximum value.

I would prefer if the values were _anded_ together.

So the existing RED value is anded. So if the value hasn't changed, the RED value won't change.

Given that all the events that use RED are the same value.

Code:

```auto
if (msg.debug != undefined)
{
    context.set("DEBUG",msg.debug);
    node.warn("Debug set to " + msg.debug);
    return;
}

let debug = context.get("DEBUG") || 0;

// Get LED number from `payload`
//let led = parseInt(msg.payload.split(",")[1]);
let payload = msg.payload
let blah = payload.split(",")[1];

let led = parseInt(blah);
if (debug == 1)
    node.warn("LED " + led);

if (led > 4)
{
    if (debug == 1)
        node.warn("LED Colour adjustment happening");
    // Get RGB values from `payload`
    let n_red = parseInt(payload.split(",")[2])
    let n_green = parseInt(payload.split(",")[3])
    let n_blue = parseInt(payload.split(",")[4])
    if (debug == 1)
    {
        node.warn("==== New values below ====");
        node.warn("R " + n_red + " G " + n_green + " B " + n_blue);
    }

    let existing_value = msg.existing[led];
    // Now get existing RGB values.
    if (existing_value == undefined)
    {
        existing_value = "0,0,0";
    }
    let x_red = parseInt(existing_value.split(",")[0]);
    let x_green = parseInt(existing_value.split(",")[1]);
    let x_blue = parseInt(existing_value.split(",")[2]);
    
    if (debug == 1)
    {
        node.warn("---- Exiting values below ----");
        node.warn("R " + x_red + " G " + x_green + " B " + x_blue);
    }

    let red = n_red + x_red;
    let green = n_green + x_green;
    let blue = n_blue + x_blue;
    
    msg.payload = "rgb," + led + "," + red + "," + green + "," + blue
}

//if (msg.payload.who == "All clear") // Old code
if (msg.wipe == "WIPE")
{
    //
    // Wipe the alarm LEDs
    //
    // work needed
    msg.payload = "rgb," + led + ",0,0,0";

}
if (msg.clear == "CLEAR")
{
    // `flow.LEDSTRIP`
    flow.set("LEDSTRIP["+led+"],0,0,0")
}

return msg;

```

I'm guessing it will be simple. I just am not sure how to do it.

I'm suspicious it is `&&` rather than the `+` in the lines:

```auto
    let red = n_red + x_red;
    let green = n_green + x_green;
    let blue = n_blue + x_blue;

```

Correct?

So they would become:

```auto
    let red = n_red && x_red;
    let green = n_green && x_green;
    let blue = n_blue && x_blue;

```

Yeah: dumb question.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [5 December 2021 08:13 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/2 "2021-12-05T08:13:22Z")

</div>

You can set a maximum value of 255:  
**let red = Math.min(n\_red + x\_red, 255);** // Either the total or 255, whichever is least  
Or a maximum of 255 and minimum of 0:  
**let red = Math.max(Math.min(n\_red + x\_red, 255), 0);**

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [5 December 2021 08:15 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/3 "2021-12-05T08:15:58Z")

</div>

Yes, thanks.

But that is kind of ..... avoiding the idea that the alarms are more colour (RGB) than brightness.  
So a red alarm is red (and at a fixed brightness) not matter how many times it happens.

Yes if the same alarm keeps happening it would/may be nice to get a brighter indication.  
Not really sure that is a good idea to have or not.

Is the `&&` I proposed correct in what I explained I wanted to do?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [5 December 2021 08:45 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/4 "2021-12-05T08:45:19Z")

</div>

Since you were adding, I assumed you wanted different brightnesses.

When you AND two integers, if either of them is zero you get zero. Otherwise you get the second one.

```auto
10 && 5 = 5
5 && 10 = 10
0 && 10 = 0
10 && 0 = 0

```

When you OR two integers, you get the first one which is non zero, else zero

```auto
10 || 5 = 10
5 || 10 = 5
0 || 10 = 10
10 || 0 = 10
0 || 0 = 0

```

Sorry, without example incoming messages and the desired output, I don't really understand what you are after!

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [5 December 2021 08:53 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/5 "2021-12-05T08:53:59Z")

</div>

That's ok. Thanks.

The values are constant for the R G B values. So now I have to work out do I wan to `&&` or `||`

But you have confirmed it is `&&`... Though I may have to use `||` because I didn't think it through enough.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [5 December 2021 09:00 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/6 "2021-12-05T09:00:37Z")

</div>

If you are operating on numbers you may want bitwise operations instead (or may not :-)... which are single | or &

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [5 December 2021 09:10 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/7 "2021-12-05T09:10:39Z")

</div>

Again: Thanks.

Alas the mention of the `||` has kind of thrown a spanner in the works.

Ok, more details:

Given _now_ the R G B values are all `0`.

and we are only talking one LED. There is an array, but that's handled at another level to what is happening here.

So, we get a message: `rgb,30,0,0` That turns on the `red` to a value of `30`.  
Soon after I get a message `rgb,0,30,0`. I need to keep the `red` at `30` and make the `green` `30`.

The message has the _existing_ value of `30,0,0`. So I want the output to be:  
`rgb,30,30,0`

All that happens quite happily with `+`. But when I get another `rgb,30,0,0` I don't want to see/send `rgb,60,30,0`. Though I have said that could be handy.

I just want to keep the message as `rgb,30,30,0`.

So it is looking more like I need the `||` than `&&`.

There is a problem when I want to turn the LED off, but that's done with a _cheat_ message, as I had already considered the accumulation problem and so wiping the values is handled else where.

I didn't post the code as it is a bit convoluted and I am not sure it is fair expecting you to wrap your head around it. I need the practice/exercise at wording my questions better. (And spelling) 😉

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [5 December 2021 09:10 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/8 "2021-12-05T09:10:47Z")

</div>

> [@Trying\_to\_learn](#):
>
> But you have confirmed it is `&&` .

Woah there! "confirmed" is a bit strong. 😀

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [5 December 2021 09:14 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/9 "2021-12-05T09:14:29Z")

</div>

Ok, sorry.... I didn't mean I was putting the _blame_ on you.

I wasn't sure of the ...... command?

And so `&&` is AND-ing the two values, as opposed to .... something else.

That is what I meant by that statement. 😉

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [5 December 2021 09:18 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/10 "2021-12-05T09:18:13Z")

</div>

I think I'd be inclined to send 1 or 0 for each colour. and OR them with the existing value.

FInally, translate 1 to your preferred ON value for each colour

existing = [0,0,1] (Blue is ON)  
message = [1,0,0] (want RED as well)  
Result = [1, 0, 1]  
Output = [30, 0, 30]

A real programmer would probably pass these as bits in a single byte and bitwise OR them.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [5 December 2021 09:18 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/11 "2021-12-05T09:18:40Z")

</div>

Ok, here is an exert of the flow:

```auto
[{"id":"4a3266fd.5be67","type":"inject","z":"a1911aa3.c45be8","name":"LED 5 ON (test) red","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"rgb,5,20,0,0","payloadType":"str","x":770,"y":900,"wires":[["f866f539.612c18","9765c17e.b692a8"]]},{"id":"c342263d.eed5a","type":"inject","z":"a1911aa3.c45be8","name":"LED 5 ON (test) green","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"rgb,5,0,20,0","payloadType":"str","x":780,"y":940,"wires":[["f866f539.612c18","9765c17e.b692a8"]]},{"id":"18013920.a70a1f","type":"inject","z":"a1911aa3.c45be8","name":"LED 2 ON (test) blue","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"rgb,5,0,0,20","payloadType":"str","x":770,"y":980,"wires":[["f866f539.612c18","9765c17e.b692a8"]]},{"id":"828fbf56.abdc08","type":"inject","z":"a1911aa3.c45be8","name":"LED 2 OFF (test)","props":[{"p":"wipe","v":"WIPE","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"rgb,5,0,0,0","payloadType":"str","x":760,"y":1020,"wires":[["f866f539.612c18","9765c17e.b692a8"]]},{"id":"f866f539.612c18","type":"link out","z":"a1911aa3.c45be8","name":"","links":["ccf13909.72b9f"],"x":935,"y":950,"wires":[]},{"id":"ccf13909.72b9f","type":"link in","z":"a1911aa3.c45be8","name":"Tele_LED command","links":["83a0be11.af7fa","6b0b56b1.42d7e","6dc80421.3dba54","a92024f2.8a95f8","7a3697ed.7f8c7","40aa6c5d.836b7c","2d025d3e.db9caa","8592035a.b9461","b3d937a3.7dfc18","6e4351dc.b4808","36d5ea1.af9fc96","b7ed8dbf.3bf508","5f49a14a.d41a9","17f005b6.ef87ba","caccb33b.17d5e8","b81aee46.41964","4616b7f2.825d8","d8bc91eb.dda1d","3c727657.fcbca2","cfd44ec6.51e508","410375d8.ecfa5c","eca9f37f.557878","b00d31ee.dd87c8","cdb5a49b.9271b8","efcc907f.dddaa8","3023429e.524cd6","f866f539.612c18"],"x":280,"y":640,"wires":[["3ef2d6b1.89130a","3365a854.4c8d5"]],"l":true},{"id":"3365a854.4c8d5","type":"switch","z":"a1911aa3.c45be8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"cont","v":"rgb,","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":620,"y":660,"wires":[["f901977f.2dbaa8"]]},{"id":"f901977f.2dbaa8","type":"change","z":"a1911aa3.c45be8","name":"get `existing`","rules":[{"t":"set","p":"existing","pt":"msg","to":"LEDSTRIP","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":700,"wires":[["3445206e.094b08"]]},{"id":"3445206e.094b08","type":"function","z":"a1911aa3.c45be8","name":"ADD values","func":"// Define variables here/now\nlet n_red = \"\";\nlet n_green = \"\";\nlet n_blue = \"\";\nlet e_red = \"\";\nlet e_green = \"\";\nlet e_blue =\"\";\nlet x_red = \"\";\nlet x_green = \"\";\nlet x_blue = \"\";\n\nlet payload = \"\";\nlet blah = \"\";\nlet led = \"\";\n\nif (msg.debug != undefined)\n{\n context.set(\"DEBUG\",msg.debug);\n node.warn(\"Debug set to \" + msg.debug);\n return;\n}\n\nlet debug = context.get(\"DEBUG\") || 0;\n\n// Get LED number from `payload`\n//let led = parseInt(msg.payload.split(\",\")[1]);\npayload = msg.payload\nblah = payload.split(\",\")[1];\n\n\nled = parseInt(blah);\nif (debug == 1)\n node.warn(\"LED \" + led);\n\nif (led > 4)\n{\n if (debug == 1)\n node.warn(\"LED Colour adjustment happening\");\n // Get RGB values from `payload`\n n_red = parseInt(payload.split(\",\")[2])\n n_green = parseInt(payload.split(\",\")[3])\n n_blue = parseInt(payload.split(\",\")[4])\n if (debug == 1)\n {\n node.warn(\"==== New values below ====\");\n node.warn(\"R \" + n_red + \" G \" + n_green + \" B \" + n_blue);\n }\n\n let existing_value = msg.existing[led];\n // Now get existing RGB values.\n if (existing_value == undefined)\n {\n existing_value = \"0,0,0\";\n }\n x_red = parseInt(existing_value.split(\",\")[0]);\n x_green = parseInt(existing_value.split(\",\")[1]);\n x_blue = parseInt(existing_value.split(\",\")[2]);\n \n if (debug == 1)\n {\n node.warn(\"---- Exiting values below ----\");\n node.warn(\"R \" + x_red + \" G \" + x_green + \" B \" + x_blue);\n }\n\n // Old code\n //red = n_red + x_red;\n //green = n_green + x_green;\n //blue = n_blue + x_blue;\n // New code 2021 12 05 was `&&` changed to `||`\n red = n_red || x_red;\n green = n_green || x_green;\n blue = n_blue || x_blue;\n \n msg.payload = \"rgb,\" + led + \",\" + red + \",\" + green + \",\" + blue\n}\n\n\n//if (msg.payload.who == \"All clear\") // Old code\nif (msg.wipe == \"WIPE\")\n{\n //\n // Wipe the alarm LEDs\n //\n // work needed\n msg.payload = \"rgb,\" + led + \",0,0,0\";\n\n}\nif (msg.clear == \"CLEAR\")\n{\n // `flow.LEDSTRIP`\n flow.set(\"LEDSTRIP[\"+led+\"],0,0,0\")\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":820,"y":700,"wires":[["a3bdb00e.d03ab","90101528.4eda98"]]}]

```

Given all flow.variables exist and are correct.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [5 December 2021 09:19 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/12 "2021-12-05T09:19:31Z")

</div>

The RBG values are 0 - 255. They are basically NEO-PIXEL leds.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [5 December 2021 09:44 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/13 "2021-12-05T09:44:00Z")

</div>

If `0,30,0` only means "set green to 30", what message do you send to turn off the red led?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [5 December 2021 09:49 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/14 "2021-12-05T09:49:40Z")

</div>

A _sneaky message_ like this:

```auto
{"_msgid":"59a12393.ebcd1c","wipe":"WIPE","payload":"rgb,5,0,0,0"}

```

Though that also includes the information that it is for LED 5.

I realised that with what I was wanting to do, there would be a _trap_ turning the LEDs off.  
So I added a `wipe` property that is used to turn the LED off.

_Swings and roundabouts_. ¯\_(ツ)\_/¯

Oh..... Ok. Now I see what you were meaning.

Yeah. I guess I could send.,,,,,

Ah. That's not going to work either.  
I guess I could put a condition where if `msg.wipe` is set make it `&&` where as if `msg.wipe` isn't set it is `||`.

That should work.

But when I am at that.... stage, I am looking at all the alarms and the idea is there shouldn't be _squillions_ of them. I step through the list and get to the point where all are cleared.

Thanks for pointing that out to me.  
I'm not sure that what you said is going to be applied how I am doing it. But thanks for mentioning it.

Oh!  
As I am stepping through the list, the RGB values are sent again to the LED, so the respective LED is turned off and when the next message in the queue is displayed it's respective message sets the LED as needed.

The LED input is from two places. The real time signal and a queue node output which also gets it's input from the real time signal too.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [5 December 2021 10:29 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/15 "2021-12-05T10:29:06Z")

</div>

Maybe some thing like this  
If msg.as\_is is set to true then the rgb will be set to the payload , so you can wipe or set to what ever you need.

```auto
[{"id":"347781de.90bebe","type":"inject","z":"88fadd65b9040724","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"rgb,5,60,0,0","payloadType":"str","x":140,"y":520,"wires":[["374fa350.54c28c"]]},{"id":"374fa350.54c28c","type":"function","z":"88fadd65b9040724","name":"","func":"let rgb = msg.payload.split(\",\");\nif(!msg.as_is){\n let stored = flow.get(\"rgb.led\" + rgb[1] ) || `${rgb[0]},${rgb[1]},0,0,0`;\n stored = stored.split(\",\");\n msg.payload = `${rgb[0]},${rgb[1]},${Number(rgb[2]) || stored[2]},${Number(rgb[3]) || stored[3]},${Number(rgb[4]) || stored[4]}`;\n}\nflow.set(\"rgb.led\" + rgb[1], msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":340,"y":620,"wires":[["33710796.b87a7"]]},{"id":"3243f1f3.f1c8b6","type":"inject","z":"88fadd65b9040724","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"rgb,5,30,0,0","payloadType":"str","x":120,"y":580,"wires":[["374fa350.54c28c"]]},{"id":"b060fa5b.23b808","type":"inject","z":"88fadd65b9040724","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"rgb,5,0,30,0","payloadType":"str","x":120,"y":620,"wires":[["374fa350.54c28c"]]},{"id":"b7c16e41.4af62","type":"inject","z":"88fadd65b9040724","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"rgb,5,30,30,0","payloadType":"str","x":120,"y":660,"wires":[["374fa350.54c28c"]]},{"id":"33710796.b87a7","type":"debug","z":"88fadd65b9040724","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":600,"y":620,"wires":[]},{"id":"297b4f95.b933f8","type":"inject","z":"88fadd65b9040724","name":"set as in payload","props":[{"p":"payload"},{"p":"as_is","v":"true","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"rgb,5,0,0,0","payloadType":"str","x":160,"y":700,"wires":[["374fa350.54c28c"]]}]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [5 December 2021 10:31 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/16 "2021-12-05T10:31:19Z")

</div>

Thanks @E1cid .... Just now there are a few other worms in that area.

I'll have a _buther's hook_ and see if I can get my head around it and how much work would be entailed applying it to what I already have.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 December 2021 10:37 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/17 "2021-12-05T10:37:38Z")

</div>

You could send null as the value for colours that were not to be changed.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [5 December 2021 10:40 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/18 "2021-12-05T10:40:37Z")

</div>

I've just had a look.... Mind blown.

Thanks. But the programming is above my skill/understanding.

I don't understand how the `rgb[1])` works to allow an array of LEDs. because the `1` is fixed.

and something is/was lost with the `msg.as_is` SORRY! Just found it. _Hidden_.

Yeah, I fully appreciate how good what you wrote is, but it is _magic_ to me and I can't parse it.

My bad, I know. I need to learn more, but that's a given. 😉

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [5 December 2021 10:46 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/19 "2021-12-05T10:46:53Z")

</div>

rgb[1] is the led id number , it is used in the flow context to store each led in it's own property, all in one object. Rather than a seperate context var for each led. This way you can delete all led context in one go. Have a look at how it is stored in context object rgb

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [5 December 2021 10:47 UTC](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723/20 "2021-12-05T10:47:25Z")

</div>

That is an idea - I guess.

But there is a lot of stuff already written.

I am just trying to make it that if an _alarm_ message is received, it sets the notification and _colours_ the LED as needed.

Then if/when another _alarm_ happens it _adds_ the colour to the LED. As in (literally) the colour. The _brightness_ isn't/doesn't change.

Some alarms show as RED, some BLUE and some GREEN.  
This signal is _split_ and one sent directly to the LED and the other is sent into a `queue` node.  
I press a button and it steps the queue to the next message.  
That message sends the LED _message_ and so resets the colour as needed for THAT alarm.  
(That isn't crucial at this point) I am looking at the screen and going through the list of what has happened.

[Next page](https://discourse.nodered.org/t/adding-values-but-more-like-and-than/54723.md?page=2)
