Best practice for conditional trigger

New to Node-Red, not to programming.
I am using Openhab and Loxone and thought to put my rule logic here.
So I learned you cannot have multiple inputs it seems.
I wonder what the best practice is for implementing a very common scenario :

  • input motion detector and brightness sensor
  • output light
  • when the motion detector fires, the light should go on if the brightness is under a certain threshold

Similar to that, motion detector + alarm armed = alarm message.
Similar to that, toggle switch so that the on off command looks at current state of switch and reverses it (from on to off and off to on).
Plenty of scenarios that would require more than one condition to match in case a certain flow gets triggered.
I am thinking about global or flow variables to present certain values and then work with function block, or perhaps boolean gates.
But this seems so common logic, that I cannot believe there is no simpler solution for it that you can in fact grab multiple inputs when one of them triggers, and work with that.
What are any best practices to implement these requirements ?

Thanks !

You would either store the values in context storage or use a join node. As to best practice that is different for everyone
Here is a join node example.

[{"id":"677f8ec2.78e86","type":"join","z":"e4f02345.29fe9","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":350,"y":880,"wires":[["9a56495c.3499d"]]},{"id":"5cd6d99c.939ca","type":"inject","z":"e4f02345.29fe9","name":"light level35","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"lightlevel","payload":"35","payloadType":"num","x":130,"y":920,"wires":[["677f8ec2.78e86"]]},{"id":"214286e5.05cc42","type":"inject","z":"e4f02345.29fe9","name":"light level100","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"lightlevel","payload":"100","payloadType":"num","x":140,"y":960,"wires":[["677f8ec2.78e86"]]},{"id":"9a56495c.3499d","type":"change","z":"e4f02345.29fe9","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"(payload.lightlevel >50 and  payload.motion = 1) ? 1 : 0","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":880,"wires":[["ff247f5b.7935b"]]},{"id":"b02c2f39.af5328","type":"change","z":"e4f02345.29fe9","name":"send complete on motion","rules":[{"t":"set","p":"complete","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":820,"wires":[["677f8ec2.78e86"]]},{"id":"ff247f5b.7935b","type":"debug","z":"e4f02345.29fe9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":880,"wires":[]},{"id":"22545677.0e6e0a","type":"inject","z":"e4f02345.29fe9","name":"motion 0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"motion","payload":"0","payloadType":"num","x":110,"y":820,"wires":[["b02c2f39.af5328"]]},{"id":"64af2594.e2d08c","type":"inject","z":"e4f02345.29fe9","name":"motion 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"motion","payload":"1","payloadType":"num","x":110,"y":860,"wires":[["b02c2f39.af5328"]]}]
1 Like

Thanks for the reply and the clear example. I thought join was not applicable in this case but I misread the documentation I recon.
Will explore this further !

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