How to compare Slider value with sensor value

Hi guis,
im verry new in the Node-Red programming. Can you help me to compare the slider value with the sensore value.

10x

[
    {
        "id": "7c559bef.0cf194",
        "type": "inject",
        "z": "200e10c3.91d01",
        "name": "",
        "topic": "",
        "payload": "10",
        "payloadType": "num",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 70,
        "y": 120,
        "wires": [
            [
                "4e855904.8b62d8"
            ]
        ]
    },
    {
        "id": "2a2b9e73.577fb2",
        "type": "ui_slider",
        "z": "200e10c3.91d01",
        "name": "",
        "label": "slider",
        "tooltip": "",
        "group": "15ead4d7.0fe35b",
        "order": 3,
        "width": 0,
        "height": 0,
        "passthru": true,
        "outs": "end",
        "topic": "",
        "min": 0,
        "max": "20",
        "step": 1,
        "x": 70,
        "y": 40,
        "wires": [
            [
                "3f52dfeb.aa6f2"
            ]
        ]
    },
    {
        "id": "3f52dfeb.aa6f2",
        "type": "function",
        "z": "200e10c3.91d01",
        "name": "pl1",
        "func": "var msg1 = { payload1:msg.payload };\n\nreturn msg1;",
        "outputs": 1,
        "noerr": 0,
        "x": 250,
        "y": 80,
        "wires": [
            [
                "77abb4d6.081cdc"
            ]
        ]
    },
    {
        "id": "4e855904.8b62d8",
        "type": "function",
        "z": "200e10c3.91d01",
        "name": "pl2",
        "func": "var msg2 = { payload2:msg.payload };\n\nreturn msg2;",
        "outputs": 1,
        "noerr": 0,
        "x": 250,
        "y": 140,
        "wires": [
            [
                "77abb4d6.081cdc"
            ]
        ]
    },
    {
        "id": "77abb4d6.081cdc",
        "type": "function",
        "z": "200e10c3.91d01",
        "name": "Temperature1",
        "func": "if(msg.payload1>msg.payload2){\nmsg.payload = '0';\nreturn msg;\n}\nelse {\nmsg.payload = '1';\nreturn msg;\n}",
        "outputs": 1,
        "noerr": 0,
        "x": 460,
        "y": 120,
        "wires": [
            [
                "6eb6eca2.e3ce54"
            ]
        ]
    },
    {
        "id": "6eb6eca2.e3ce54",
        "type": "rpi-gpio out",
        "z": "200e10c3.91d01",
        "name": "",
        "pin": "11",
        "set": "",
        "level": "0",
        "freq": "",
        "out": "out",
        "x": 660,
        "y": 120,
        "wires": []
    },
    {
        "id": "15ead4d7.0fe35b",
        "type": "ui_group",
        "z": "",
        "name": "weather",
        "tab": "d3408c2f.0311b",
        "order": 1,
        "disp": false,
        "width": "6",
        "collapse": false
    },
    {
        "id": "d3408c2f.0311b",
        "type": "ui_tab",
        "z": "",
        "name": "weather",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

Messages travel down the wires at different times, so your 2 payloads are never at the function at the same time.

You will need to join the messages with a join node or save them to context storage, and fetch when needed.


Here is an example of context storage

[{"id":"d169c00e.e86a58","type":"ui_slider","z":"8d22ae29.7df6d","name":"","label":"slider","tooltip":"","group":"39975297.f7403e","order":3,"width":0,"height":0,"passthru":true,"outs":"end","topic":"","min":0,"max":"20","step":1,"x":100,"y":2140,"wires":[["12314e09.b59232"]]},{"id":"a13d87c0.8d4cd","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload","v":"10","vt":"num"},{"p":"topic","v":"","vt":"string"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":100,"y":2220,"wires":[["72754745.375098"]]},{"id":"12314e09.b59232","type":"function","z":"8d22ae29.7df6d","name":"pl1","func":"msg.payload1= msg.payload;\nmsg.payload2 = (flow.get(\"storeP2\") || 10);\nflow.set(\"storeP1\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":280,"y":2160,"wires":[["50342ae9.8bf734"]]},{"id":"72754745.375098","type":"function","z":"8d22ae29.7df6d","name":"pl2","func":"msg.payload2= msg.payload;\nmsg.payload1 = (flow.get(\"storeP1\") || 10);\nflow.set(\"storeP2\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":273.33331298828125,"y":2222.66650390625,"wires":[["50342ae9.8bf734"]]},{"id":"50342ae9.8bf734","type":"function","z":"8d22ae29.7df6d","name":"Temperature1","func":"if(msg.payload1 > msg.payload2){\nmsg.payload = '0';\nreturn msg;\n}\nelse {\nmsg.payload = '1';\nreturn msg;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":2220,"wires":[["49952583.65b3fc"]]},{"id":"39975297.f7403e","type":"ui_group","z":"","name":"weather","tab":"468df50a.5dca5c","order":1,"disp":false,"width":"6","collapse":false},{"id":"468df50a.5dca5c","type":"ui_tab","z":"","name":"weather","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
1 Like

Thankyou, i reached this conclusion last night. Your example work verry good.
good day

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