Switch off relay

Any help would be appreciated. I am trying to set up a flow for heater control. I want the user to be able to switch on the heater, only when the temperature is bellow the set point and the heater to switch off when the temperature is equal or above the set point. This means that the switch on the dashboard will do nothing if the temperature is above or equal the set point or switch back to off, once the temperature rises to the set point.

[
    {
        "id": "f499b7ea.100118",
        "type": "tab",
        "label": "test",
        "disabled": false,
        "info": ""
    },
    {
        "id": "aebd59a1.e5b398",
        "type": "ui_switch",
        "z": "f499b7ea.100118",
        "name": "",
        "label": "switch",
        "tooltip": "",
        "group": "7c7fe7a7.d5e398",
        "order": 5,
        "width": 0,
        "height": 0,
        "passthru": true,
        "decouple": "false",
        "topic": "",
        "style": "",
        "onvalue": "ON",
        "onvalueType": "str",
        "onicon": "",
        "oncolor": "",
        "offvalue": "OFF",
        "offvalueType": "str",
        "officon": "",
        "offcolor": "",
        "x": 130,
        "y": 280,
        "wires": [
            [
                "c6cef357.1f624",
                "777db117.66834",
                "71cec172.6fe92"
            ]
        ]
    },
    {
        "id": "b90d81c6.9977e",
        "type": "ui_slider",
        "z": "f499b7ea.100118",
        "name": "",
        "label": "tempNow",
        "tooltip": "",
        "group": "7c7fe7a7.d5e398",
        "order": 4,
        "width": 0,
        "height": 0,
        "passthru": false,
        "outs": "end",
        "topic": "",
        "min": 0,
        "max": 10,
        "step": 1,
        "x": 120,
        "y": 100,
        "wires": [
            [
                "a03f3dc7.f3a28"
            ]
        ]
    },
    {
        "id": "99c3bd1d.4d195",
        "type": "ui_slider",
        "z": "f499b7ea.100118",
        "name": "",
        "label": "tempSet",
        "tooltip": "",
        "group": "7c7fe7a7.d5e398",
        "order": 7,
        "width": 0,
        "height": 0,
        "passthru": false,
        "outs": "end",
        "topic": "",
        "min": 0,
        "max": 10,
        "step": 1,
        "x": 120,
        "y": 160,
        "wires": [
            [
                "73f3cfb.639c83"
            ]
        ]
    },
    {
        "id": "a03f3dc7.f3a28",
        "type": "function",
        "z": "f499b7ea.100118",
        "name": "msg.tempnow",
        "func": "flow.set(\"tempnow\", msg.payload);",
        "outputs": 1,
        "noerr": 0,
        "x": 300,
        "y": 100,
        "wires": [
            []
        ]
    },
    {
        "id": "73f3cfb.639c83",
        "type": "function",
        "z": "f499b7ea.100118",
        "name": "msg.tempset",
        "func": "flow.set(\"tempset\", msg.payload);",
        "outputs": 1,
        "noerr": 0,
        "x": 290,
        "y": 160,
        "wires": [
            []
        ]
    },
    {
        "id": "c6cef357.1f624",
        "type": "debug",
        "z": "f499b7ea.100118",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "x": 330,
        "y": 280,
        "wires": []
    },
    {
        "id": "a628afb9.ef32a",
        "type": "rpi-gpio out",
        "z": "f499b7ea.100118",
        "name": "",
        "pin": "33",
        "set": true,
        "level": "1",
        "freq": "",
        "out": "out",
        "x": 640,
        "y": 340,
        "wires": []
    },
    {
        "id": "777db117.66834",
        "type": "change",
        "z": "f499b7ea.100118",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "OFF",
                "fromt": "str",
                "to": "1",
                "tot": "num"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "ON",
                "fromt": "str",
                "to": "0",
                "tot": "num"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 320,
        "y": 340,
        "wires": [
            [
                "a628afb9.ef32a"
            ]
        ]
    },
    {
        "id": "71cec172.6fe92",
        "type": "trigger",
        "z": "f499b7ea.100118",
        "op1": "",
        "op2": "0",
        "op1type": "date",
        "op2type": "str",
        "duration": "-5",
        "extend": false,
        "units": "s",
        "reset": "OFF",
        "bytopic": "all",
        "name": "",
        "x": 300,
        "y": 400,
        "wires": [
            [
                "a4b1ede0.bc5db"
            ]
        ]
    },
    {
        "id": "a4b1ede0.bc5db",
        "type": "function",
        "z": "f499b7ea.100118",
        "name": "Temp comparing Set Point",
        "func": "var temperature = flow.get(\"tempnow\");\nvar setting = flow.get(\"tempset\");\n\n//if temperature now is less than the setpoint\nif(temperature < setting) {\n    //close the relay\n    msg.payload = 0;\n    return msg;\n    }\n//if temperature is equal or over the setpoint    \nelse {\n    //open the relay\n    msg.payload = 1;\n    return msg;\n}",
        "outputs": 1,
        "noerr": 0,
        "x": 560,
        "y": 400,
        "wires": [
            [
                "a628afb9.ef32a"
            ]
        ]
    },
    {
        "id": "87c96e16.83a17",
        "type": "inject",
        "z": "f499b7ea.100118",
        "name": "",
        "topic": "",
        "payload": "OFF",
        "payloadType": "str",
        "repeat": "",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "x": 130,
        "y": 220,
        "wires": [
            [
                "aebd59a1.e5b398"
            ]
        ]
    },
    {
        "id": "7c7fe7a7.d5e398",
        "type": "ui_group",
        "z": "",
        "name": "Control",
        "tab": "de03cc52.a371c",
        "order": 2,
        "disp": false,
        "width": "8",
        "collapse": false
    },
    {
        "id": "de03cc52.a371c",
        "type": "ui_tab",
        "z": "",
        "name": "Home",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

Help me to understand your question please. If the temperature is below the set point you want the heater to turn on automatically. If the temperature is above the set point the relay will be off. Yet you want the user to be able to turn on the heater only if the temperature is below the set point. Won't the heater already be on when the user goes to turn it on? What does the switch do that the code doesn't take care of?

So, in order to switch on the relay, the heater that is, the switch must be on and the current temperature must be below the setpoint.

The switch then acts as an on/off switch for the heater? Switch on heater works, switch off heater off?

[{"id":"3d3788b6.361128","type":"tab","label":"Folly","disabled":false,"info":""},{"id":"366ca737.ce6f5","type":"ui_switch","z":"3d3788b6.361128","name":"manual","label":"On / Off","tooltip":"","group":"2223e6c7.3073e2","order":5,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"manual","style":"","onvalue":"1","onvalueType":"num","onicon":"","oncolor":"","offvalue":"0","offvalueType":"num","officon":"","offcolor":"","x":120,"y":220,"wires":[["cc7cb819.ccadd"]]},{"id":"cdcd547.10fb528","type":"ui_slider","z":"3d3788b6.361128","name":"","label":"tempNow","tooltip":"","group":"2223e6c7.3073e2","order":4,"width":0,"height":0,"passthru":false,"outs":"end","topic":"tempnow","min":0,"max":10,"step":1,"x":120,"y":100,"wires":[["9f184522.6a5268"]]},{"id":"4add2209.516e6c","type":"ui_slider","z":"3d3788b6.361128","name":"","label":"tempSet","tooltip":"","group":"2223e6c7.3073e2","order":7,"width":0,"height":0,"passthru":false,"outs":"end","topic":"tempset","min":0,"max":10,"step":1,"x":120,"y":160,"wires":[["8f73c9d9.f4206"]]},{"id":"9f184522.6a5268","type":"function","z":"3d3788b6.361128","name":"msg.tempnow","func":"flow.set(\"tempnow\", msg.payload);\n\nnode.status({fill:\"blue\",shape:\"dot\",text:msg.payload});\n\nreturn msg;","outputs":1,"noerr":0,"x":300,"y":100,"wires":[[]]},{"id":"8f73c9d9.f4206","type":"function","z":"3d3788b6.361128","name":"msg.tempset","func":"flow.set(\"tempset\", msg.payload);\n\nnode.status({fill:\"blue\",shape:\"dot\",text:msg.payload});\n\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":160,"wires":[[]]},{"id":"4267b35f.03a9ac","type":"rpi-gpio out","z":"3d3788b6.361128","name":"","pin":"33","set":true,"level":"1","freq":"","out":"out","x":720,"y":300,"wires":[]},{"id":"27c4a6a6.19b3a2","type":"function","z":"3d3788b6.361128","name":"Temp comparing Set Point","func":"var temperature = flow.get(\"tempnow\");\nvar setting = flow.get(\"tempset\");\nvar on = flow.get('on');\n\nnode.status({fill:\"blue\",shape:\"dot\",text:\"temperature\"+\":\"+temperature+\"---\"+\"setting\"+\":\"+setting+\"   \" + \"  on \" + on});\n\nif (on === 0){\n    msg.payload = 0;\n    return msg;\n}\n\n//if temperature now is less than the setpoint\nif(temperature > setting) {\n    //close the relay\n    msg.payload = 0;\n    on = 0;\n    } else {\n    //open the relay\n    msg.payload = 1;\n    on = 1;\n}\n\n\nreturn msg;","outputs":1,"noerr":0,"x":400,"y":300,"wires":[["4267b35f.03a9ac"]]},{"id":"85be7973.ac09a8","type":"inject","z":"3d3788b6.361128","name":"inject","topic":"inject","payload":"","payloadType":"date","repeat":"5","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":300,"wires":[["27c4a6a6.19b3a2"]]},{"id":"cc7cb819.ccadd","type":"function","z":"3d3788b6.361128","name":"on / off","func":"flow.set(\"on\", msg.payload);\n\nnode.status({fill:\"blue\",shape:\"dot\",text:msg.payload});\n\nreturn msg;","outputs":1,"noerr":0,"x":320,"y":220,"wires":[[]]},{"id":"2223e6c7.3073e2","type":"ui_group","z":"","name":"Control","tab":"39f9c026.d4976","order":2,"disp":false,"width":"8","collapse":false},{"id":"39f9c026.d4976","type":"ui_tab","z":"","name":"Folly","icon":"dashboard","order":4,"disabled":false,"hidden":false}]

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