# Multiple switches trigger

**URL:** <https://discourse.nodered.org/t/multiple-switches-trigger/63725>\
**Category:** General\
**Created:** [10 June 2022 13:27 UTC](https://discourse.nodered.org/t/multiple-switches-trigger/63725 "2022-06-10T13:27:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![etmomoabc](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/etmomoabc/32/53077_2.png) [@etmomoabc](https://discourse.nodered.org/u/etmomoabc)\
**Post date:** [10 June 2022 13:27 UTC](https://discourse.nodered.org/t/multiple-switches-trigger/63725/1 "2022-06-10T13:27:16Z")

</div>

I need help creating flow for multiple switches.

I have 6 fan switches, zone\_1 - zone\_6, their states are **off** and **fan\_only**.

I wish they could work like this

they are all **off** then go to the next one

either one of them is **fan\_only** go to the other one

Can anyone give me a sample so I can look into it?

thanks!

---

<div class="post-metadata">

**Author:** ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)\
**Post date:** [10 June 2022 13:41 UTC](https://discourse.nodered.org/t/multiple-switches-trigger/63725/2 "2022-06-10T13:41:35Z")

</div>

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

So I recommend to put all in one object - and translate off to false and fan\_only to true.

```auto
[
    {
        "id": "434f43cc4f36f51d",
        "type": "switch",
        "z": "54b226bc.0793e8",
        "name": "OR?",
        "property": "$reduce(payload.*,function($i, $j){$i or $j})",
        "propertyType": "jsonata",
        "rules": [
            {
                "t": "true"
            },
            {
                "t": "false"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 510,
        "y": 3100,
        "wires": [
            [
                "f46360d91a25f936"
            ],
            [
                "05d404c088048d4e"
            ]
        ],
        "info": "# Only one or more properties of an object need to be true.\n\n Only one or more properties of an object need to be true.\n\n`{\n \"Office\": false,\n \"Bedroom\": false,\n \"Living Room Balcony\": false,\n \"Liviueng Room Right Window\": false,\n \"Living Room Left Window\": false\n}`\n\nis false,\n\n`{\n \"Office\": false,\n \"Bedroom\": true,\n \"Living Room Balcony\": false,\n \"Living Room Right Window\": false,\n \"Living Room Left Window\": false\n}`\n\nis true.\n\n# Mindestens eine Eigenschaft des Objektes muss wahr sein.\n\nMindestens eine Eigenschaft des Objektes muss wahr sein.\n\n`{\n \"Büro Balkon\": false,\n \"Schlafzimmer Balkon\": false,\n \"Wohnzimmer Balkon\": false,\n \"Wohnzimmer rechtes Fenster\": false,\n \"Wohnzimmer linkes Fenster\": false\n}`\n\nergibt false,\n\n`{\n \"Büro Balkon\": false,\n \"Schlafzimmer Balkon\": true,\n \"Wohnzimmer Balkon\": false,\n \"Wohnzimmer rechtes Fenster\": false,\n \"Wohnzimmer linkes Fenster\": false\n}`\n\nergibt true (wahr)."
    },
    {
        "id": "33ed66f9f5bfad95",
        "type": "inject",
        "z": "54b226bc.0793e8",
        "name": "all off",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"zone-1\":false,\"zone-2\":false,\"zone-3\":false,\"zone-4\":false,\"zone-5\":false,\"zone-6\":false}",
        "payloadType": "json",
        "x": 330,
        "y": 3080,
        "wires": [
            [
                "434f43cc4f36f51d"
            ]
        ]
    },
    {
        "id": "cbd8f3464cd6739a",
        "type": "inject",
        "z": "54b226bc.0793e8",
        "name": "one on",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"zone-1\":false,\"zone-2\":false,\"zone-3\":true,\"zone-4\":false,\"zone-5\":false,\"zone-6\":false}",
        "payloadType": "json",
        "x": 330,
        "y": 3120,
        "wires": [
            [
                "434f43cc4f36f51d"
            ]
        ]
    },
    {
        "id": "05d404c088048d4e",
        "type": "debug",
        "z": "54b226bc.0793e8",
        "name": "all off",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 670,
        "y": 3120,
        "wires": []
    },
    {
        "id": "f46360d91a25f936",
        "type": "debug",
        "z": "54b226bc.0793e8",
        "name": "one on",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 670,
        "y": 3080,
        "wires": []
    }
]

```

If you dont know how to create the object here a complete flow with translations:

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

```auto

[
    {
        "id": "e88d7f6c78b20c7c",
        "type": "inject",
        "z": "54b226bc.0793e8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "zone-1",
        "payload": "off",
        "payloadType": "str",
        "x": 320,
        "y": 3240,
        "wires": [
            [
                "1bbbe1f8b058ea07"
            ]
        ]
    },
    {
        "id": "8c862811545026c1",
        "type": "inject",
        "z": "54b226bc.0793e8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "zone-2",
        "payload": "off",
        "payloadType": "str",
        "x": 320,
        "y": 3280,
        "wires": [
            [
                "1bbbe1f8b058ea07"
            ]
        ]
    },
    {
        "id": "208509976d8f72f2",
        "type": "inject",
        "z": "54b226bc.0793e8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "zone-3",
        "payload": "off",
        "payloadType": "str",
        "x": 320,
        "y": 3320,
        "wires": [
            [
                "1bbbe1f8b058ea07"
            ]
        ]
    },
    {
        "id": "c6fe73fc70b13cc8",
        "type": "inject",
        "z": "54b226bc.0793e8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "zone-4",
        "payload": "off",
        "payloadType": "str",
        "x": 320,
        "y": 3360,
        "wires": [
            [
                "1bbbe1f8b058ea07"
            ]
        ]
    },
    {
        "id": "746ee55b398e14bc",
        "type": "inject",
        "z": "54b226bc.0793e8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "zone-5",
        "payload": "off",
        "payloadType": "str",
        "x": 320,
        "y": 3400,
        "wires": [
            [
                "1bbbe1f8b058ea07"
            ]
        ]
    },
    {
        "id": "366d285e820bcce1",
        "type": "inject",
        "z": "54b226bc.0793e8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "zone-6",
        "payload": "off",
        "payloadType": "str",
        "x": 320,
        "y": 3440,
        "wires": [
            [
                "1bbbe1f8b058ea07"
            ]
        ]
    },
    {
        "id": "1bbbe1f8b058ea07",
        "type": "change",
        "z": "54b226bc.0793e8",
        "name": "translate",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "off",
                "fromt": "str",
                "to": "false",
                "tot": "bool"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "fan_only",
                "fromt": "str",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 520,
        "y": 3320,
        "wires": [
            [
                "1712a10693436277"
            ]
        ]
    },
    {
        "id": "1712a10693436277",
        "type": "join",
        "z": "54b226bc.0793e8",
        "name": "",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "accumulate": true,
        "timeout": "",
        "count": "1",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 670,
        "y": 3320,
        "wires": [
            [
                "b865c08eb848d36f"
            ]
        ]
    },
    {
        "id": "b865c08eb848d36f",
        "type": "switch",
        "z": "54b226bc.0793e8",
        "name": "OR?",
        "property": "$reduce(payload.*,function($i, $j){$i or $j})",
        "propertyType": "jsonata",
        "rules": [
            {
                "t": "true"
            },
            {
                "t": "false"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 810,
        "y": 3320,
        "wires": [
            [
                "eff51d8e146cd433"
            ],
            [
                "c94c112143c7a353"
            ]
        ],
        "info": "# Only one or more properties of an object need to be true.\n\n Only one or more properties of an object need to be true.\n\n`{\n \"Office\": false,\n \"Bedroom\": false,\n \"Living Room Balcony\": false,\n \"Liviueng Room Right Window\": false,\n \"Living Room Left Window\": false\n}`\n\nis false,\n\n`{\n \"Office\": false,\n \"Bedroom\": true,\n \"Living Room Balcony\": false,\n \"Living Room Right Window\": false,\n \"Living Room Left Window\": false\n}`\n\nis true.\n\n# Mindestens eine Eigenschaft des Objektes muss wahr sein.\n\nMindestens eine Eigenschaft des Objektes muss wahr sein.\n\n`{\n \"Büro Balkon\": false,\n \"Schlafzimmer Balkon\": false,\n \"Wohnzimmer Balkon\": false,\n \"Wohnzimmer rechtes Fenster\": false,\n \"Wohnzimmer linkes Fenster\": false\n}`\n\nergibt false,\n\n`{\n \"Büro Balkon\": false,\n \"Schlafzimmer Balkon\": true,\n \"Wohnzimmer Balkon\": false,\n \"Wohnzimmer rechtes Fenster\": false,\n \"Wohnzimmer linkes Fenster\": false\n}`\n\nergibt true (wahr)."
    },
    {
        "id": "c94c112143c7a353",
        "type": "debug",
        "z": "54b226bc.0793e8",
        "name": "all off",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 970,
        "y": 3340,
        "wires": []
    },
    {
        "id": "eff51d8e146cd433",
        "type": "debug",
        "z": "54b226bc.0793e8",
        "name": "one on",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 970,
        "y": 3300,
        "wires": []
    },
    {
        "id": "d27a59977cd320c6",
        "type": "inject",
        "z": "54b226bc.0793e8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "zone-3",
        "payload": "fan_only",
        "payloadType": "str",
        "x": 300,
        "y": 3480,
        "wires": [
            [
                "1bbbe1f8b058ea07"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [10 June 2022 14:26 UTC](https://discourse.nodered.org/t/multiple-switches-trigger/63725/3 "2022-06-10T14:26:23Z")

</div>

This is a more compact JSONata expression which outputs true or false

```auto
true in $$.payload.*

```

---

<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:** [24 June 2022 14:26 UTC](https://discourse.nodered.org/t/multiple-switches-trigger/63725/4 "2022-06-24T14:26:35Z")

</div>

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