# How to (if not)!

**URL:** https://discourse.nodered.org/t/how-to-if-not/32993
**Category:** General
**Created:** [17 September 2020 12:23 UTC](https://discourse.nodered.org/t/how-to-if-not/32993 "2020-09-17T12:23:44Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![yotti](https://avatars.discourse-cdn.com/v4/letter/y/ad7895/32.png) [@yotti](https://discourse.nodered.org/u/yotti)
#### Post date: [17 September 2020 12:23 UTC](https://discourse.nodered.org/t/how-to-if-not/32993/1 "2020-09-17T12:23:44Z")

</div>

hello help me with this, please  
node1 and node2 are inputs to node3, node4 is the output  
if node3 received 2 msgs from node1 and didn't receive any msg from node2 then node3 send msg  
I'll preheat your help 😅

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [17 September 2020 12:50 UTC](https://discourse.nodered.org/t/how-to-if-not/32993/2 "2020-09-17T12:50:02Z")

</div>

So are the nodes in sequence? i.e. does node1's out go to node2's input and node2's out go to node3 input etc?

What nodes are you using? What have you tried? what does your flow look like?

---

<div class="post-metadata">

### Author: ![yotti](https://avatars.discourse-cdn.com/v4/letter/y/ad7895/32.png) [@yotti](https://discourse.nodered.org/u/yotti)
#### Post date: [17 September 2020 13:17 UTC](https://discourse.nodered.org/t/how-to-if-not/32993/3 "2020-09-17T13:17:40Z")

</div>

node1 is the schedule node that turns on the led in a specific time, node2 is a button that turns off led....the led must be turned off every time ...if not then node3 will send a warning(email) @zenofmud

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [17 September 2020 13:22 UTC](https://discourse.nodered.org/t/how-to-if-not/32993/4 "2020-09-17T13:22:15Z")

</div>

> [@yotti](#):
>
> turns on the led in a specific time

do you mean `at` a specific time?  
so you haven't shown me how the nodes are connected. Please export your flow and attach it to a reply (make wure to use the `</>` option when inserting your flow.

---

<div class="post-metadata">

### Author: ![yotti](https://avatars.discourse-cdn.com/v4/letter/y/ad7895/32.png) [@yotti](https://discourse.nodered.org/u/yotti)
#### Post date: [17 September 2020 13:58 UTC](https://discourse.nodered.org/t/how-to-if-not/32993/5 "2020-09-17T13:58:55Z")

</div>

sorry for my English, LED suppose to work as a reminder, this is something similar for what I mean ...and node3 is what I'm asking about it will do nothing unless the button is not pushed after the LED is turned on by the cron-plus node

```auto
[{"id":"f2ffc9c7.914b38","type":"inject","z":"2acee63b.cfe00a","name":"GPIOinput button","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":620,"y":60,"wires":[["93c462d8.c2baa","7fb6a45f.8ab30c"]]},{"id":"46b7aaa5.4b4af4","type":"cronplus","z":"2acee63b.cfe00a","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"schedule1","topic":"schedule1","payloadType":"default","payload":"","expressionType":"cron","expression":"0 0 */12 * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":620,"y":180,"wires":[["93c462d8.c2baa","7fb6a45f.8ab30c"]]},{"id":"93c462d8.c2baa","type":"debug","z":"2acee63b.cfe00a","name":"GPIOoutput LED","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":870,"y":180,"wires":[]},{"id":"7fb6a45f.8ab30c","type":"function","z":"2acee63b.cfe00a","name":"node3 !!!!!!!!!","func":"\nreturn msg;","outputs":1,"noerr":0,"x":850,"y":60,"wires":[[]]}]

```

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [17 September 2020 16:44 UTC](https://discourse.nodered.org/t/how-to-if-not/32993/6 "2020-09-17T16:44:54Z")

</div>

So if I understand  
1 - cron causes a msg to be sent and turns on the LED  
2 - you can press the button and turn off the LED  
3 - after a set amount of time, if the button has not been pushed, send an email

Is that right?

---

<div class="post-metadata">

### Author: ![yotti](https://avatars.discourse-cdn.com/v4/letter/y/ad7895/32.png) [@yotti](https://discourse.nodered.org/u/yotti)
#### Post date: [17 September 2020 17:51 UTC](https://discourse.nodered.org/t/how-to-if-not/32993/7 "2020-09-17T17:51:06Z")

</div>

that's right

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [17 September 2020 18:53 UTC](https://discourse.nodered.org/t/how-to-if-not/32993/8 "2020-09-17T18:53:38Z")

</div>

What I think you want is to use the `trigger` node. Check out this little sample I came up with:

 ![Screen Shot 2020-09-17 at 2.52.48 PM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/2/b2141fe830a6668cd984367f648e22a5936930c2.png)

```auto
[{"id":"39dfd9f8.b63146","type":"inject","z":"dfab065e.cd792","name":"GPIOinput button (ON)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ON","payloadType":"str","x":300,"y":160,"wires":[["789a3f8c.6221f","706448d1.63aea8"]]},{"id":"789a3f8c.6221f","type":"debug","z":"dfab065e.cd792","name":"GPIOoutput LED","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":610,"y":280,"wires":[]},{"id":"98482bd7.ff5b38","type":"inject","z":"dfab065e.cd792","name":"Manual OFF button","props":[{"p":"payload"},{"p":"reset","v":"reset","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"OFF","payloadType":"str","x":290,"y":280,"wires":[["789a3f8c.6221f","706448d1.63aea8"]]},{"id":"706448d1.63aea8","type":"trigger","z":"dfab065e.cd792","name":"","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"5","extend":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":580,"y":160,"wires":[["866efa9b.bd2ea8"]]},{"id":"e1861431.ef646","type":"debug","z":"dfab065e.cd792","name":"send email","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":970,"y":160,"wires":[]},{"id":"866efa9b.bd2ea8","type":"change","z":"dfab065e.cd792","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"send email","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":160,"wires":[["e1861431.ef646"]]}]

```

---

<div class="post-metadata">

### Author: ![yotti](https://avatars.discourse-cdn.com/v4/letter/y/ad7895/32.png) [@yotti](https://discourse.nodered.org/u/yotti)
#### Post date: [17 September 2020 19:24 UTC](https://discourse.nodered.org/t/how-to-if-not/32993/9 "2020-09-17T19:24:06Z")

</div>

> [@zenofmud](#):
>
> after a set amount of time, if the button has not been pushed, send an email

here it's not "after a set amount of time" it's before another msg from cron comes

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [17 September 2020 21:36 UTC](https://discourse.nodered.org/t/how-to-if-not/32993/10 "2020-09-17T21:36:37Z")

</div>

> [@yotti](#):
>
> here it's not "after a set amount of time" it's before another msg from cron comes

So if I understand you, this is what you want?

initialization msg\_count = 0  
1 - cron sends out a msg - add 1 to msg\_count  
2 - if msg\_count \> 1 send email  
3 - button pushed - set msg\_count = 0

---

<div class="post-metadata">

### Author: ![yotti](https://avatars.discourse-cdn.com/v4/letter/y/ad7895/32.png) [@yotti](https://discourse.nodered.org/u/yotti)
#### Post date: [17 September 2020 21:53 UTC](https://discourse.nodered.org/t/how-to-if-not/32993/11 "2020-09-17T21:53:05Z")

</div>

that's right

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [18 September 2020 00:20 UTC](https://discourse.nodered.org/t/how-to-if-not/32993/12 "2020-09-18T00:20:28Z")

</div>

So make three flows  
Flow 1: an inject node that sets flow.msg\_count to 0 and set the inject node to run on initialization.  
Flow 2: cron to a change node to the led node. In the change node add 1 to flow.msg\_count. I would use JSONata to do it. You could also do this in a function node. Send the output of the change node to test if flow.msg\_count is greater than 1. If so send the email  
Flow 3: a button node connected to a change node that sets flow.msg\_count to 0

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [18 September 2020 09:45 UTC](https://discourse.nodered.org/t/how-to-if-not/32993/13 "2020-09-18T09:45:57Z")

</div>

Hrer is a sample of how you could do it - note flow 2 and 3 are flipped to make the wiring neat:

 ![Screen Shot 2020-09-18 at 5.44.17 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/7/37f02641ce4c6ed9bcefd644b61aabec72d05e67.png)

```auto
[{"id":"ce5936c0.23cb4","type":"inject","z":"dfab065e.cd792","name":"GPIOinput button (ON)","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"str","x":180,"y":600,"wires":[["300441b.d4a8ebe","2db1acd9.d8e834"]]},{"id":"2db1acd9.d8e834","type":"debug","z":"dfab065e.cd792","name":"GPIOoutput LED","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":690,"y":520,"wires":[]},{"id":"ffb6464a.3c4c08","type":"inject","z":"dfab065e.cd792","name":"Manual OFF button","props":[{"p":"payload"},{"p":"reset","v":"reset","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"OFF","payloadType":"str","x":170,"y":520,"wires":[["2db1acd9.d8e834","9c79b450.2a5dd"]]},{"id":"d4262bb4.2163b","type":"debug","z":"dfab065e.cd792","name":"send email","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":680,"wires":[]},{"id":"e3a6562e.9f31","type":"change","z":"dfab065e.cd792","name":"setup email text","rules":[{"t":"set","p":"payload","pt":"msg","to":"send email","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":680,"wires":[["d4262bb4.2163b"]]},{"id":"ebd03041.87b53","type":"inject","z":"dfab065e.cd792","name":"Flow 1: initilization","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":440,"wires":[["9c79b450.2a5dd"]]},{"id":"9c79b450.2a5dd","type":"change","z":"dfab065e.cd792","name":"set flow.msg_count to 0","rules":[{"t":"set","p":"msg_count","pt":"flow","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":440,"wires":[[]]},{"id":"300441b.d4a8ebe","type":"change","z":"dfab065e.cd792","name":"flow.msg_count + 1","rules":[{"t":"set","p":"payload","pt":"msg","to":"$flowContext(\"msg_count\")+1","tot":"jsonata"},{"t":"set","p":"msg_count","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":600,"wires":[["12fe943e.2d1e04","5246ab7d.8daba4"]]},{"id":"12fe943e.2d1e04","type":"debug","z":"dfab065e.cd792","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":600,"wires":[]},{"id":"5246ab7d.8daba4","type":"switch","z":"dfab065e.cd792","name":"msg_count > 1 ?","property":"msg_count","propertyType":"flow","rules":[{"t":"gt","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":450,"y":640,"wires":[["e3a6562e.9f31"]],"outputLabels":["True"]},{"id":"366ff401.f96a84","type":"comment","z":"dfab065e.cd792","name":"Flow 1","info":"","x":120,"y":400,"wires":[]},{"id":"1fea589b.48d64f","type":"comment","z":"dfab065e.cd792","name":"Flow 2","info":"","x":130,"y":560,"wires":[]},{"id":"880bedcd.e2b95","type":"comment","z":"dfab065e.cd792","name":"Flow 3","info":"","x":130,"y":480,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![yotti](https://avatars.discourse-cdn.com/v4/letter/y/ad7895/32.png) [@yotti](https://discourse.nodered.org/u/yotti)
#### Post date: [18 September 2020 10:52 UTC](https://discourse.nodered.org/t/how-to-if-not/32993/14 "2020-09-18T10:52:33Z")

</div>

@zenofmud thank you so much

---

<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: [2 October 2020 10:52 UTC](https://discourse.nodered.org/t/how-to-if-not/32993/15 "2020-10-02T10:52:42Z")

</div>

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