# Problems with conditional function

**URL:** <https://discourse.nodered.org/t/problems-with-conditional-function/30498>\
**Category:** General\
**Created:** [21 July 2020 17:57 UTC](https://discourse.nodered.org/t/problems-with-conditional-function/30498 "2020-07-21T17:57:56Z")\
**Posts on this page:** 9\
**Page:** 2

<div class="post-metadata">

**Author:** ![lalo](https://avatars.discourse-cdn.com/v4/letter/l/f4b2a3/32.png) [@lalo](https://discourse.nodered.org/u/lalo)\
**Post date:** [22 July 2020 16:48 UTC](https://discourse.nodered.org/t/problems-with-conditional-function/30498/21 "2020-07-22T16:48:31Z")

</div>

Thanks to every one to help me now I realize that my problem is no the conditions I will send you a video, so what I think is happening I'm connection a ESP8266 with the mqtt node so when my flow send open/close/ stop I think it sends to many msgs open open open until one of my conditions is completed so when is time to close the valve my flow sends close but it don't work so I have to turn off my ESP8266 turn on and he makes the close action so. My question is there is way in my if to send just one time a msg.payload "OPEN" like a sleep or something to not send to many msjs. I'm using a delay node with rate limit each 10 seconds but I think is not the best solution

 ![Node-RED _ 192.168.43.47 - Google Chrome 2020-07-22 11-42-12](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/f/9fbeea1c54bd53245a07b1a85df2145edaf79d07.gif)

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [22 July 2020 17:16 UTC](https://discourse.nodered.org/t/problems-with-conditional-function/30498/22 "2020-07-22T17:16:00Z")

</div>

You can use the same [i describe here in answer to your question](https://discourse.nodered.org/t/last-message-comparation-with-new-message/30511) but apply it to the output message and not the input message.  
Otherwise you could also use [the rbe node](https://flows.nodered.org/node/node-red-node-rbe).

Johannes

---

<div class="post-metadata">

**Author:** ![lalo](https://avatars.discourse-cdn.com/v4/letter/l/f4b2a3/32.png) [@lalo](https://discourse.nodered.org/u/lalo)\
**Post date:** [22 July 2020 17:22 UTC](https://discourse.nodered.org/t/problems-with-conditional-function/30498/23 "2020-07-22T17:22:03Z")

</div>

The `> rbe node` is a good solution thanks.

---

<div class="post-metadata">

**Author:** ![lalo](https://avatars.discourse-cdn.com/v4/letter/l/f4b2a3/32.png) [@lalo](https://discourse.nodered.org/u/lalo)\
**Post date:** [23 July 2020 15:57 UTC](https://discourse.nodered.org/t/problems-with-conditional-function/30498/25 "2020-07-23T15:57:21Z")

</div>

I chek it out and my statments the message are send but they never pass the `rbe node` to the `mqtt out node`

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 July 2020 17:10 UTC](https://discourse.nodered.org/t/problems-with-conditional-function/30498/26 "2020-07-23T17:10:24Z")

</div>

What topic + payload do you send through the RBE.

RBE typically works per topic.

e.g.

| index | topic | payload | rbe will pass / block | info |
| --- | --- | --- | --- | --- |
| 1 | OPEN | OPEN | ➡ | because this is the first time RBE has see this `payload` / `topic combination |
| 2 | OPEN | OPEN | ❌ | because `payload` is same value as last time `topic` == "OPEN" |
| 3 | OPEN | OPEN | ❌ | because `payload` is same value as last time `topic` == "OPEN" |
| 4 | CLOSE | CLOSE | ➡ | because this is the first time RBE has see this `payload` / `topic combination |
| 5 | CLOSE | CLOSE | ❌ | because `payload` is same value as last time `topic` == "CLOSE" |
| 6 | OPEN | OPEN | ❌ | because `payload` is same value as last time `topic` == "OPEN " |
| 7 | CLOSE | CLOSE | ❌ | because `payload` is same value as last time `topic` == "CLOSE" |
| 8 | CLOSE | CLOSE | ❌ | because `payload` is same value as last time `topic` == "CLOSE" |
| 9 | CLOSE | _i\_am\_different_ | ➡ | because the `payload` for `topic` "CLOSE" is different to the last time |
| 10 | CLOSE | CLOSE | ➡ | because the `payload` for `topic` "CLOSE" is different to the last time |
| 11 | CLOSE | CLOSE | ❌ | because `payload` is same value as last time `topic` == "CLOSE" |

A better way to handle this is...

| index | topic | payload | rbe will pass / block | info |
| --- | --- | --- | --- | --- |
| 1 | STATUS | OPEN | ➡ | because this is the first time RBE has see this `payload` / `topic combination |
| 2 | STATUS | CLOSE | ➡ | because the `payload` for `topic` "STATUS" has changed |
| 3 | STATUS | OPEN | ➡ | because the `payload` for `topic` "STATUS" has changed |
| 5 | STATUS | CLOSE | ➡ | because the `payload` for `topic` "STATUS" has changed |
| 4 | STATUS | CLOSE | ❌ | because `payload` is same value as last time the RBE seen `topic` "STATUS" |
| 6 | STATUS | OPEN | ➡ | because the `payload` for `topic` "STATUS" has changed |
| 7 | STATUS | CLOSE | ➡ | because the `payload` for `topic` "STATUS" has changed |

Might be your concern?

If not, then I hope this is useful to someone 😃

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 July 2020 17:21 UTC](https://discourse.nodered.org/t/problems-with-conditional-function/30498/28 "2020-07-23T17:21:09Z")

</div>

Dunno.

but could have a good guess if you answer...

> [@Steve-Mcl](#):
>
> What topic + payload do you send through the RBE

and you show debug output of what GOES INTO the RBE?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 July 2020 17:36 UTC](https://discourse.nodered.org/t/problems-with-conditional-function/30498/30 "2020-07-23T17:36:30Z")

</div>

try adding a topic.

You can do it in the function before the RBE like this...

```auto
//add the below line somewhere suitable in your function (before the return msg statement)
msg.topic = "some/suitable/topic"

```

### --- OR ---

add a change node BETWEEN the function & the RBE

SET `msg.topic`  
TO `some/useful/and/meaningful/topic`

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 July 2020 18:02 UTC](https://discourse.nodered.org/t/problems-with-conditional-function/30498/32 "2020-07-23T18:02:12Z")

</div>

I cant tell anything from the partial flow you have posted.

What you posted....

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/9/4945e343eef48a25ed61b434e34916a5b6434a8a.png)

Also, I have no idea what values you have in your globals.  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/d/9d68a716ee533e3610c8ed7e3f7df3e1b78037d1.png)

> [@lalo](#):
>
> so what happend is that it hits the values that I set as max that was 32 but it did't send anything

I have no idea what you are trying to achieve (sorry, I am not gonna read this full post to find out)

If you want someone to help, you really should only post minimum amount of flow/nodes required to replicate your issue & it should include sample data / fixed values etc. Also, you should really state an expected outcome ("it did't send anything" means nothing to me!). I cant guess what you are trying to achieve (its not as obvious as you might think)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [24 July 2020 15:16 UTC](https://discourse.nodered.org/t/problems-with-conditional-function/30498/35 "2020-07-24T15:16:31Z")

</div>

> [@lalo](#):
>
> So no answer

I could say the same to you 😛

Look at my post before yours...

> What is the value of these globals?

> Also, you should really state an expected outcome

your reply was to simply re-posted your full flow.

  

Like i said before.

> If you want someone to help, you really should only post minimum amount of flow/nodes required to replicate your issue & it should include sample data / fixed values

and

> you should really state an expected outcome

and

> I cant guess what you are trying to achieve (its not as obvious as you might think)

[Previous page](https://discourse.nodered.org/t/problems-with-conditional-function/30498.md?page=1)
