# Different values as one message. Minimize my suggesion?

**URL:** <https://discourse.nodered.org/t/different-values-as-one-message-minimize-my-suggesion/71506>\
**Category:** General\
**Created:** [30 November 2022 14:16 UTC](https://discourse.nodered.org/t/different-values-as-one-message-minimize-my-suggesion/71506 "2022-11-30T14:16:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Herbert](https://avatars.discourse-cdn.com/v4/letter/h/ce73a5/32.png) [@Herbert](https://discourse.nodered.org/u/Herbert)\
**Post date:** [30 November 2022 14:16 UTC](https://discourse.nodered.org/t/different-values-as-one-message-minimize-my-suggesion/71506/1 "2022-11-30T14:16:35Z")

</div>

Hello. I have different machines. Each machine sends a value for "system is OK" . If there is any failure in any system, then its value is changing to failure code.

I have here the nodes and it should works. I have to expand it to all failure siuations... It takes lot of time. Anyway: Have somebody an idea to minimize my nodes, save the trigger nodes?

```auto
[
    {
        "id": "073cf9698e9cb44f",
        "type": "switch",
        "z": "1a0d5b259b9dac43",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "neq",
                "v": "U0-00",
                "vt": "str"
            },
            {
                "t": "else"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 510,
        "y": 2700,
        "wires": [
            [
                "109c48757f0c696e"
            ],
            [
                "635b0c538f583d83"
            ]
        ]
    },
    {
        "id": "81147b764793105f",
        "type": "switch",
        "z": "1a0d5b259b9dac43",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "false"
            },
            {
                "t": "true"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 490,
        "y": 2780,
        "wires": [
            [
                "05662dba8bb3c9f0"
            ],
            [
                "299b9f4e3dfe8a22"
            ]
        ]
    },
    {
        "id": "109c48757f0c696e",
        "type": "trigger",
        "z": "1a0d5b259b9dac43",
        "name": "",
        "op1": "true",
        "op2": "",
        "op1type": "bool",
        "op2type": "nul",
        "duration": "250",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 680,
        "y": 2680,
        "wires": [
            [
                "06bc12ec6d8ad856"
            ]
        ]
    },
    {
        "id": "90c2daec9a3d7dff",
        "type": "inject",
        "z": "1a0d5b259b9dac43",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "U0-00",
        "payloadType": "str",
        "x": 190,
        "y": 2700,
        "wires": [
            [
                "073cf9698e9cb44f"
            ]
        ]
    },
    {
        "id": "0c9c82f998bb8473",
        "type": "inject",
        "z": "1a0d5b259b9dac43",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "U0-01",
        "payloadType": "str",
        "x": 350,
        "y": 2720,
        "wires": [
            [
                "073cf9698e9cb44f"
            ]
        ]
    },
    {
        "id": "730accf3a9d59347",
        "type": "comment",
        "z": "1a0d5b259b9dac43",
        "name": "System is OK",
        "info": "",
        "x": 170,
        "y": 2640,
        "wires": []
    },
    {
        "id": "5c7c98dd9e637963",
        "type": "comment",
        "z": "1a0d5b259b9dac43",
        "name": "System fail",
        "info": "",
        "x": 340,
        "y": 2640,
        "wires": []
    },
    {
        "id": "db4aa68fb442d7b2",
        "type": "inject",
        "z": "1a0d5b259b9dac43",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 350,
        "y": 2800,
        "wires": [
            [
                "81147b764793105f"
            ]
        ]
    },
    {
        "id": "ba7a28d6859659f5",
        "type": "inject",
        "z": "1a0d5b259b9dac43",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "false",
        "payloadType": "bool",
        "x": 190,
        "y": 2780,
        "wires": [
            [
                "81147b764793105f"
            ]
        ]
    },
    {
        "id": "06bc12ec6d8ad856",
        "type": "toggle",
        "z": "1a0d5b259b9dac43",
        "name": "",
        "onOffTopic": "",
        "onValue": "true",
        "onType": "bool",
        "offValue": "false",
        "offType": "bool",
        "toggleTopic": "",
        "toggleValue": "",
        "toggleType": "str",
        "passOnOff": "always",
        "x": 910,
        "y": 2800,
        "wires": [
            [
                "989bf70e48631103"
            ]
        ]
    },
    {
        "id": "989bf70e48631103",
        "type": "debug",
        "z": "1a0d5b259b9dac43",
        "name": "debug 11",
        "active": true,
        "tosidebar": false,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 1020,
        "y": 2700,
        "wires": []
    },
    {
        "id": "635b0c538f583d83",
        "type": "trigger",
        "z": "1a0d5b259b9dac43",
        "name": "",
        "op1": "false",
        "op2": "",
        "op1type": "bool",
        "op2type": "nul",
        "duration": "250",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 680,
        "y": 2720,
        "wires": [
            [
                "06bc12ec6d8ad856"
            ]
        ]
    },
    {
        "id": "299b9f4e3dfe8a22",
        "type": "trigger",
        "z": "1a0d5b259b9dac43",
        "name": "",
        "op1": "true",
        "op2": "",
        "op1type": "bool",
        "op2type": "nul",
        "duration": "250",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 680,
        "y": 2820,
        "wires": [
            [
                "06bc12ec6d8ad856"
            ]
        ]
    },
    {
        "id": "05662dba8bb3c9f0",
        "type": "trigger",
        "z": "1a0d5b259b9dac43",
        "name": "",
        "op1": "false",
        "op2": "",
        "op1type": "bool",
        "op2type": "nul",
        "duration": "250",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 680,
        "y": 2780,
        "wires": [
            [
                "06bc12ec6d8ad856"
            ]
        ]
    }
]

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [30 November 2022 15:56 UTC](https://discourse.nodered.org/t/different-values-as-one-message-minimize-my-suggesion/71506/2 "2022-11-30T15:56:01Z")

</div>

The top switch and two triggers combination does this

```auto
If msg.payload = U0-00 change it to true.
Otherwise, change it to false.

```

You could replace these with a single change node.

The bottom switch and two triggers seem to do nothing at all.

> [@Herbert](#):
>
> Each machine sends a value for "system is OK"

What do those messages look like? How are they delivered?

If I was doing this, I'd use MQTT for the communications and send something like

```auto
msg.payload = {
timestamp: now,
statusCode: 0
}
msg.topic = "status/machine1" // Each machine uses status/ plus the machine id

```

In Node-red you only need a single input point. If a message arrives with payload.statusCode != 0, the message contains everything you need to generate an alert - the machine ID (in msg.topic) and status.

 ![Untitled 3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/6/8680c73b733a0ca44f4046cedc2672aafc6841fd.jpeg)

```auto
[{"id":"003ee46ca1e90bfb","type":"mqtt in","z":"f77cbf8b5446a20e","name":"","topic":"status/#","qos":"2","datatype":"auto-detect","broker":"754230cc.99c44","nl":false,"rap":true,"rh":0,"inputs":0,"x":130,"y":520,"wires":[["5fa93dda258926b4"]]},{"id":"5fa93dda258926b4","type":"switch","z":"f77cbf8b5446a20e","name":"status != 0?","property":"payload.statusCode","propertyType":"msg","rules":[{"t":"neq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":290,"y":520,"wires":[["2210d1e222702cee"]]},{"id":"2210d1e222702cee","type":"rbe","z":"f77cbf8b5446a20e","name":"Block repeats ","func":"rbe","gap":"","start":"","inout":"out","septopics":true,"property":"payload","topi":"topic","x":480,"y":520,"wires":[["dc8ddb059254736c"]]},{"id":"dc8ddb059254736c","type":"debug","z":"f77cbf8b5446a20e","name":"debug 65","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":660,"y":520,"wires":[]},{"id":"754230cc.99c44","type":"mqtt-broker","name":"","broker":"localhost","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]

```

Including a timestamp in the status message gives you the opportunity towrite more code to trigger an alert if a machine fails to send a message for a given period.

---

<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:** [29 January 2023 15:56 UTC](https://discourse.nodered.org/t/different-values-as-one-message-minimize-my-suggesion/71506/3 "2023-01-29T15:56:28Z")

</div>

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