Use one function-node for many lights

Ok, sorry for the bad title but I could not figure out how to formulate myself. I have several lights where I use several separate flows that are almost identical. It checks for motion and for the time of day and the reading of a light-sensor and uses a function to transform the lux (light level) from the sensor to a dimlevel for the light-bulbs.
I have a function in all these flows and the function is the same. Is it possible to use the same function-node for all flows ? I did some testing and tried to replace all with one global function but after that all light-bulbs seamed to trigger as soon as one motion-detection happened.

Is this supposed to work somehow by checking id's or similar ?

Are the flows similar enough that you can build a subflow that you configure using the subflow properties, which can then be used for each light?

I not then show us how you attempted to replaced it with a global function.

I do not use subflows yet as I'm not able to pass all dynamic properties (~10 variables) down into the subflow

Any advise?

The change node allows you to put variables onto the msg. Otherwise, a function node will let you grab any variables.

I'm using function nodes all the time and aware on how tog grab/manage variables.

But I struggle to pass down the necessary values into a subflow :frowning:

Simple example:

  • I have a sublfow to turn on a Lamp (LampID via variable)
  • The will switch ON
  • The lamp will wait for a specified duration (Duration via variable)
  • the lamp switches OFF

It works for the 1st lamp .. but whenever I try a 2nd or 3rd lamp the it forgets the previous ones :frowning: .. it looks like the variables are getting overwritten every time

The Trigger node will do that for you as long as each light control has a separate msg.topic.