Help with multiple conditional flow

Hey, hello there !
I'm new to Node red and have no programing background (nothing beyond setting up a rpi and use it in my home automation).
I have a few basic flows for things like using zigbee buttons and turn on/off lights when a door opens with luminosity and hour conditions, but now I want to make node red trigger some virtual buttons so my Amazon Echo could warn me when I have oppened windows and starts to rain, let me explain:
I have 4 zigbee contact sensors and 1 zigbee water leak sensor (working as rain sensor).
11 virtual buttons to trigger Alexa routines

I'm trying to make:
rain sensor detects rain > node red checks which windows are open > accourding to the oppened windows turn on a specific button > alexa stuff e etc ...

ex: rain > bedroom window open > office window open > turn on "bedroom and office" virtual swich.

I just can't figure out how to make the conditional steps.
So, anyone there to give me some help?

That sounds good.

This is where the switch node comes in. (The yellow one)

When windows are open, (or closed) put a change node at/near the end and set a variable.
Either FLOW or GLOBAL - depending on if all things are on that tab. FLOW keeps things a bit neater.

So if the window is open, set flow.window(name) "OPEN"
When closed set it as "CLOSED".

Get the rain message. -> switch node.
The switch node is something like:

if "flow.window(name)" == "OPEN"

Then the message only goes through the node if the state is "OPEN".

Have a series of them for each window (there are/may be easier ways, but for now) and at the end, if the message gets through: press the virtual button and get alexa to do things.

1 Like

Here is an example of setting widow states in context storage, then when ever leak sensor reports 1 ( rain), it checks the stored window states and reports which widows are open. I have simulated sensor input with inject nodes, and the output is shown in debug node and panel. From there you just have to link to virtual buttons. Hope this example helps you.

[{"id":"e36f4d68.2b4308","type":"inject","z":"5a245aa1.510164","name":"leak 0","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":110,"y":1100,"wires":[["999c4aa9.8da65"]]},{"id":"f12feddc.ac79f","type":"inject","z":"5a245aa1.510164","name":"leak 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":100,"y":1061,"wires":[["999c4aa9.8da65"]]},{"id":"999c4aa9.8da65","type":"switch","z":"5a245aa1.510164","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":260,"y":1060,"wires":[["11f62f2b.3868b9"]]},{"id":"11f62f2b.3868b9","type":"change","z":"5a245aa1.510164","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"[$keys($sift($flowContext(\"sensorstates\"), function($v){\t$v.state=1}))]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":1060,"wires":[["b9df7457.6eb84"]]},{"id":"b9df7457.6eb84","type":"debug","z":"5a245aa1.510164","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"true","targetType":"full","statusVal":"$count(payload) & \"  open \" & $join(payload,\", \")","statusType":"jsonata","x":610,"y":1060,"wires":[]}]
1 Like

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