Node-RED : efficient way to do an "AND" among several triggers

Hello everyone !

I’ve been using Node Red for about a year now, but still I’m struggling on this easy problem.

Let’s assume I want to switch on a light when all of these conditions are met :

  • Light is currently off or brightness is < 20%
  • Motion is detected in the area
  • Outdoor luminance < 500lux

How can I achieve this efficiently in Node Red ? :slight_smile:

Currently I have 3 triggers, and then that I check that all conditions are met. But it does not seem efficient because doing so I recheck also the condition of the trigger itself.
Or I could have 3 lines, one for each trigger and then check the 2 other conditions for each line, but once again inefficient nad more difficult to maintain (when I want to change a luminance threshold for instance, I would have to change it in 3 nodes…).

I’ve tested the “AND” and “OR” nodes from a few custom packages but I always had issues, most of the time after HA or node Red restarts.

That seems very basic but I can not find an easy and efficient way to achieve this. How do you do this ?

Thanks ! :slight_smile:

Just use a trigger with motion detected, then add conditions to that trigger for the other two entities/states.

It does not work.
If motion has been detected for 2 hours but the sun goes down just now, I want the flow to trigger also for instance.

So each of the conditions has also to be a trigger. That’s the tricky part.

I’ve used a simple example. For some flows I have 4 or 5 conditions that should all be met and each of them has also to be trigger.
The logic is easy to implement but in a very inefficient way that I’d like to avoid. More specifically I’d like to avoid duplicating conditions.

Saying that, I should maybe consider some “gateway” node.

I would still go with AND / OR modules. Retaining the state on a restart is a problem. Not a complete solution but setting the trigger nodes as “output on connect” helps in my cases…