I keep the power states of some lights in flow variables, for example:
flow.garageeavelights
flow.backyardfloowlight
flow.drivewayflood
And I have a number of switch nodes that use jsonata to see if the saved value differs from a target value, e.g.:
($number(payload.On) = 1 and $string($flowContext('drivewayflood')) = "off") or ($number(payload.On) = 0 and $string($flowContext('drivewayflood')) = "on")
If the states differ, the msg is passed on...
I decided I wanted to create a subflow that took the payload and took the value of one of the flow variables (that I provide as an an input environment variable), but I discovered that:
The environment variable input cannot be set with either:
- a flow variable, e.g.
flow.whatever
- a jsonata expression, e.g.
$string($flowContext('drivewayflood'))
So I thought I would just provide the flow variable name (e.g. drivewayflood
) and then grab the parent flow's variable value from the subflow... but I cannot figure out how to do that.
I mean, I could add the flow variable's value to msg
before the call to the subflow, but the purpose of having a subflow is to reduce the node clutter in the flow that's calling it. Using the subflow would also make it easier to read the flow (since the jsonata in the switch node is hard to read). So if I can't just pass my current p[ayload to one subflow node without needing extra nodes, I might as well just keep my current switch nodes with the long jsonata expression...
So, how can I pass a payload and a selected flow variable to a subflow?