# One button control

**URL:** <https://discourse.nodered.org/t/one-button-control/21816>\
**Category:** General\
**Created:** [16 February 2020 19:28 UTC](https://discourse.nodered.org/t/one-button-control/21816 "2020-02-16T19:28:57Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![AD3D](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ad3d/32/2731_2.png) [@AD3D](https://discourse.nodered.org/u/AD3D)\
**Post date:** [16 February 2020 19:28 UTC](https://discourse.nodered.org/t/one-button-control/21816/1 "2020-02-16T19:28:57Z")

</div>

I am wondering if there is a 'simple' solution for what I would like to do with a few flows at ones.  
I have a few WiFi/network devices that act as a lamp. Nothing fancy but it works. ![6xlol_dashboard](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/7/2744dcef577680cb78856ce58e736b4b36231f38.jpeg)  
Node-RED can ask them what there current color is and there state and shows a yellow lamp for on, grey for off and shows the current color on the button. A push on the POWER button changes it's state.  
I have them almost all on separate flows (except for the 06 version where they are on one flow).

 ![lol07_flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/f/6f887fc732c2118d940eb2a2cc52227c488e3397.jpeg)

```auto
[{"id":"ab7cbe16.df717","type":"tab","label":"LOL07","disabled":false,"info":""},{"id":"46ab4bd1.85472c","type":"inject","z":"ab7cbe16.df717","name":"","topic":"","payload":"","payloadType":"str","repeat":"3","crontab":"","once":true,"onceDelay":"","x":110,"y":140,"wires":[["a5e69504.92bb3","d3a10a91.d6d73"]]},{"id":"a5e69504.92bb3","type":"http request","z":"ab7cbe16.df717","name":"get current state","method":"GET","ret":"txt","url":"lol07.local/current_state","tls":"","x":290,"y":180,"wires":[["f365f49b.5a3918","d9e6a1cd.7ac768"]]},{"id":"f365f49b.5a3918","type":"debug","z":"ab7cbe16.df717","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":490,"y":260,"wires":[]},{"id":"d3a10a91.d6d73","type":"http request","z":"ab7cbe16.df717","name":"get current color","method":"GET","ret":"txt","url":"lol07.local/current_color","tls":"","x":290,"y":120,"wires":[["3165b8bc.46c36","f135ed84.4374a8","94be12e6.c75c98","8e9bc079.a09728"]]},{"id":"3165b8bc.46c36","type":"debug","z":"ab7cbe16.df717","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":490,"y":60,"wires":[]},{"id":"94be12e6.c75c98","type":"ui_button","z":"ab7cbe16.df717","name":"","group":"aadd247e.ac6898","order":1,"width":"3","height":"1","passthru":false,"label":"Power","color":"","bgcolor":"{{msg.payload}}","icon":"","payload":"@2","payloadType":"str","topic":"","x":690,"y":100,"wires":[["e511d263.935f"]]},{"id":"e21659af.6bf148","type":"ui_text","z":"ab7cbe16.df717","group":"aadd247e.ac6898","order":2,"width":"1","height":"1","name":"indicator","label":"","format":"<font color={{msg.payload}} ><i class=\"fa fa-lightbulb-o fa-2x\" style=\"font-size:48px;\"></i></font>","layout":"row-spread","x":680,"y":220,"wires":[]},{"id":"d9e6a1cd.7ac768","type":"change","z":"ab7cbe16.df717","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"Off","fromt":"str","to":"grey","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"On","fromt":"str","to":"yellow","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":220,"wires":[["e21659af.6bf148"]]},{"id":"8e9bc079.a09728","type":"ui_colour_picker","z":"ab7cbe16.df717","name":"","label":"","group":"aadd247e.ac6898","format":"hex","outformat":"string","showSwatch":true,"showPicker":true,"showValue":true,"showHue":false,"showAlpha":false,"showLightness":true,"dynOutput":"false","order":4,"width":"1","height":"1","passthru":false,"topic":"","x":670,"y":140,"wires":[["c4aca56d.d9be6"]]},{"id":"f135ed84.4374a8","type":"ui_text","z":"ab7cbe16.df717","group":"aadd247e.ac6898","order":3,"width":"3","height":"1","name":"","label":"","format":"{{msg.payload}}","layout":"col-center","x":690,"y":180,"wires":[]},{"id":"1ce48feb.8d7e88","type":"debug","z":"ab7cbe16.df717","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":990,"y":200,"wires":[]},{"id":"e511d263.935f","type":"websocket out","z":"ab7cbe16.df717","name":"","server":"","client":"3effd81d.47d4f","x":1000,"y":60,"wires":[]},{"id":"ed7255db.179d48","type":"ui_dropdown","z":"ab7cbe16.df717","name":"","label":"","place":"Select option","group":"aadd247e.ac6898","order":0,"width":"4","height":"1","passthru":true,"options":[{"label":"red","value":"#ff0000","type":"str"},{"label":"green","value":"#00ff00","type":"str"},{"label":"blue","value":"#0000ff","type":"str"},{"label":"magenta","value":"#ff00ff","type":"str"},{"label":"yellow","value":"#ffff00","type":"str"},{"label":"cyaan","value":"#00ffff","type":"str"},{"label":"white","value":"#ffffff","type":"str"},{"label":"black","value":"#000000","type":"str"},{"label":"default","value":"#808080","type":"str"},{"label":"nice one","value":"#444800","type":"str"},{"label":"Aineke's choice","value":"#727f1e","type":"str"}],"payload":"","topic":"","x":680,"y":60,"wires":[["e511d263.935f"]]},{"id":"c4aca56d.d9be6","type":"change","z":"ab7cbe16.df717","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"\"#\"&payload","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":140,"wires":[["e511d263.935f","1ce48feb.8d7e88"]]},{"id":"aadd247e.ac6898","type":"ui_group","z":"","name":"LOL07","tab":"4cbb5257.8f207c","disp":true,"width":"4","collapse":false},{"id":"3effd81d.47d4f","type":"websocket-client","z":"","path":"ws://lol07.local:81","tls":"","wholemsg":"false"},{"id":"4cbb5257.8f207c","type":"ui_tab","z":"","name":"LOL","icon":"dashboard","order":12}]

```

That means I have 4 flows that are almost the same except for there address and there name.

Now I like to make a switch that change the state of all devices at ones.  
Something like a button on a new group that, if a device is on (as in the picture, LOL06B and LOL07 are TRUE therefor on) only does two get a message to change there state. (otherwise the other ones would go on!).  
Do I need to create a new flow with, in this case six WebSocket's and six HTTP nodes, or is there an other way?  
Maybe put all the devices on one flow and add that button function there is an option but looks very messy to me and made me wonder if that is really the best way.  
So, I am just wondering what would you do?  
Sorry for asking but I am just a simple carpenter with a very nice hobby that likes to learn this.  
Despite I am not the quickest learner, I have learned already a lot from some people here, so any advice is always welcome.  
Thanks in advance.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [16 February 2020 21:18 UTC](https://discourse.nodered.org/t/one-button-control/21816/2 "2020-02-16T21:18:16Z")

</div>

> [@AD3D](#):
>
> simple carpenter

Haha, I never found carpentry "simple".

> [@AD3D](#):
>
> Sorry for asking

Don't be sorry, that's what the forum is for 😀

So, to answer the question. The way you have things set up at the moment, yes you would need another flow to drive the other button with the output from that new button also linked to the other buttons. That is a very flow-like way of doing things. But not a very computery way of doing things.

A more generic way, however, would require you to replace the current flows with a template that created all the buttons dynamically. More learning to be done possibly but it is scalable which would mean that if you added another 20 switches in the future, all you would need to do would be to update the data, the interface would update automatically.

---

<div class="post-metadata">

**Author:** ![AD3D](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ad3d/32/2731_2.png) [@AD3D](https://discourse.nodered.org/u/AD3D)\
**Post date:** [17 February 2020 01:41 UTC](https://discourse.nodered.org/t/one-button-control/21816/3 "2020-02-17T01:41:34Z")

</div>

Thanks for the response.  
As far as I see it now, the more generic way would be a very smart way.  
Thanks for that suggestion.  
That way even add some possibility that is for sure worth the time for trying to understand, learn and create it that way.  
But, because it doesn't sound that simple to create to me, I better start with the raw wood, uhm, sorry, very flow-like way for now.

---

<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:** [17 February 2020 15:29 UTC](https://discourse.nodered.org/t/one-button-control/21816/4 "2020-02-17T15:29:03Z")

</div>

You could maybe use link nodes to link the output of the new button to where each of the other buttons go - so press one = press them all.

---

<div class="post-metadata">

**Author:** ![AD3D](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ad3d/32/2731_2.png) [@AD3D](https://discourse.nodered.org/u/AD3D)\
**Post date:** [18 February 2020 01:57 UTC](https://discourse.nodered.org/t/one-button-control/21816/5 "2020-02-18T01:57:08Z")

</div>

Thanks for the suggestion.  
That could do it but I stumbled on an other logical event. Not all websockets needs to send the "switch the state" sign namely.  
That is something I need to fix with a function and a whole lot of if's, I think.  
Something like: If yellow light of lol06a is on then send a @2 to lol06a else do nothing.  
Or: If HTTP requests payload is "Off" do nothing.

---

<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:** [18 February 2020 04:37 UTC](https://discourse.nodered.org/t/one-button-control/21816/6 "2020-02-18T04:37:39Z")

</div>

I'll jump in here too.

What you could do is something like:

> [@AD3D](#):
>
> Node-RED can ask them what there current color is and there state and shows a yellow lamp for on

Store that as a `flow` variable for each bulb.

Then, when you press the new "ALL TURN OFF" button you route the message through a `switch` node.

That node switches the message on the condition of the `flow` variable for that bulb being on.

That would reduce a lot of your problem you mentioned

> [@AD3D](#):
>
> That is something I need to fix with a function and a whole lot of if's, I think

No longer a problem.

I would love to be smart enough to use `template`s, but I'm dumb.

Oh, _another_ way you could do it is by learning how to use `sub-flows`.  
But that would require a bit of rewriting the flow as `sub-flows` don't allow multiple inputs and don't allow GUI things.

But I have done it with a few things in my flows.

Just another possibility.

---

<div class="post-metadata">

**Author:** ![AD3D](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ad3d/32/2731_2.png) [@AD3D](https://discourse.nodered.org/u/AD3D)\
**Post date:** [18 February 2020 14:44 UTC](https://discourse.nodered.org/t/one-button-control/21816/7 "2020-02-18T14:44:33Z")

</div>

Well, Trying\_to\_learn, nice of you to jump in and thank you for the idea.  
The more the merrier we like to say around here. 🙂  
But, if you are dumb and suggest me to store that as a flow, I must be dumber because I am looking at a few examples, that's basically how I can learn something, and do not understand it yet how this can work.

 ![countit2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/2/325d98588b9ca1d76cac00e20dc2e1cde6c05e64.jpeg)  
Mainly because the most examples I see are counting and storing the count. and not a msg.payload (a string like"On")  
 ![countit](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/9/693e6d3a2821a12dac7c69bbdebc248e83c9b8bc.jpeg).  
I think I have to look at context now.

---

<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:** [18 February 2020 19:41 UTC](https://discourse.nodered.org/t/one-button-control/21816/8 "2020-02-18T19:41:14Z")

</div>

I'll have to be quick on this reply.

Power is going to be turned off today for about 10 hours.

You say that the flow you have can tell you the state of the bulbs.

So what you need is something like what you showed there in that example.

Just looking at the time I think I had better shut down now. Though I have 20 minutes, I don't want to push the friendship with the people doing the job.

Talk later.

---

<div class="post-metadata">

**Author:** ![AD3D](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ad3d/32/2731_2.png) [@AD3D](https://discourse.nodered.org/u/AD3D)\
**Post date:** [19 February 2020 00:20 UTC](https://discourse.nodered.org/t/one-button-control/21816/9 "2020-02-19T00:20:26Z")

</div>

No worries.  
There is plenty of time to create solutions because it is not a problem but a challenge.

Hope there is no problem for you.

> [@Trying\_to\_learn](#):
>
> Power is going to be turned off today for about 10 hours

Take care.

---

<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:** [19 February 2020 20:01 UTC](https://discourse.nodered.org/t/one-button-control/21816/10 "2020-02-19T20:01:13Z")

</div>

Thanks.

Yeah, "Just another day in the office" alas. Things happened and a few others, and a couple of unexpected.

Today is a bit more of the same with other things.

Here is the flow/idea.

```auto
[{"id":"301d9e57.c4a36a","type":"inject","z":"184dc884.7aba5f","name":"LOL06aON state","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":2070,"y":200,"wires":[["11240296.ae25a5"]]},{"id":"11240296.ae25a5","type":"change","z":"184dc884.7aba5f","name":"","rules":[{"t":"set","p":"LOL05a","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":2270,"y":200,"wires":[[]]},{"id":"6deb6db8.22e3fc","type":"comment","z":"184dc884.7aba5f","name":"Adjust the flow name for each input/device","info":"","x":2170,"y":160,"wires":[]},{"id":"37c16883.bcc5a","type":"inject","z":"184dc884.7aba5f","name":"The big button","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":2090,"y":360,"wires":[["28a920a5.54f208"]]},{"id":"28a920a5.54f208","type":"change","z":"184dc884.7aba5f","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"LOL06a","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":2340,"y":360,"wires":[["d9d5cea9.9a25e8"]]},{"id":"d9d5cea9.9a25e8","type":"switch","z":"184dc884.7aba5f","name":"Filter","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"ON","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":2500,"y":360,"wires":[["6adb11.bc2444f"]]},{"id":"d5032d4f.efdfa8","type":"comment","z":"184dc884.7aba5f","name":"The \"BIG BUTTON\" input","info":"","x":2070,"y":320,"wires":[]},{"id":"6adb11.bc2444f","type":"change","z":"184dc884.7aba5f","name":"Turn off the bulb","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2660,"y":360,"wires":[["337604ca.07fd94"]]},{"id":"337604ca.07fd94","type":"debug","z":"184dc884.7aba5f","name":"Send this to your flow.","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":3010,"y":360,"wires":[]},{"id":"5ebeddd7.795a14","type":"comment","z":"184dc884.7aba5f","name":"Duplicate this for every bulb","info":"","x":2530,"y":320,"wires":[]}]

```

Idea:  
Every time you _press a button_ and change a bulb's condition there will be a message sent from the bulb.  
This is then set in _context_ (`flow` actually) with the name of the bulb.  
When you press the _big button_ to turn off all bulbs, **only** the ones which are `ON` are send a message to turn `OFF`.

Though seriously, if all you want to do is turn them off, you could just send the `OFF` command to all the bulbs irrespective if they are on or off. As the ones which are off wouldn't do anything anyway.

But this way is a bit _neater_ as it only sends the message to the ones which are `ON`.

You could modify the flow in the `filter` node and rather than having it match `ON` have it match `!= OFF`. That way any bulbs which are on with a colour value would also be turned off.

---

<div class="post-metadata">

**Author:** ![AD3D](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ad3d/32/2731_2.png) [@AD3D](https://discourse.nodered.org/u/AD3D)\
**Post date:** [20 February 2020 03:01 UTC](https://discourse.nodered.org/t/one-button-control/21816/11 "2020-02-20T03:01:37Z")

</div>

O. I know these days. They pass.  
About your idea.

> [@Trying\_to\_learn](#):
>
> you could just send the `OFF` command

That's not completely the case here, I'm afraid because I send an `@2` to change the state of the device. The device send a `On` or a `Off` text (string) back when asked for with the HTTP requests node.  
The change node search for the `On` to make the bulb on the dashboard yellow or `Off` to make it grey.  
I couldn't, yet, figure out a way to make the button on the dashboard grey when the change node found `off` or make the button show the color the real light is on. But that's not relevant here for now. (funny. Now I am typing this I may have got an idea about that!).  
The main hiccup will probability be that it needs to know if it is allowed to send `@2` or not.  
I am sorry if I didn't was clear about that.

If I am trying to understand your idea, I can't understand the command `Adjust the flow name for each input/device`  
The inject node name is `LOL06aON state` what I can understand but the change node set the `flow LOL05a`, and that `LOL05a`confuses me.  
Well, I need a lot more to learn and try to read more about this.  
Thanks for the idea, and your time.

---

<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:** [20 February 2020 05:43 UTC](https://discourse.nodered.org/t/one-button-control/21816/12 "2020-02-20T05:43:00Z")

</div>

> [@AD3D](#):
>
> If I am trying to understand your idea, I can't understand the command `Adjust the flow name for each input/device`

Well, if you have (say) 4 bulbs..... you will have LOL01a, LOL02a, LOL03a, etc.

You will need to duplicate those nodes and _edit_ the parts needed to be useful for all the individual devices / bulbs.

I got the `LOL05a` from your original post / flow. (Ok, `LOL07a` in the first and `LOL06a` in the 5'th post)

I am sending a specific `OFF` signal just for simplicity.  
But if you inject (connect?) that into your flow indicated.....

 ![flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/2/52e07aa22a7e9ef27f567486839f225e1941f057.jpeg)

I'm guessing the `Power` button turns the bulb on/off.

So....... What ever that button injects, send that from my flow and insert it into your flow.  
All should be working.

---

<div class="post-metadata">

**Author:** ![AD3D](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ad3d/32/2731_2.png) [@AD3D](https://discourse.nodered.org/u/AD3D)\
**Post date:** [20 February 2020 14:47 UTC](https://discourse.nodered.org/t/one-button-control/21816/13 "2020-02-20T14:47:03Z")

</div>

**Got it**  
 ![twoforall_dashboard](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/7/373b50da04d74dd063dd433c645e714cc12e93eb.jpeg)  
and learned a few things on the way.  
On the flow (example is LOL03) added the change node and set it to `global`and `LOL03State`  
 ![globalLOL03State](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/7/07785b2a9c73509dfd63d92c590b9989d8fb75f2.jpeg)  
Added a link out node to the HTTP requests node and called that `LOL03 state` and a link in to the WebSocket out node and called that `LOL03 send state`.  
So it now looks like the picture below.

 ![setLOL03State](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/d/fdefe52736b79adccd84f1a71a3fe5ef260966e0.jpeg)  
On the two for all flow, where the `all on` and `all off` buttons are created, added the change node and let that set the msg payload to `global` `LOL03State`. ![globalLOL03State-2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/9/1956a83a8b7fdb42658c42a29f8f9542909a0ce3.jpeg)  
The switch node, connected after that change node to the `all off` button for example, looks for an `On` string.  
 ![switchLOL03State](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/7/f795c9caf9780a1f34a637368e02287195592329.jpeg)  
And sets the next change node to the string I like to send.  
 ![changeLOL03State](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/9/795006afc26c8eee32c187e5c06923fc6a2bdc83.jpeg)  
The link node connect to the WebSocket out node link `LOL03 send state` on the LOL03 flow does the rest.  
 ![twoforall_flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/f/4f87899100ac75108f90444607148d18587c220b.jpeg)

Thanks a lot to

> [@Trying\_to\_learn](#):
>

for the flow/idea that made this challenge to a success.  
And

> [@dceejay](#):
>

for point me to the link node that also helped me in this.

Learned again a few things and without you kind people that made suggestions, give ideas and spend some time to help I probably couldn't make it this way.  
Thank you all.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 March 2020 14:47 UTC](https://discourse.nodered.org/t/one-button-control/21816/14 "2020-03-05T14:47:10Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
