# Sequenced "IF" clauses

**URL:** https://discourse.nodered.org/t/sequenced-if-clauses/47106
**Category:** General
**Created:** [13 June 2021 20:09 UTC](https://discourse.nodered.org/t/sequenced-if-clauses/47106 "2021-06-13T20:09:51Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![RonMa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ronma/32/42531_2.png) [@RonMa](https://discourse.nodered.org/u/RonMa)
#### Post date: [13 June 2021 20:09 UTC](https://discourse.nodered.org/t/sequenced-if-clauses/47106/1 "2021-06-13T20:09:52Z")

</div>

Hi guys,

I´m trying to create a function node with a sequenced "IF" clause. The use case is as follows:

- My hue sensor tracks motion
- Msg.payload "true" (boolean) is sent to the function node
- Depending on the part of the day _AND_ the brightness in the room, different scenes should be activated

This is the flow

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/0/d0d1eadc279f15a6af91aa7e878ba8bab21fbb98.png)

Thats the content of the debug node "Status Conditions"

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/f/cf1b4720aefdf92874e427b252fad822be99a827.png)

And thats the content of my function node "Check Conditions":

```auto
msg.debug = {
    occupancy: msg.payload,
    occupancyType: typeof msg.payload,
    Lights_Off: flow.get("Lights_Off"),
    Lights_OffType: typeof flow.get("Lights_Off"),
    TagModus: global.get("TagModus"),
    TagModusType: typeof global.get("TagModus"),
    AbendModus: global.get("AbendModus"),
    AbendModusType: typeof global.get("AbendModus"),
    NachtModus: global.get("NachtModus"),
    NachtModusType: typeof global.get("NachtModus"),
    Brightness: flow.get("Brightness"),
    BrightnessType: typeof flow.get("Brightness")
}

if (((flow.get("Lights_Off")===true))&&
    ((flow.get("Brightness")<25)))
    {
    if (global.get("TagModus") === true)
        {
        if ((flow.get("Brightness")>12))
            msg.payload = {"scene":"EStwiUv7q69qKtm"};
            return msg;
        }
        else
        {
            msg.payload = {"scene":"57KOzEvv0bVYuq9"};
            return msg;
        }
    if (global.get("AbendModus") === true)
    {
    msg.payload = {"scene":"zTM-LR-NfXhpzWs"};
    return msg;
    }
    else
    {
    msg.payload = null;
    return msg;
    }
}

```

Now what actually _SHOULD_ happen under the circumstances given, is this:  
`msg.payload = {"scene":"zTM-LR-NfXhpzWs"};`

However, what actually _ **DOES** _ happen is this:  
`msg.payload = {"scene":"57KOzEvv0bVYuq9"};`

And now I need your brain power guys to point me where am I going down the wrong path 🤔

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [13 June 2021 20:27 UTC](https://discourse.nodered.org/t/sequenced-if-clauses/47106/2 "2021-06-13T20:27:24Z")

</div>

Add `node.warn()` function calls at appropriate places to work out which test is failing an why. You can find examples of this in [Writing Functions : Node-RED](https://nodered.org/docs/user-guide/writing-functions)

---

<div class="post-metadata">

### Author: ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)
#### Post date: [13 June 2021 20:34 UTC](https://discourse.nodered.org/t/sequenced-if-clauses/47106/3 "2021-06-13T20:34:18Z")

</div>

It looks to me it is working as written. If I'm following the logic correctly given the settings provided you will get to the message payload you indicated then because you have a return msg it will kick you out of the logic and return your value . Thus it will never interrogate for the value of abendmous in your logic

---

<div class="post-metadata">

### Author: ![RonMa](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ronma/32/42531_2.png) [@RonMa](https://discourse.nodered.org/u/RonMa)
#### Post date: [13 June 2021 20:53 UTC](https://discourse.nodered.org/t/sequenced-if-clauses/47106/4 "2021-06-13T20:53:41Z")

</div>

Thanks much @gerry - removed the "return msg" arguments in the if clauses and now it works 🙂

---

<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: [27 June 2021 20:54 UTC](https://discourse.nodered.org/t/sequenced-if-clauses/47106/5 "2021-06-27T20:54:07Z")

</div>

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