# Repeat node not working correctly

**URL:** https://discourse.nodered.org/t/repeat-node-not-working-correctly/6696
**Category:** General
**Created:** [11 January 2019 12:29 UTC](https://discourse.nodered.org/t/repeat-node-not-working-correctly/6696 "2019-01-11T12:29:36Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![IvarMvl](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@IvarMvl](https://discourse.nodered.org/u/IvarMvl)
#### Post date: [11 January 2019 12:29 UTC](https://discourse.nodered.org/t/repeat-node-not-working-correctly/6696/1 "2019-01-11T12:29:36Z")

</div>

repeat node not working correctly doesnt awitch to ELSE output after message passed 3 times  
.  
.  
the node:.

> **[node-red-contrib-repeat](https://www.npmjs.com/package/node-red-contrib-repeat)**
>
> Limit the number of times a message is allowed to pass through the node before it is discarded

  
my code:

```
 [{"id":"cda5a735.9bf3a8","type":"delay","z":"e4d8382f.f4813","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1720,"y":1460,"wires":[["cc1497c7.71a8b"]]},{"id":"3804f703.e84b48","type":"inject","z":"e4d8382f.f4813","name":"test","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1716,"y":1337,"wires":[["c3b110d0.7cce4"]]},{"id":"cc1497c7.71a8b","type":"delay","z":"e4d8382f.f4813","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1723,"y":1520,"wires":[["1571bb17.744cb5"]]},{"id":"1571bb17.744cb5","type":"delay","z":"e4d8382f.f4813","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1722,"y":1581,"wires":[["14559f5a.9fe351"]]},{"id":"14559f5a.9fe351","type":"delay","z":"e4d8382f.f4813","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1721,"y":1633,"wires":[["735f2110.6e7eb"]]},{"id":"735f2110.6e7eb","type":"delay","z":"e4d8382f.f4813","name":"Kenteken wisselen 10 seconde","pauseType":"delay","timeout":"10","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1794,"y":1707,"wires":[["cf078ebb.ac14f8"]]},{"id":"cf078ebb.ac14f8","type":"repeat","z":"e4d8382f.f4813","name":"","repetitions":"3","elseOutput":true,"outputs":2,"x":1744,"y":1747,"wires":[["c3b110d0.7cce4"],["87a5150e.56c37"]]},{"id":"c3b110d0.7cce4","type":"ui_button","z":"e4d8382f.f4813","name":"Normaal inrijden","group":"1c37e01a.713448","order":2,"width":"6","height":"1","passthru":true,"label":"Normaal inrijden","color":"","bgcolor":"","icon":"","payload":"true","payloadType":"bool","topic":"","x":1916,"y":1337,"wires":[["f26e058f.29eed8","da268118.201098"]]},{"id":"9b6666c4.c46e3","type":"gate","z":"e4d8382f.f4813","name":"gate","controlTopic":"control","defaultState":"closed","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":1856,"y":1417,"wires":[["cda5a735.9bf3a8"]]},{"id":"437d3303.4dfc94","type":"rpi-gpio in","z":"e4d8382f.f4813","name":"","pin":"16","intype":"tri","debounce":"25","read":false,"x":1576,"y":1417,"wires":[["45df1a9d.bd0df4"]]},{"id":"45df1a9d.bd0df4","type":"switch","z":"e4d8382f.f4813","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1716,"y":1417,"wires":[["9b6666c4.c46e3"]]},{"id":"87a5150e.56c37","type":"change","z":"e4d8382f.f4813","name":"Reset","rules":[{"t":"set","p":"payload","pt":"msg","to":"default","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1716,"y":1377,"wires":[["9b6666c4.c46e3"]]},{"id":"f26e058f.29eed8","type":"change","z":"e4d8382f.f4813","name":"Open","rules":[{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1576,"y":1377,"wires":[["9b6666c4.c46e3"]]},{"id":"3d30eae.c762416","type":"inject","z":"e4d8382f.f4813","name":"test Pin","topic":"","payload":"1","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1556,"y":1457,"wires":[[]]},{"id":"da268118.201098","type":"ui_text","z":"e4d8382f.f4813","group":"defe4730.2123f8","order":0,"width":0,"height":0,"name":"","label":"output to trigger pin 16","format":"{{msg.payload}}","layout":"row-spread","x":2200,"y":1340,"wires":[]},{"id":"1c37e01a.713448","type":"ui_group","z":"","name":"dubbele In/Uit","tab":"13f7e980.24574f","order":1,"disp":true,"width":"6","collapse":false},{"id":"defe4730.2123f8","type":"ui_group","z":"e4d8382f.f4813","name":"Click","tab":"","order":1,"disp":true,"width":"5"},{"id":"13f7e980.24574f","type":"ui_tab","z":"","name":"Slagboom Sim","icon":"dashboard"}]

```

thanks in advance,

.  
Ivar

---

<div class="post-metadata">

### Author: ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)
#### Post date: [11 January 2019 12:48 UTC](https://discourse.nodered.org/t/repeat-node-not-working-correctly/6696/2 "2019-01-11T12:48:31Z")

</div>

> [@IvarMvl](#):
>
> repeat node not working correctly

If the node is not working correctly, wouldn't it be better for you to raise an issue with the node author?

---

<div class="post-metadata">

### Author: ![IvarMvl](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@IvarMvl](https://discourse.nodered.org/u/IvarMvl)
#### Post date: [11 January 2019 12:54 UTC](https://discourse.nodered.org/t/repeat-node-not-working-correctly/6696/3 "2019-01-11T12:54:08Z")

</div>

I thought, maybe someone here would know the answer  
and maybe it is working correctly, that im doing it wrong

---

<div class="post-metadata">

### Author: ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)
#### Post date: [11 January 2019 13:00 UTC](https://discourse.nodered.org/t/repeat-node-not-working-correctly/6696/4 "2019-01-11T13:00:44Z")

</div>

@IvarMvl

This node hasn't been updated for more than 3 years.  
But it's a simple node, so you need to count the number of msgs until 3 and get an output?  
Maybe I can post another solution.

---

<div class="post-metadata">

### Author: ![IvarMvl](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@IvarMvl](https://discourse.nodered.org/u/IvarMvl)
#### Post date: [11 January 2019 13:05 UTC](https://discourse.nodered.org/t/repeat-node-not-working-correctly/6696/5 "2019-01-11T13:05:11Z")

</div>

so when you put the node in a closed loop it loops 3 times through the fist output and the fouth time its meant to send the message to a second output out of the same node so it can break off

---

<div class="post-metadata">

### Author: ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)
#### Post date: [11 January 2019 13:08 UTC](https://discourse.nodered.org/t/repeat-node-not-working-correctly/6696/6 "2019-01-11T13:08:45Z")

</div>

> [@IvarMvl](#):
>
> so when you put the node in a closed loop it loops 3 times through the fist output and the fouth time its meant to send the message to a second output out of the same node so it can break off

Do you need the first output? it seems to me that it's only used for the \_loopController.

---

<div class="post-metadata">

### Author: ![IvarMvl](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@IvarMvl](https://discourse.nodered.org/u/IvarMvl)
#### Post date: [11 January 2019 13:16 UTC](https://discourse.nodered.org/t/repeat-node-not-working-correctly/6696/7 "2019-01-11T13:16:14Z")

</div>

this is what the node help said

.  
Allow a message to pass through this node for an specific number of times, after which it will be discarded, unveiling the ability to limit the loops over a flow to N times.

If `Else Output` is activated, a second output is enabled that will receive the message once when the repetitions have been exhausted

---

<div class="post-metadata">

### Author: ![cflurin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cflurin/32/29_2.png) [@cflurin](https://discourse.nodered.org/u/cflurin)
#### Post date: [11 January 2019 13:30 UTC](https://discourse.nodered.org/t/repeat-node-not-working-correctly/6696/8 "2019-01-11T13:30:47Z")

</div>

A simple function (set Outputs to 2) to replace the repeat node (not really sure it's what you need)

```auto
var count = context.get('count') || 0;
var msg2 = {};

if (count < 3) {
    count++;
    msg2 = null;
} else {
    count = 0;
    msg2 = msg;
    msg = null;
}

context.set('count', count);

return [msg, msg2];

```

---

<div class="post-metadata">

### Author: ![IvarMvl](https://avatars.discourse-cdn.com/v4/letter/i/3e96dc/32.png) [@IvarMvl](https://discourse.nodered.org/u/IvarMvl)
#### Post date: [11 January 2019 13:44 UTC](https://discourse.nodered.org/t/repeat-node-not-working-correctly/6696/9 "2019-01-11T13:44:04Z")

</div>

exactely what I needed thank you.
