# Assistance with logic for flow, please. :)

**URL:** <https://discourse.nodered.org/t/assistance-with-logic-for-flow-please/48143>\
**Category:** General\
**Created:** [7 July 2021 16:59 UTC](https://discourse.nodered.org/t/assistance-with-logic-for-flow-please/48143 "2021-07-07T16:59:27Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![daxliniere](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daxliniere/32/42187_2.png) [@daxliniere](https://discourse.nodered.org/u/daxliniere)\
**Post date:** [7 July 2021 16:59 UTC](https://discourse.nodered.org/t/assistance-with-logic-for-flow-please/48143/1 "2021-07-07T16:59:27Z")

</div>

Hey everyone,  
I was hoping to get some direction on how to create this logical flow in NR. It's a system with 2 binary inputs and a camera for still image capture. I have the image capture stuff working already and the input monitoring is already set up and in-use in a much more simple setup than what I'd ultimately like to achieve.  
These are the two sequences I'm hoping to create in NR.

_Sequence 1:_  
Input\_A goes low -\> start frame capture, every 3 seconds until Input\_A goes high AND (Input\_B is high for 3 seconds **OR** 20 seconds passes without Input\_B going high).  
Send images in notification.

_Sequence 2:_  
Input\_B goes high -\> start frame capture, every 1 seconds until Input\_A goes low, then every 3 seconds until Input\_A goes high, then 2 more frames.  
Send images in notification unless Input\_A doesn't go low within 60 seconds -\> discard images. (false trigger)

Any examples would be greatly appreciated!

All the best,  
Dax.

---

<div class="post-metadata">

**Author:** ![Gunner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gunner/32/43582_2.png) [@Gunner](https://discourse.nodered.org/u/Gunner)\
**Post date:** [7 July 2021 23:54 UTC](https://discourse.nodered.org/t/assistance-with-logic-for-flow-please/48143/2 "2021-07-07T23:54:10Z")

</div>

> [@daxliniere](#):
>
> I have the image capture stuff working already and the input monitoring is already set up

It might encourage involvement if you show what you already have that works, and explain what you have tried that may not have worked, so as to better understand your question.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [8 July 2021 00:51 UTC](https://discourse.nodered.org/t/assistance-with-logic-for-flow-please/48143/3 "2021-07-08T00:51:03Z")

</div>

> [@daxliniere](#):
>
> Input\_A goes low -\> start frame capture, every 3 seconds until Input\_A goes high AND (Input\_B is high for 3 seconds **OR** 20 seconds passes without Input\_B going high).  
> Send images in notification.

Maybe re-word that.

My take:  
When `Input_A` goes low:  
capture a frame every 3 seconds until `Input_A` goes high **AND** - then it all falls over.

Maybe a _Truth table_? If possible.

It is just you haven't shown all the other options.  
What happens if they aren't met?

Just I feel that without knowing that: it is difficult to work out what you actually want/need.

I'll try it this way:

Once started - taking pictures ever 3 seconds:  
Continue until: **either** `Input_A` is high **AND** either `Input_B` is high for `3` seconds **OR** `20` seconds passes by.  
No need to mention `Input_B` condition. That only confused silly people like me.

Maybe better worded like this:  
(Once started)  
continue until:  
for `20` seconds **OR**  
`Input_A` goes hight **AND** `Input_B` is hight for \>`3` seconds

To me that is clearer.

---

<div class="post-metadata">

**Author:** ![daxliniere](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daxliniere/32/42187_2.png) [@daxliniere](https://discourse.nodered.org/u/daxliniere)\
**Post date:** [9 July 2021 08:11 UTC](https://discourse.nodered.org/t/assistance-with-logic-for-flow-please/48143/4 "2021-07-09T08:11:55Z")

</div>

Hey Gunner and Andrew,  
Thanks for your replies. The problem is that I don't even know how to start this. The very first 'gate' is actually two choices: Input\_A goes low, triggering sequence 1 or Input\_B goes high, triggering sequence 2. Once one of those sequences has started, it must follow to the end (which could be the time-out)

These inputs are switches (NC and NO) on GPIO pins.

Does that help at all?

Cheers,  
Dax.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [10 July 2021 02:30 UTC](https://discourse.nodered.org/t/assistance-with-logic-for-flow-please/48143/5 "2021-07-10T02:30:41Z")

</div>

How about this?

It is the best I can work out from your description.

```auto
[{"id":"9ee519c1.fc7f88","type":"inject","z":"3a01457a.3b59aa","name":"HIGH","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":170,"y":120,"wires":[["9e110a.d1807ef8"]]},{"id":"4851b0f0.7a7488","type":"inject","z":"3a01457a.3b59aa","name":"LOW","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":170,"y":160,"wires":[["9e110a.d1807ef8"]]},{"id":"bb97be99.aa5a8","type":"comment","z":"3a01457a.3b59aa","name":"Input A","info":"","x":160,"y":80,"wires":[]},{"id":"13888054.c319d","type":"inject","z":"3a01457a.3b59aa","name":"HIGH","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":170,"y":280,"wires":[["d47c6d90.701708"]]},{"id":"7a94ae8.ca2245","type":"inject","z":"3a01457a.3b59aa","name":"LOW","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":170,"y":320,"wires":[["d47c6d90.701708"]]},{"id":"9822aad7.d67788","type":"comment","z":"3a01457a.3b59aa","name":"Input B","info":"","x":160,"y":240,"wires":[]},{"id":"9e110a.d1807ef8","type":"switch","z":"3a01457a.3b59aa","name":"LOW?","property":"payload","propertyType":"msg","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":false,"outputs":2,"x":370,"y":140,"wires":[["495a8a95.48b55c","662cb4cb.26804c"],["fc41e5b6.40aa68"]]},{"id":"495a8a95.48b55c","type":"change","z":"3a01457a.3b59aa","name":"Start","rules":[{"t":"set","p":"payload","pt":"msg","to":"start","tot":"str"},{"t":"set","p":"A","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":100,"wires":[["a828ad32.a7cc9"]]},{"id":"a828ad32.a7cc9","type":"trigger","z":"3a01457a.3b59aa","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"-3","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":710,"y":100,"wires":[["9efdb5c8.acf3b8"]]},{"id":"3536f3e9.72958c","type":"trigger","z":"3a01457a.3b59aa","name":"","op1":"","op2":"RESET","op1type":"nul","op2type":"str","duration":"3","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":500,"y":270,"wires":[["d6467993.2bb5a8"]]},{"id":"d47c6d90.701708","type":"switch","z":"3a01457a.3b59aa","name":"High?","property":"payload","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":360,"y":300,"wires":[["3536f3e9.72958c"],["f712364.4c25a48"]]},{"id":"9efdb5c8.acf3b8","type":"debug","z":"3a01457a.3b59aa","name":"What you want?","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":100,"wires":[]},{"id":"372f3154.7bbd96","type":"change","z":"3a01457a.3b59aa","name":"Reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":220,"wires":[["a828ad32.a7cc9"]]},{"id":"f712364.4c25a48","type":"change","z":"3a01457a.3b59aa","name":"Reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":320,"wires":[["3536f3e9.72958c"]]},{"id":"d6467993.2bb5a8","type":"switch","z":"3a01457a.3b59aa","name":"A True?","property":"A","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":650,"y":270,"wires":[["372f3154.7bbd96"]]},{"id":"fc41e5b6.40aa68","type":"change","z":"3a01457a.3b59aa","name":"","rules":[{"t":"set","p":"A","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":180,"wires":[[]]},{"id":"662cb4cb.26804c","type":"trigger","z":"3a01457a.3b59aa","name":"","op1":"","op2":"TIMEOUT","op1type":"nul","op2type":"str","duration":"20","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":450,"y":220,"wires":[["372f3154.7bbd96"]]}]

```

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [10 July 2021 05:41 UTC](https://discourse.nodered.org/t/assistance-with-logic-for-flow-please/48143/6 "2021-07-10T05:41:29Z")

</div>

Have a look at the Ultimate Boolean nodes - i think they might help here for what you are trying to achieve.

Craig

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [10 July 2021 12:07 UTC](https://discourse.nodered.org/t/assistance-with-logic-for-flow-please/48143/7 "2021-07-10T12:07:25Z")

</div>

Does this achieve your Sequence 1?

 ![Untitled 2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/b/bb229b53a899204fa64c465daf080834f3f863b7.jpeg)

```auto
[{"id":"d00ece9ff8864fe0","type":"group","z":"c5b102c3ffa0250d","name":"Input A low - start capturing for 20s.","style":{"label":true},"nodes":["97954d8e600b218d","3ba14277e31ea3c3","6afc4fe6aee82864","8e3c2228fc93aa9b","383f69ddb8a3eb80","13eb537361594c82","8b4efc3ec3c93845"],"x":14,"y":19,"w":952,"h":162},{"id":"97954d8e600b218d","type":"rpi-gpio in","z":"c5b102c3ffa0250d","g":"d00ece9ff8864fe0","name":"input A","pin":"11","intype":"tri","debounce":"25","read":false,"x":90,"y":60,"wires":[["6afc4fe6aee82864"]]},{"id":"3ba14277e31ea3c3","type":"trigger","z":"c5b102c3ffa0250d","g":"d00ece9ff8864fe0","name":"","op1":"GO","op2":"STOP","op1type":"str","op2type":"str","duration":"20","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":610,"y":60,"wires":[["8e3c2228fc93aa9b"]]},{"id":"6afc4fe6aee82864","type":"switch","z":"c5b102c3ffa0250d","g":"d00ece9ff8864fe0","name":"Low?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":260,"y":60,"wires":[["3ba14277e31ea3c3"]]},{"id":"8e3c2228fc93aa9b","type":"debug","z":"c5b102c3ffa0250d","g":"d00ece9ff8864fe0","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":60,"wires":[]},{"id":"383f69ddb8a3eb80","type":"inject","z":"c5b102c3ffa0250d","g":"d00ece9ff8864fe0","name":"Test (0)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":110,"y":100,"wires":[["6afc4fe6aee82864"]]},{"id":"13eb537361594c82","type":"inject","z":"c5b102c3ffa0250d","g":"d00ece9ff8864fe0","name":"Test (1)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":110,"y":140,"wires":[["6afc4fe6aee82864"]]},{"id":"8b4efc3ec3c93845","type":"change","z":"c5b102c3ffa0250d","g":"d00ece9ff8864fe0","name":"reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":140,"wires":[["3ba14277e31ea3c3"]]},{"id":"d40c41ec3ba7eac3","type":"group","z":"c5b102c3ffa0250d","name":"Input B high for 3s: stop capture and cancel 20s countdown","style":{"label":true},"nodes":["a7ea1960f76d12e0","43d32d413f9a1b26","fe6b4ce53413e7e8","673c988711b7533b","d39d90269b43ecdc","5217aeaedbbfbadb"],"x":14,"y":199,"w":692,"h":162},{"id":"a7ea1960f76d12e0","type":"rpi-gpio in","z":"c5b102c3ffa0250d","g":"d40c41ec3ba7eac3","name":"input B","pin":"13","intype":"tri","debounce":"25","read":false,"x":90,"y":240,"wires":[["fe6b4ce53413e7e8"]]},{"id":"43d32d413f9a1b26","type":"trigger","z":"c5b102c3ffa0250d","g":"d40c41ec3ba7eac3","name":"","op1":"","op2":"STOP","op1type":"nul","op2type":"str","duration":"3","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":620,"y":240,"wires":[["8e3c2228fc93aa9b","8b4efc3ec3c93845"]]},{"id":"fe6b4ce53413e7e8","type":"switch","z":"c5b102c3ffa0250d","g":"d40c41ec3ba7eac3","name":"High?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":270,"y":240,"wires":[["43d32d413f9a1b26"],["5217aeaedbbfbadb"]]},{"id":"673c988711b7533b","type":"inject","z":"c5b102c3ffa0250d","g":"d40c41ec3ba7eac3","name":"Test (0)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":110,"y":280,"wires":[["fe6b4ce53413e7e8"]]},{"id":"d39d90269b43ecdc","type":"inject","z":"c5b102c3ffa0250d","g":"d40c41ec3ba7eac3","name":"Test (1)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":110,"y":320,"wires":[["fe6b4ce53413e7e8"]]},{"id":"5217aeaedbbfbadb","type":"change","z":"c5b102c3ffa0250d","g":"d40c41ec3ba7eac3","name":"reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":260,"wires":[["43d32d413f9a1b26"]]}]

```

---

<div class="post-metadata">

**Author:** ![daxliniere](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daxliniere/32/42187_2.png) [@daxliniere](https://discourse.nodered.org/u/daxliniere)\
**Post date:** [16 July 2021 12:27 UTC](https://discourse.nodered.org/t/assistance-with-logic-for-flow-please/48143/8 "2021-07-16T12:27:15Z")

</div>

Hey everyone, sorry for the super slow reply, we have a newborn at home, so it's been hard to find a moment to go through these proposed solutions.

I want to sit down and go through them properly so I can a) solve the problem and b) learn from these examples.

@Trying_to_learn and @jbudd, thank you both so much for your time to help me with this.

@craigcurtin, ahh! Those nodes looks awesome. I just read the descriptions; they sound like something I will use a lot. Thank you!!

Speak soon! 😃  
-Dax.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [14 September 2021 12:27 UTC](https://discourse.nodered.org/t/assistance-with-logic-for-flow-please/48143/9 "2021-09-14T12:27:48Z")

</div>

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