# Probleme lecture conditions (Problem reading conditions)

**URL:** https://discourse.nodered.org/t/probleme-lecture-conditions-problem-reading-conditions/24203
**Category:** General
**Created:** [4 April 2020 06:21 UTC](https://discourse.nodered.org/t/probleme-lecture-conditions-problem-reading-conditions/24203 "2020-04-04T06:21:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![micke007](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@micke007](https://discourse.nodered.org/u/micke007)
#### Post date: [4 April 2020 06:21 UTC](https://discourse.nodered.org/t/probleme-lecture-conditions-problem-reading-conditions/24203/1 "2020-04-04T06:21:47Z")

</div>

bonjours a tous,  
quand je j'appuie sur A puis sur B ma variable "compteur" ne s'incremente pas  
alors que dans l'autre sens (B puis A) mon "compteur" monte  
quelqu'un pourrais me dire comment faire pour que ça monte peut importe le sens d'appuie

merci de votre aide

* * *

Hello everyone,  
when I press A then B my variable "counter" does not increment  
while in the other direction (B then A) my "counter" goes up  
someone could tell me how to make it go up no matter what sense of support

Thank you for your help

```auto
[{"id":"3861b0a.555ca5","type":"function","z":"3dafcb6f.c00894","name":"","func":"if (msg.payload == \"0\") {\n msg.fourche = \"AC\"\nreturn msg;\n} else if (msg.payload == \"1\") {\n msg.fourche = \"AD\"\nreturn msg;\n}","outputs":1,"noerr":0,"x":290,"y":380,"wires":[["46999e10.3514a"]]},{"id":"42a272a2.c6224c","type":"function","z":"3dafcb6f.c00894","name":"","func":"if (msg.payload == \"0\") {\n msg.fourchebis = \"BC\"\nreturn msg;\n} else if (msg.payload == \"1\") {\n msg.fourchebis = \"BD\"\nreturn msg;\n}","outputs":1,"noerr":0,"x":290,"y":420,"wires":[["46999e10.3514a"]]},{"id":"46999e10.3514a","type":"join","z":"3dafcb6f.c00894","name":"","mode":"custom","build":"array","property":"","propertyType":"full","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":470,"y":400,"wires":[["3257806d.a6861"]]},{"id":"3257806d.a6861","type":"function","z":"3dafcb6f.c00894","name":"","func":"var fourche = msg.payload[1].fourche;\nvar fourchebis = msg.payload[0].fourchebis ;\nif ((fourche === \"AC\") && (fourchebis === \"BC\")){\n msg.alarm = \"on\"\nreturn msg;\n} else {\nmsg.alarm = \"off\"\n return msg;\n}","outputs":1,"noerr":0,"x":630,"y":400,"wires":[["2a21901d.6cbf1"]]},{"id":"ac38e032.d8f16","type":"debug","z":"3dafcb6f.c00894","name":"compte","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":980,"y":400,"wires":[]},{"id":"eb2e0580.8b91d8","type":"inject","z":"3dafcb6f.c00894","name":"0 A","topic":"","payload":"0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":380,"wires":[["3861b0a.555ca5"]]},{"id":"7edb3e4.be15ec","type":"inject","z":"3dafcb6f.c00894","name":"0 B","topic":"","payload":"0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":420,"wires":[["42a272a2.c6224c"]]},{"id":"2a21901d.6cbf1","type":"function","z":"3dafcb6f.c00894","name":"compteur","func":"// Get the current value of the 'count' context property - default to 0\nvar compte = flow.get(\"compte\")||0;\n\n//if (msg.topic === \"init\") {\n // set its value locally\n// count = msg.payload;\n//} \nif ((msg.alarm === \"on\") && (compte< 30)) {\n compte++;\n} else if (msg.alarm === \"off\") {\n compte=0;\n}else if (compte === 30){\n msg.alarmstatu = \"go\";\n compte = 0;\n}else if (compte > 30){\ncompte = 0;\n}\nflow.set('compte',compte);\nmsg.payload = compte;\nreturn msg;","outputs":1,"noerr":0,"x":820,"y":400,"wires":[["ac38e032.d8f16"]]}]

```

---

<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: [4 April 2020 08:03 UTC](https://discourse.nodered.org/t/probleme-lecture-conditions-problem-reading-conditions/24203/2 "2020-04-04T08:03:46Z")

</div>

Your problem is that the join is putting the msgs into the msg.payload array based on the order they arrive, while your function is expecting msg A to always be the first msg in the array. Instead, try creating a key:value object. Here is your flow setup that way.

====

Votre problème est que la jointure place les msgs dans le tableau msg.payload en fonction de l'ordre dans lequel ils arrivent, tandis que votre fonction s'attend à ce que le msg A soit toujours le premier msg du tableau. Essayez plutôt de créer un objet clé: valeur. Voici votre configuration de flux de cette façon.

```auto
[{"id":"d5e7d88d.c97008","type":"function","z":"ce29dad6.d93a2","name":"","func":"msg.topic = \"fourche\"\nif (msg.payload == \"0\") {\n msg.fourche = \"AC\"\nreturn msg;\n} else if (msg.payload == \"1\") {\n msg.fourche = \"AD\"\nreturn msg;\n}","outputs":1,"noerr":0,"x":250,"y":60,"wires":[["f378914a.bf2608"]]},{"id":"815fddb4.e24068","type":"function","z":"ce29dad6.d93a2","name":"","func":"msg.topic = \"fourchebis\"\nif (msg.payload == \"0\") {\n msg.fourchebis = \"BC\"\nreturn msg;\n} else if (msg.payload == \"1\") {\n msg.fourchebis = \"BD\"\nreturn msg;\n}","outputs":1,"noerr":0,"x":250,"y":100,"wires":[["f378914a.bf2608"]]},{"id":"f378914a.bf2608","type":"join","z":"ce29dad6.d93a2","name":"","mode":"custom","build":"object","property":"","propertyType":"full","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":430,"y":80,"wires":[["7a3edf9c.8da578","32ba0887.e91788"]]},{"id":"7a3edf9c.8da578","type":"function","z":"ce29dad6.d93a2","name":"","func":"var fourche = msg.payload.fourche.fourche;\nvar fourchebis = msg.payload.fourchebis.fourchebis ;\nif ((fourche === \"AC\") && (fourchebis === \"BC\")){\n msg.alarm = \"on\"\nreturn msg;\n} else {\nmsg.alarm = \"off\"\n return msg;\n}","outputs":1,"noerr":0,"x":250,"y":180,"wires":[["6500ad6e.8f0144","e7efe8ff.48a9e8"]]},{"id":"db9ce295.782ce","type":"debug","z":"ce29dad6.d93a2","name":"compte","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":440,"y":240,"wires":[]},{"id":"97372c0.6cb2fd8","type":"inject","z":"ce29dad6.d93a2","name":"0 A","topic":"","payload":"0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":60,"wires":[["d5e7d88d.c97008"]]},{"id":"7892ee8f.3bd818","type":"inject","z":"ce29dad6.d93a2","name":"0 B","topic":"","payload":"0","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":100,"wires":[["815fddb4.e24068"]]},{"id":"6500ad6e.8f0144","type":"function","z":"ce29dad6.d93a2","name":"compteur","func":"// Get the current value of the 'count' context property - default to 0\nvar compte = flow.get(\"compte\")||0;\n\n//if (msg.topic === \"init\") {\n // set its value locally\n// count = msg.payload;\n//} \nif ((msg.alarm === \"on\") && (compte< 30)) {\n compte++;\n} else if (msg.alarm === \"off\") {\n compte=0;\n}else if (compte === 30){\n msg.alarmstatu = \"go\";\n compte = 0;\n}else if (compte > 30){\ncompte = 0;\n}\nflow.set('compte',compte);\nmsg.payload = compte;\nreturn msg;","outputs":1,"noerr":0,"x":260,"y":240,"wires":[["db9ce295.782ce"]]},{"id":"e7efe8ff.48a9e8","type":"debug","z":"ce29dad6.d93a2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":450,"y":180,"wires":[]},{"id":"32ba0887.e91788","type":"debug","z":"ce29dad6.d93a2","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":590,"y":80,"wires":[]}]

```

p.s. veuillez utiliser google translate pour traduire votre message en anglais lors de la publication. Merci!

* * *

p.s. please use google translate to translate your message to english when posting. Thanks!

---

<div class="post-metadata">

### Author: ![micke007](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@micke007](https://discourse.nodered.org/u/micke007)
#### Post date: [4 April 2020 15:07 UTC](https://discourse.nodered.org/t/probleme-lecture-conditions-problem-reading-conditions/24203/3 "2020-04-04T15:07:16Z")

</div>

thank you so much  
for this information

---

<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: [3 June 2020 15:07 UTC](https://discourse.nodered.org/t/probleme-lecture-conditions-problem-reading-conditions/24203/4 "2020-06-03T15:07:20Z")

</div>

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