So I’m searching around, looking at tutorials etc, but all I see is generally a flow doing one specific thing (ie time of day, turn on specific lights).
I will be having multiple lights and multiple switches, all wanting to change colors, brightness, on/off, etc.
From what I’m seeing I will need to have multiple flows for this - one for every switch effectively… But they’ll all be the same flow - the only difference is the light switch and the bulb/s (or group) it’s interacting with - all the logic will basically be the same.
So, is it possible to have an “entity_id” in node red refer to some variable or value elsewhere (maybe an array, maybe a property held against a switch, or maybe just performing the ‘automation’/‘script’ against the calling switch in a ‘generic’ fashion?
Basically set up an “all event” listener for a button press (‘on’ let’s say), and then grab the calling switch ID from the message and then use that later on?
I’ll continue looking and reading, node red seems very nice and will definitely do what I want… I just hope that I won’t have to make about 15 flows (or one big bad flow with duplicated sections/logic) when a simple lookup table and variable substituation would surely do.
–
Whizz
First things first: NEVER listen for all events. Don’t. Bad things happen.
You absolutely can have a single flow handling multiple events. This is one that I’m in the process of rewriting for my office lights and devices. Most of my other rooms are the same way. Basically, I break my flows into rooms and targeted domains (notifications, contact sensor events, motion events, etc).
However, the real trick to accomplishing a lot with NodeRed is mastering the Function node. As an example, this is the flow for my “basic” contact sensors.
Each sensor has an event node. They all flow into a function node that figures out who called and what to do and then it passes that into an empty call-service node.
You can also accomplish the same thing with switch nodes, change nodes and global/flow level variables.
2 Likes
Ah great - a function node looks very similar to what I’m looking for, so I’ll start looking into those a lot more.
And, by “all events” I mean something like you’ve got where you’re listening for “zha_events”, and then after that you filter through a switch node or some logic nodes to filter out the button events you want.
Thanks very much for the point in this direction - just how ‘empty’ is the call-service node?
1 Like
Very empty
For zha_events, this is how I have it configured:
This is my master bedroom 5 button remote one:
Absolutely possible. If your flows are very similar, you may think about employing subflows to ease your workload as well. https://nodered.org/docs/user-guide/editor/workspace/subflows
1 Like