# How to compare Slider value with sensor value

**URL:** <https://discourse.nodered.org/t/how-to-compare-slider-value-with-sensor-value/34792>\
**Category:** General\
**Created:** [25 October 2020 19:11 UTC](https://discourse.nodered.org/t/how-to-compare-slider-value-with-sensor-value/34792 "2020-10-25T19:11:46Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mgolemanov](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@mgolemanov](https://discourse.nodered.org/u/mgolemanov)\
**Post date:** [25 October 2020 19:11 UTC](https://discourse.nodered.org/t/how-to-compare-slider-value-with-sensor-value/34792/1 "2020-10-25T19:11:47Z")

</div>

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

10x

```auto
[
    {
        "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
    }
]

```

---

<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:** [25 October 2020 19:38 UTC](https://discourse.nodered.org/t/how-to-compare-slider-value-with-sensor-value/34792/2 "2020-10-25T19:38:00Z")

</div>

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.

> **[Create a single message from separate streams of messages : Node-RED](https://cookbook.nodered.org/basic/join-streams)**

  

> **[Working with context : Node-RED](https://nodered.org/docs/user-guide/context)**

Here is an example of context storage

```auto
[{"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}]

```

---

<div class="post-metadata">

**Author:** ![mgolemanov](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@mgolemanov](https://discourse.nodered.org/u/mgolemanov)\
**Post date:** [26 October 2020 05:07 UTC](https://discourse.nodered.org/t/how-to-compare-slider-value-with-sensor-value/34792/3 "2020-10-26T05:07:12Z")

</div>

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

---

<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:** [9 November 2020 05:07 UTC](https://discourse.nodered.org/t/how-to-compare-slider-value-with-sensor-value/34792/4 "2020-11-09T05:07:20Z")

</div>

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