Creating a flow with multiple triggers and conditions

I’m pretty new to Node-RED so I’m slowly working on moving all of my existing automations from HA to NR, as well as creating some from scratch. I’ve been trying to wrap my head around a concept that I use quite frequently in my HA automations, but that I don’t quite know how to implement in NR. Here’s an example:

I have some light bars behind my tv which I only want to have on IF the tv is on and IF the sun is down:

  1. when the tv turns on but the sun is still up, the light bars need to stay OFF
  2. when the sun sets but the tv is off, the light bars need to stay OFF
  3. when the tv turns on and the sun is down, the light bars need to turn ON
  4. when the sun sets and the tv is already on, the light bars need to turn ON
  5. when either the tv turns off or the sun rises, the light bars need to switch OFF

#5 shouldn’t be any trouble at all, but I’m not quite sure how to approach #1 through #4. How does one work with multiple triggers which are also conditions in NR? Any advice or pointers in the right direction would be appreciated.

I have been searching for answers, mostly in this category on the forum but also on reddit. Unfortunately, I haven’t come across a similar scenario. I’m sure I’m not the only person wanting a flow like this, so I guess my searching skills must be letting me down.

I would probably use a couple of flows.

#2 is easy, you don’t have to do anything

1 and 3 can be combined into a single flow.
TV is the trigger, TV turns on, check the sun, control light bar

4 is simple too. Use the sun as a trigger, check state of the TV, turn on light bar

So, really what you need is 2 different trigger nodes (you can use the Trigger-state node or the Event-state node). I prefer the event-state node. The first one will be the TV power (assuming you have your TV and/or power state for it exposed to HA). The second one will be the sun.sun position. You’ll also make use of the current-state node to test for various conditions.

This should help. I haven’t tested it, but the general logic should work.

Thank you both for your input. I guess my mistake was thinking it could be done in 1 single flow.

It could be, but it would look nasty. Keep it simple and readable.

2 Likes

As @flamingm0e said, the KISS principle absolutely applies here, however, flows are just containers. You can have as many or as few automations in flows as you want. There’s no hard rule (that I’ve ever seen). I typically setup my flows according to purpose and/or room. So, for my office (which has about 10 different automations), I keep all of them in a single flow. That way, should I need to mess with something, I know exactly where to go and the same for my other rooms (kitchen, living room, dining room, etc).

Not to confuse @fanaticDavid, but the term “flow” in Node Red relates to 2 different things, and it’s stupid that they do this. LOL.

A flow can be a “tab” page where you create “flows”

or

A flow is the string of nodes you create to perform a function (within a “flow” tab)

1 Like

I totally agree with you about their (Node Red devs) choice of nomenclature regarding flows. I’ve seen this brought up a few times in their forums. That’s why usually when I try to explain Node Red, I use the term “automations” to refer to the inner(?) “flow” on the “flow” tab.

Yeah, I was talking about the latter: a single string of nodes to create an automation.

1 Like