Zigbee motion to a zwave light, on/off logic in Node-Red.
Motion: 12:10:46.747
Light ON: 12:10:47.079
So 0.332s. On that device driver I know that I log the ON event via the report back from the device (not issuance of the ON command), so it actually turned on faster than 0.332s.
Now, the logic is very simple in node-red on that one (motion, check mode, turn light on at x% based on mode), but still gives you another data point. My node-red server is running on docker on my AMD EPYC 3251 based server.
Similar to yours EXCEPT I am not asking the hub for the current mode in that part of my logic.
I store the mode as a flow.variable any time the mode updates and then use that variable in a switch node. That is MUCH faster than going out to the hub to check mode every time.
To store mode in a variable: Hubitat mode node -> change node that does a 'set flow.currentMode = msg.payload.value'
I just stick that at the top of my lighting flow sheet (side note: I do all lighting for my entire house in a single Node-Red flow), then I can use flow.currentFlow anywhere I want to in that flow. I guess you could make it global.currentFlow instead, and then use it in all flows. I haven't tried that to see what the speed penalty is by doing that (if any).
To check the stored mode variable in a flow: switch node that checks flow.currentMode == 'desired mode'
Whether you check the flow.currentMode in a function node or a switch node is up to you (more of a style preference versus technical decision). But either way it is a really handy way to do mode checking basically for 'free' (well, close enough to 'free' versus polling the hub, anyway).
It is handy to have that inject there. Even handier if you make it a 1-time 'on startup' execution (run after 0.1s, repeat=none). Then the variable gets set on startup without waiting for the next mode change.
I can't get this work. So clearly doing something wrong. The debug node indicates that I am able to save the current mode, but I cannot retrieve it using a switch node.
Just explain in words a sample flow that you're trying to do, and I would be happy to slap together how I would do it.
Not sure if that would be more or less helpful though. Like we've all said before, there are probably a dozen different ways to do it - all technically fine.
Still not sure why you would want/need all the boolean true/false stuff - that just isn't how I do my logic - but no matter.
If you want to use the function node like that, then do it the way dan said. That is the easiest way to do it with the assumption that you want to use your function node like that.
That is hard to answer without knowing what you are doing with the boolean logic.
Need to understand the big picture to say how I would do it. And who knows - maybe I would do it the same way? I definitely use function nodes for some of my mode based lighting logic - just not as boolean true/false on the output.
For instance, here is a standard motion lighting (2 motion sensors) with no function blocks, but it does different things in 2 different modes. Could have made it 1 Hubitat command block on the right if I used a function node, but I like not using function nodes when I don't have to.
(note to self, probably needs some logic on the "on" path so that it doesn't send an ON command every motion detection event - so this isn't a great/perfect example...)
Let's focus on the motion sensor M-K and go upward.
M-K is my kitchen motion sensor.
If it is "active", it gets the current mode (function with 3 outputs). O1 = home, O2 = away, O3 = sleep. The function sets home as (true, false, false), sets away as FTF, and sets sleep as FFT.
If O1 or O3 are True, then based on the time, I either turn on the kitchen tube lights or the kitchen wall lights.
If O2 is True (away mode), then I check the state of two switches (Visitor and Pattie Poehl). If either of those are true, then it feeds into the same time based light selection.