One button control

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
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).

[{"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.

Haha, I never found carpentry "simple".

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

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.

1 Like

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.

1 Like

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.

1 Like

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.

I'll jump in here too.

What you could do is something like:

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

No longer a problem.

I would love to be smart enough to use templates, 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.

1 Like

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. :slightly_smiling_face:
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.


Mainly because the most examples I see are counting and storing the count. and not a msg.payload (a string like"On")
.
I think I have to look at context now.

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.

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.

Take care.

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.

[{"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.

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

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 LOL05aconfuses me.
Well, I need a lot more to learn and try to read more about this.
Thanks for the idea, and your time.

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.....

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.

1 Like

Got it
twoforall_dashboard
and learned a few things on the way.
On the flow (example is LOL03) added the change node and set it to globaland LOL03State
globalLOL03State
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.


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
The switch node, connected after that change node to the all off button for example, looks for an On string.
switchLOL03State
And sets the next change node to the string I like to send.
changeLOL03State
The link node connect to the WebSocket out node link LOL03 send state on the LOL03 flow does the rest.

Thanks a lot to

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

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.

1 Like

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