How is data compared dynamically?

Hello. I need to send data: which comes constantly 1 time per second and arrives 1 per second (let's assume that this voltage is the blue arrow) and compare with what I set using the slider (green arrow), that is, a dynamic comparison. I compare what I set with the green arrow with the constantly incoming data (blue arrow). How to do it? I hope I explained it correctly?

You need both values in the same msg to be able to compare them.

See this article in the cookbook for an example of how to join messages into one object.

Alternatively use a change node to store your slider value as a flow context variable.
Then your switch node can compare msg.payload with flow.slider

image

Your suggestion doesn't work

[
    {
        "id": "ad6d68105b95aa5b",
        "type": "debug",
        "z": "ded344b4e00b625c",
        "name": "1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1770,
        "y": 740,
        "wires": []
    },
    {
        "id": "c48f4559ab67834d",
        "type": "switch",
        "z": "ded344b4e00b625c",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "lt",
                "v": "payload1",
                "vt": "flow"
            },
            {
                "t": "gt",
                "v": "payload1",
                "vt": "flow"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 1570,
        "y": 760,
        "wires": [
            [
                "ad6d68105b95aa5b"
            ],
            [
                "7eea7e3314087853"
            ]
        ]
    },
    {
        "id": "472043f0a568677c",
        "type": "inject",
        "z": "ded344b4e00b625c",
        "name": "219",
        "props": [
            {
                "p": "payload1",
                "v": "219",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 1370,
        "y": 580,
        "wires": [
            [
                "b8e17ff1ec616aa5"
            ]
        ]
    },
    {
        "id": "9570b5282cb4ed47",
        "type": "inject",
        "z": "ded344b4e00b625c",
        "name": "229",
        "props": [
            {
                "p": "payload1",
                "v": "229",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 1370,
        "y": 660,
        "wires": [
            [
                "b8e17ff1ec616aa5"
            ]
        ]
    },
    {
        "id": "deb1babb0c1e12c9",
        "type": "inject",
        "z": "ded344b4e00b625c",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "220",
        "payloadType": "num",
        "x": 1370,
        "y": 720,
        "wires": [
            [
                "c48f4559ab67834d"
            ]
        ]
    },
    {
        "id": "2d39a7a94b5ca670",
        "type": "inject",
        "z": "ded344b4e00b625c",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "228",
        "payloadType": "num",
        "x": 1370,
        "y": 780,
        "wires": [
            [
                "c48f4559ab67834d"
            ]
        ]
    },
    {
        "id": "b8e17ff1ec616aa5",
        "type": "change",
        "z": "ded344b4e00b625c",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "payload1",
                "pt": "flow",
                "to": "payload1",
                "tot": "flow"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1570,
        "y": 600,
        "wires": [
            [
                "8226cb0bd6bf6409"
            ]
        ]
    },
    {
        "id": "8226cb0bd6bf6409",
        "type": "debug",
        "z": "ded344b4e00b625c",
        "name": "0",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1770,
        "y": 600,
        "wires": []
    },
    {
        "id": "7eea7e3314087853",
        "type": "debug",
        "z": "ded344b4e00b625c",
        "name": "2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1750,
        "y": 780,
        "wires": []
    },
    {
        "id": "9d67e9a9269f544a",
        "type": "inject",
        "z": "ded344b4e00b625c",
        "name": "221",
        "props": [
            {
                "p": "payload1",
                "v": "221",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 1370,
        "y": 620,
        "wires": [
            [
                "b8e17ff1ec616aa5"
            ]
        ]
    }
]

The ui slider node sends it's output as msg.payload so in your change node you need to copy msg.payload to flow.payload1

Not like this

But like this
image

Trying to explain a little:

The properties of a message - msg.payload, msg.topic, etc have no existence outside of the message. They are like passengers on a train, you can't compare a passenger on the 09:00 train with a passenger on the 10:00 train because only one train (message) is at a station (node) at any one time.

But you can save the properties of a message as "context variables" which are visible to any message on that flow tab (variables can also be global)

So flow.payload1 is a record of the output of the slider and you can access that value to compare with any message property anywhere in the flow.

Hmm I don't think that is a very good explanation.
There are some videos which will do a better job!
Node-RED Essentials.

@jbudd's suggestion most certainly will work. I think what you mean is "I can't get your suggestion to work, what am I doing wrong".

1 Like

Thank you. I found a solution.

[
    {
        "id": "ad6d68105b95aa5b",
        "type": "debug",
        "z": "ded344b4e00b625c",
        "name": "1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1730,
        "y": 740,
        "wires": []
    },
    {
        "id": "c48f4559ab67834d",
        "type": "switch",
        "z": "ded344b4e00b625c",
        "name": "switch",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "lt",
                "v": "payload1",
                "vt": "flow"
            },
            {
                "t": "gt",
                "v": "payload1",
                "vt": "flow"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 1550,
        "y": 760,
        "wires": [
            [
                "ad6d68105b95aa5b"
            ],
            [
                "7eea7e3314087853"
            ]
        ]
    },
    {
        "id": "472043f0a568677c",
        "type": "inject",
        "z": "ded344b4e00b625c",
        "name": "200",
        "props": [
            {
                "p": "payload1",
                "v": "200",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 1370,
        "y": 580,
        "wires": [
            [
                "b8e17ff1ec616aa5"
            ]
        ]
    },
    {
        "id": "9570b5282cb4ed47",
        "type": "inject",
        "z": "ded344b4e00b625c",
        "name": "229",
        "props": [
            {
                "p": "payload1",
                "v": "229",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 1370,
        "y": 660,
        "wires": [
            [
                "b8e17ff1ec616aa5"
            ]
        ]
    },
    {
        "id": "deb1babb0c1e12c9",
        "type": "inject",
        "z": "ded344b4e00b625c",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "220",
        "payloadType": "num",
        "x": 1370,
        "y": 720,
        "wires": [
            [
                "c48f4559ab67834d"
            ]
        ]
    },
    {
        "id": "2d39a7a94b5ca670",
        "type": "inject",
        "z": "ded344b4e00b625c",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "228",
        "payloadType": "num",
        "x": 1370,
        "y": 780,
        "wires": [
            [
                "c48f4559ab67834d"
            ]
        ]
    },
    {
        "id": "b8e17ff1ec616aa5",
        "type": "change",
        "z": "ded344b4e00b625c",
        "name": "set",
        "rules": [
            {
                "t": "set",
                "p": "payload1",
                "pt": "flow",
                "to": "payload1",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 1530,
        "y": 600,
        "wires": [
            [
                "8226cb0bd6bf6409"
            ]
        ]
    },
    {
        "id": "8226cb0bd6bf6409",
        "type": "debug",
        "z": "ded344b4e00b625c",
        "name": "0",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1730,
        "y": 600,
        "wires": []
    },
    {
        "id": "7eea7e3314087853",
        "type": "debug",
        "z": "ded344b4e00b625c",
        "name": "2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1730,
        "y": 780,
        "wires": []
    },
    {
        "id": "9d67e9a9269f544a",
        "type": "inject",
        "z": "ded344b4e00b625c",
        "name": "221",
        "props": [
            {
                "p": "payload1",
                "v": "221",
                "vt": "num"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 1370,
        "y": 620,
        "wires": [
            [
                "b8e17ff1ec616aa5"
            ]
        ]
    }
]

Thank you

Making progress :grinning:

Just to point out that you don't need to use a different property name (msg.payload1) in your inject node.
Msg.payload in one message does not interfere with msg.payload in any other message.

Indeed, I think you cannot tell the slider to set any property except msg.payload.

Yes, I understood and got what I needed with your proposal. I would call this case as dynamic or variable hysteresis. It’s good that there are people who quickly answer and you find a solution to the problem. See you soon!

[
    {
        "id": "e528f7984e385464",
        "type": "change",
        "z": "7274279d65cc34eb",
        "name": "flow to payload",
        "rules": [
            {
                "t": "set",
                "p": "Voltmax",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2520,
        "y": 580,
        "wires": [
            [
                "2b94d238144d37bb"
            ]
        ]
    },
    {
        "id": "2b94d238144d37bb",
        "type": "switch",
        "z": "7274279d65cc34eb",
        "name": "switch",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "gt",
                "v": "Voltmax",
                "vt": "flow"
            },
            {
                "t": "lt",
                "v": "Voltmin",
                "vt": "flow"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 2,
        "x": 2770,
        "y": 600,
        "wires": [
            [
                "01c64debe61edb97",
                "99cf230b4542030f"
            ],
            [
                "ceba819e42bcbc53",
                "213d8f67fc7917b7"
            ]
        ]
    },
    {
        "id": "caf9c4ae3bda3a62",
        "type": "ui-slider",
        "z": "7274279d65cc34eb",
        "group": "15fdbe52d3196b92",
        "name": "Установка максимального напряжения для сравнения",
        "label": "максимального напряжения",
        "tooltip": "",
        "order": 1,
        "width": "8",
        "height": "1",
        "passthru": false,
        "outs": "all",
        "topic": "topic",
        "topicType": "msg",
        "thumbLabel": true,
        "min": "200",
        "max": "250",
        "step": 1,
        "className": "",
        "x": 2210,
        "y": 580,
        "wires": [
            [
                "e528f7984e385464"
            ]
        ]
    },
    {
        "id": "af9fdec289fa6207",
        "type": "ui-slider",
        "z": "7274279d65cc34eb",
        "group": "15fdbe52d3196b92",
        "name": "Установка минимального напряжения для сравнения",
        "label": "минимального напряжения",
        "tooltip": "",
        "order": 3,
        "width": "8",
        "height": "1",
        "passthru": false,
        "outs": "all",
        "topic": "topic",
        "topicType": "msg",
        "thumbLabel": true,
        "min": "200",
        "max": "250",
        "step": 1,
        "className": "",
        "x": 2210,
        "y": 620,
        "wires": [
            [
                "cc19a716b1d35ace"
            ]
        ]
    },
    {
        "id": "cc19a716b1d35ace",
        "type": "change",
        "z": "7274279d65cc34eb",
        "name": "flow to payload",
        "rules": [
            {
                "t": "set",
                "p": "Voltmin",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 2520,
        "y": 620,
        "wires": [
            [
                "2b94d238144d37bb"
            ]
        ]
    },
    {
        "id": "01c64debe61edb97",
        "type": "debug",
        "z": "7274279d65cc34eb",
        "name": "1",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 2930,
        "y": 580,
        "wires": []
    },
    {
        "id": "ceba819e42bcbc53",
        "type": "debug",
        "z": "7274279d65cc34eb",
        "name": "2",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 2930,
        "y": 620,
        "wires": []
    },
    {
        "id": "611a7cdb560c17fe",
        "type": "ui-slider",
        "z": "7274279d65cc34eb",
        "group": "15fdbe52d3196b92",
        "name": "Установка напряжения",
        "label": "Входящее напряжение для примера",
        "tooltip": "",
        "order": 2,
        "width": "8",
        "height": "1",
        "passthru": false,
        "outs": "all",
        "topic": "topic",
        "topicType": "msg",
        "thumbLabel": true,
        "min": "200",
        "max": "250",
        "step": 1,
        "className": "",
        "x": 2110,
        "y": 540,
        "wires": [
            [
                "2b94d238144d37bb"
            ]
        ]
    },
    {
        "id": "99cf230b4542030f",
        "type": "ui-text",
        "z": "7274279d65cc34eb",
        "group": "15fdbe52d3196b92",
        "order": 4,
        "width": "0",
        "height": "0",
        "name": "сравнение с максимальным",
        "label": "сравнение с максимальным",
        "format": "{{msg.payload}}",
        "layout": "row-spread",
        "style": false,
        "font": "",
        "fontSize": 16,
        "color": "#717171",
        "className": "",
        "x": 3000,
        "y": 540,
        "wires": []
    },
    {
        "id": "213d8f67fc7917b7",
        "type": "ui-text",
        "z": "7274279d65cc34eb",
        "group": "15fdbe52d3196b92",
        "order": 5,
        "width": "0",
        "height": "0",
        "name": "сравнение с минимальным",
        "label": "сравнение с минимальным",
        "format": "{{msg.payload}}",
        "layout": "row-spread",
        "style": false,
        "font": "",
        "fontSize": 16,
        "color": "#717171",
        "className": "",
        "x": 3020,
        "y": 660,
        "wires": []
    },
    {
        "id": "15fdbe52d3196b92",
        "type": "ui-group",
        "name": "реле и счетчик",
        "page": "108bba136c098591",
        "width": "8",
        "height": "1",
        "order": 2,
        "showTitle": true,
        "className": "",
        "visible": "true",
        "disabled": "false"
    },
    {
        "id": "108bba136c098591",
        "type": "ui-page",
        "name": "управление",
        "ui": "8e88ed68f54ffc23",
        "path": "/page4",
        "icon": "home",
        "layout": "flex",
        "theme": "ebbd600a4950e6d4",
        "order": 4,
        "className": "",
        "visible": "true",
        "disabled": "false"
    },
    {
        "id": "8e88ed68f54ffc23",
        "type": "ui-base",
        "name": "UI Name 2",
        "path": "/dashboard",
        "includeClientData": true,
        "acceptsClientConfig": [
            "ui-notification",
            "ui-control"
        ],
        "showPathInSidebar": false,
        "navigationStyle": "fixed"
    },
    {
        "id": "ebbd600a4950e6d4",
        "type": "ui-theme",
        "name": "Theme Name 1",
        "colors": {
            "surface": "#1a0505",
            "primary": "#05b8ff",
            "bgPage": "#400202",
            "groupBg": "#e6efe7",
            "groupOutline": "#0b92f9"
        },
        "sizes": {
            "pagePadding": "12px",
            "groupGap": "12px",
            "groupBorderRadius": "4px",
            "widgetGap": "12px"
        }
    }
]

What time does the train leave and how fast is it ? :stuck_out_tongue_winking_eye:

1 Like

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