# Controlling a heat pump with two temperatures and a setpoint, problem with OR logic gate

**URL:** <https://discourse.nodered.org/t/controlling-a-heat-pump-with-two-temperatures-and-a-setpoint-problem-with-or-logic-gate/53309>\
**Category:** General\
**Created:** [6 November 2021 20:28 UTC](https://discourse.nodered.org/t/controlling-a-heat-pump-with-two-temperatures-and-a-setpoint-problem-with-or-logic-gate/53309 "2021-11-06T20:28:49Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![lale02](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@lale02](https://discourse.nodered.org/u/lale02)\
**Post date:** [6 November 2021 20:28 UTC](https://discourse.nodered.org/t/controlling-a-heat-pump-with-two-temperatures-and-a-setpoint-problem-with-or-logic-gate/53309/1 "2021-11-06T20:28:49Z")

</div>

Hi guys, I' am an old automation engineer, but new with Node Red (which is an awesome tool btw.)  
I am stuck at one point, so I take two temperatures of my sensors, compare them with an setpoint temp, and if one of those comparisons is true start heat pump which is controlled with Siemens S7 LOGO!, problem is, when state is changed from true to false, the or logic does not do the job and heat pump is always on.  
So my question is, what am I doing wrong, and can someone help me to fix my flow.

I am running Home Automation on RAPI 3b+ and latest Node Red, and my code is down below.

Thank you very much.

```auto
[{"id":"97b34efde9c39373","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"8e7345938b206492","type":"s7 in","z":"97b34efde9c39373","endpoint":"c389e1d7ecaa6e32","mode":"single","variable":"RELAY_0","diff":true,"name":"","x":1840,"y":380,"wires":[["200bca8328f0b58c"]]},{"id":"200bca8328f0b58c","type":"debug","z":"97b34efde9c39373","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1990,"y":380,"wires":[]},{"id":"72d690b70587cc44","type":"inject","z":"97b34efde9c39373","name":"inject heater_id_living","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"099950821892","payloadType":"str","x":120,"y":260,"wires":[["de04a8c0c2430bb2"]]},{"id":"de04a8c0c2430bb2","type":"fritz-thermostat","z":"97b34efde9c39373","connection":"c2e6322e.33404","name":"Living","action":"getDevice","x":310,"y":260,"wires":[["aca319070f62a09c","aad7ac76f471e74f","45ea11ecb6e599dc"]]},{"id":"aca319070f62a09c","type":"change","z":"97b34efde9c39373","name":"is_temperature","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.temperature.celsius","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":200,"wires":[["c3fdda121228a26f"]]},{"id":"c3fdda121228a26f","type":"function","z":"97b34efde9c39373","name":"convert_t_to_celsius","func":"msg.topic='Actual Temp';\nmsg.payload=msg.payload/10;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":740,"y":200,"wires":[["fd11bb69297f5a29","ed1c284429eac662"]]},{"id":"aad7ac76f471e74f","type":"change","z":"97b34efde9c39373","name":"comfort_temperature","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.hkr.komfort","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":320,"wires":[["7748dfaee9f2117c"]]},{"id":"7748dfaee9f2117c","type":"function","z":"97b34efde9c39373","name":"convert_t_to_celsius","func":"msg.topic='SetPoint Temp';\nmsg.payload=msg.payload*0.5;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":320,"wires":[["47e60a682a2fe46d","ed1c284429eac662"]]},{"id":"45ea11ecb6e599dc","type":"debug","z":"97b34efde9c39373","name":"Device_info","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":530,"y":140,"wires":[]},{"id":"47e60a682a2fe46d","type":"debug","z":"97b34efde9c39373","name":"Comfort_temperatura_Living","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1060,"y":320,"wires":[]},{"id":"fd11bb69297f5a29","type":"debug","z":"97b34efde9c39373","name":"Real Temp Living room","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1020,"y":200,"wires":[]},{"id":"b98d8ffb67ea0fa0","type":"s7 out","z":"97b34efde9c39373","endpoint":"c389e1d7ecaa6e32","variable":"RELAY_0","name":"RELAY","x":1680,"y":380,"wires":[]},{"id":"ed1c284429eac662","type":"function","z":"97b34efde9c39373","name":"Compare ACC and SP","func":"context.node = context.node || 0;\ncontext.node1 = context.node1 || 0;\n\nif(msg.topic == 'Actual Temp'){\n\tcontext.node = msg.payload;\n}else if (msg.topic == 'SetPoint Temp'){\n\tcontext.node1 = msg.payload;\n}\nif (context.node < context.node1){\n\treturn { topic: 'Current temp is Less than SP', payload: 'Start Boiler'}\n}else{\n\treturn { topic: 'Current temp is Higher than SP', payload: 'Stop Boiler'}\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1020,"y":260,"wires":[["219fe1fe67733ef5"]]},{"id":"3f50cb93bbe8a1ef","type":"debug","z":"97b34efde9c39373","name":"Status","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1450,"y":200,"wires":[]},{"id":"219fe1fe67733ef5","type":"change","z":"97b34efde9c39373","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"Start Boiler","fromt":"str","to":"true","tot":"bool"},{"t":"change","p":"payload","pt":"msg","from":"Stop Boiler","fromt":"str","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1260,"y":260,"wires":[["3f50cb93bbe8a1ef","48e4d748115f190f"]]},{"id":"f08decc9892e2c2c","type":"inject","z":"97b34efde9c39373","name":"inject heater_id_dining","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"099950818803","payloadType":"str","x":130,"y":500,"wires":[["4ea197cf60ede151"]]},{"id":"4ea197cf60ede151","type":"fritz-thermostat","z":"97b34efde9c39373","connection":"c2e6322e.33404","name":"Dining","action":"getDevice","x":310,"y":500,"wires":[["ded944ebf002b3d1","c50ae13f4d296a60","c2461bf793a0af97"]]},{"id":"ded944ebf002b3d1","type":"change","z":"97b34efde9c39373","name":"is_temperature","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.temperature.celsius","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":440,"wires":[["7b7185bc189dfdd8"]]},{"id":"7b7185bc189dfdd8","type":"function","z":"97b34efde9c39373","name":"convert_t_to_celsius","func":"msg.topic='Actual Temp';\nmsg.payload=msg.payload/10;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":740,"y":440,"wires":[["047ff7e3af7d2669","e346efcbc8ed4d22"]]},{"id":"c50ae13f4d296a60","type":"change","z":"97b34efde9c39373","name":"comfort_temperature","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.hkr.komfort","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":540,"wires":[["a84fd06e228dcbc2"]]},{"id":"a84fd06e228dcbc2","type":"function","z":"97b34efde9c39373","name":"convert_t_to_celsius","func":"msg.topic='SetPoint Temp';\nmsg.payload=msg.payload*0.5;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":540,"wires":[["0e68341f6cbc5734","e346efcbc8ed4d22"]]},{"id":"c2461bf793a0af97","type":"debug","z":"97b34efde9c39373","name":"Device_info","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":490,"y":380,"wires":[]},{"id":"0e68341f6cbc5734","type":"debug","z":"97b34efde9c39373","name":"Comfort_Temp_Dining","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1020,"y":540,"wires":[]},{"id":"047ff7e3af7d2669","type":"debug","z":"97b34efde9c39373","name":"Real Temp Dining Room","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1050,"y":440,"wires":[]},{"id":"e346efcbc8ed4d22","type":"function","z":"97b34efde9c39373","name":"Compare ACC and SP","func":"context.node = context.node || 0;\ncontext.node1 = context.node1 || 0;\n\nif(msg.topic == 'Actual Temp'){\n\tcontext.node = msg.payload;\n}else if (msg.topic == 'SetPoint Temp'){\n\tcontext.node1 = msg.payload;\n}\nif (context.node < context.node1){\n\treturn { topic: 'Current temp is Less than SP', payload: 'Start Boiler'}\n\t//msg.payload = 'Start Boiler';\n}else{\n\treturn { topic: 'Current temp is Higher than SP', payload: 'Stop Boiler'}\n\t//msg.payload = 'Stop Boiler';\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1020,"y":480,"wires":[["90f7f3016e47dc35"]]},{"id":"e41acc6ced0d69ba","type":"debug","z":"97b34efde9c39373","name":"Status","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1450,"y":540,"wires":[]},{"id":"90f7f3016e47dc35","type":"change","z":"97b34efde9c39373","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"Start Boiler","fromt":"str","to":"true","tot":"bool"},{"t":"change","p":"payload","pt":"msg","from":"Stop Boiler","fromt":"str","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1260,"y":480,"wires":[["e41acc6ced0d69ba","48e4d748115f190f"]]},{"id":"48e4d748115f190f","type":"BooleanLogicUltimate","z":"97b34efde9c39373","name":"","filtertrue":"both","persist":false,"sInitializeWith":"WaitForPayload","triggertopic":"trigger","outputtriggeredby":"all","inputCount":"2","topic":"result","restrictinputevaluation":false,"x":1500,"y":380,"wires":[[],["b98d8ffb67ea0fa0"],[]]},{"id":"a44982d0621f043a","type":"inject","z":"97b34efde9c39373","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":1530,"y":320,"wires":[["b98d8ffb67ea0fa0"]]},{"id":"0b6526ab2f27357f","type":"inject","z":"97b34efde9c39373","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":1530,"y":440,"wires":[["b98d8ffb67ea0fa0"]]},{"id":"c389e1d7ecaa6e32","type":"s7 endpoint","transport":"iso-on-tcp","address":"192.168.178.249","port":"102","rack":"0","slot":"2","localtsaphi":"02","localtsaplo":"00","remotetsaphi":"02","remotetsaplo":"00","connmode":"tsap","adapter":"","busaddr":"2","cycletime":"500","timeout":"1500","name":"LOGO!","vartable":[{"addr":"Q0.0","name":"RELAY_0"},{"addr":"Q0.1","name":"RELAY_1"},{"addr":"Q0.2","name":"RELAY_2"},{"addr":"I0.0","name":"INPUT_1"}]},{"id":"c2e6322e.33404","type":"fritz-api","name":"fritzBox","host":"http://fritz.box","strictSSL":true}]

```

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [6 November 2021 21:13 UTC](https://discourse.nodered.org/t/controlling-a-heat-pump-with-two-temperatures-and-a-setpoint-problem-with-or-logic-gate/53309/2 "2021-11-06T21:13:13Z")

</div>

Hello,

I think you can merge a lot of the logic and use half of the nodes by simply doing in you function node something like

```auto
let actual_temp = msg.payload.temperature.celsius / 10;
let comfort_temp = msg.payload.hkr.komfort * 0.5

node.status({ fill: "green", shape: "dot", text: `Actual Temp: ${actual_temp} Comfort Temp: ${comfort_temp}` });

if (actual_temp < comfort_temp) {
    return { topic: 'Current temp is Less than SP', payload: true } // start Heat Pump
} else {
    return { topic: 'Current temp is Higher than SP', payload: false } // stop Heat Pump
}

```

The problem that you may be facing with you flow is that you split the processing of the `is_temperature` and `comfort_temperature` in different paths (wires) where (since they arrive from the same thermostat) could be processed in the same function as above.

---

<div class="post-metadata">

**Author:** ![lale02](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@lale02](https://discourse.nodered.org/u/lale02)\
**Post date:** [6 November 2021 21:33 UTC](https://discourse.nodered.org/t/controlling-a-heat-pump-with-two-temperatures-and-a-setpoint-problem-with-or-logic-gate/53309/3 "2021-11-06T21:33:47Z")

</div>

Thank you UnborN for quick response, still I am getting correct outputs (true - false) but when state is changed from true to false nothing is happening - Relay stays on (true)

 ![error](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/b/6bb7629748f3d3d9643332a7c67381326df7d18f.jpeg)

```auto
[{"id":"97b34efde9c39373","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"8e7345938b206492","type":"s7 in","z":"97b34efde9c39373","endpoint":"c389e1d7ecaa6e32","mode":"single","variable":"RELAY_0","diff":true,"name":"","x":1840,"y":380,"wires":[["200bca8328f0b58c"]]},{"id":"200bca8328f0b58c","type":"debug","z":"97b34efde9c39373","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1990,"y":380,"wires":[]},{"id":"72d690b70587cc44","type":"inject","z":"97b34efde9c39373","name":"inject heater_id_living","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"099950821892","payloadType":"str","x":120,"y":260,"wires":[["de04a8c0c2430bb2"]]},{"id":"de04a8c0c2430bb2","type":"fritz-thermostat","z":"97b34efde9c39373","connection":"c2e6322e.33404","name":"Living","action":"getDevice","x":310,"y":260,"wires":[["aca319070f62a09c","aad7ac76f471e74f","45ea11ecb6e599dc","f914578db3d0b121"]]},{"id":"aca319070f62a09c","type":"change","z":"97b34efde9c39373","name":"is_temperature","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.temperature.celsius","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":200,"wires":[["c3fdda121228a26f"]]},{"id":"aad7ac76f471e74f","type":"change","z":"97b34efde9c39373","name":"comfort_temperature","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.hkr.komfort","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":320,"wires":[["7748dfaee9f2117c"]]},{"id":"45ea11ecb6e599dc","type":"debug","z":"97b34efde9c39373","name":"Device_info","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":530,"y":140,"wires":[]},{"id":"47e60a682a2fe46d","type":"debug","z":"97b34efde9c39373","name":"Comfort_temperatura_Living","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1060,"y":320,"wires":[]},{"id":"fd11bb69297f5a29","type":"debug","z":"97b34efde9c39373","name":"Real Temp Living room","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1060,"y":140,"wires":[]},{"id":"b98d8ffb67ea0fa0","type":"s7 out","z":"97b34efde9c39373","endpoint":"c389e1d7ecaa6e32","variable":"RELAY_0","name":"RELAY","x":1680,"y":380,"wires":[]},{"id":"3f50cb93bbe8a1ef","type":"debug","z":"97b34efde9c39373","name":"Status living","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1270,"y":260,"wires":[]},{"id":"f08decc9892e2c2c","type":"inject","z":"97b34efde9c39373","name":"inject heater_id_dining","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"099950818803","payloadType":"str","x":130,"y":500,"wires":[["4ea197cf60ede151"]]},{"id":"4ea197cf60ede151","type":"fritz-thermostat","z":"97b34efde9c39373","connection":"c2e6322e.33404","name":"Dining","action":"getDevice","x":310,"y":500,"wires":[["ded944ebf002b3d1","c50ae13f4d296a60","c2461bf793a0af97","6410e52f088e4e03"]]},{"id":"ded944ebf002b3d1","type":"change","z":"97b34efde9c39373","name":"is_temperature","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.temperature.celsius","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":440,"wires":[["7b7185bc189dfdd8"]]},{"id":"7b7185bc189dfdd8","type":"function","z":"97b34efde9c39373","name":"convert_t_to_celsius","func":"msg.topic='Actual Temp';\nmsg.payload=msg.payload/10;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":420,"wires":[["047ff7e3af7d2669"]]},{"id":"c50ae13f4d296a60","type":"change","z":"97b34efde9c39373","name":"comfort_temperature","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.hkr.komfort","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":540,"wires":[["a84fd06e228dcbc2"]]},{"id":"a84fd06e228dcbc2","type":"function","z":"97b34efde9c39373","name":"convert_t_to_celsius","func":"msg.topic='SetPoint Temp';\nmsg.payload=msg.payload*0.5;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":780,"y":580,"wires":[["0e68341f6cbc5734"]]},{"id":"c2461bf793a0af97","type":"debug","z":"97b34efde9c39373","name":"Device_info","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":490,"y":380,"wires":[]},{"id":"0e68341f6cbc5734","type":"debug","z":"97b34efde9c39373","name":"Comfort_Temp_Dining","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1060,"y":580,"wires":[]},{"id":"047ff7e3af7d2669","type":"debug","z":"97b34efde9c39373","name":"Real Temp Dining Room","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1050,"y":440,"wires":[]},{"id":"e41acc6ced0d69ba","type":"debug","z":"97b34efde9c39373","name":"Status dining","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1230,"y":520,"wires":[]},{"id":"48e4d748115f190f","type":"BooleanLogicUltimate","z":"97b34efde9c39373","name":"","filtertrue":"both","persist":false,"sInitializeWith":"WaitForPayload","triggertopic":"trigger","outputtriggeredby":"all","inputCount":"2","topic":"result","restrictinputevaluation":false,"x":1500,"y":380,"wires":[[],["b98d8ffb67ea0fa0"],[]]},{"id":"a44982d0621f043a","type":"inject","z":"97b34efde9c39373","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":1530,"y":320,"wires":[["b98d8ffb67ea0fa0"]]},{"id":"0b6526ab2f27357f","type":"inject","z":"97b34efde9c39373","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":1530,"y":440,"wires":[["b98d8ffb67ea0fa0"]]},{"id":"f914578db3d0b121","type":"function","z":"97b34efde9c39373","name":"TEST_FC_living","func":"let actual_temp = msg.payload.temperature.celsius / 10\nlet comfort_temp = msg.payload.hkr.komfort * 0.5\n\nnode.status({ fill: \"green\", shape: \"dot\", text: `Actual Temp: ${actual_temp} Comfort Temp: ${comfort_temp}` });\n\nif (actual_temp < comfort_temp) {\n return { topic: 'Current temp is Less than SP', payload: true } // start Heat Pump\n} else {\n return { topic: 'Current temp is Higher than SP', payload: false } // stop Heat Pump\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1040,"y":260,"wires":[["48e4d748115f190f","3f50cb93bbe8a1ef"]]},{"id":"6410e52f088e4e03","type":"function","z":"97b34efde9c39373","name":"TEST_FC","func":"let actual_temp = msg.payload.temperature.celsius / 10;\nlet comfort_temp = msg.payload.hkr.komfort * 0.5;\n\nnode.status({ fill: \"green\", shape: \"dot\", text: `Actual Temp: ${actual_temp} Comfort Temp: ${comfort_temp}` });\n\nif (actual_temp < comfort_temp) {\n return { topic: 'Current temp is Less than SP', payload: true } // start Heat Pump\n} else {\n return { topic: 'Current temp is Higher than SP', payload: false } // stop Heat Pump\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1020,"y":520,"wires":[["48e4d748115f190f","e41acc6ced0d69ba"]]},{"id":"7748dfaee9f2117c","type":"function","z":"97b34efde9c39373","name":"convert_t_to_celsius","func":"msg.topic='SetPoint Temp';\nmsg.payload=msg.payload*0.5;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":380,"wires":[["47e60a682a2fe46d"]]},{"id":"c3fdda121228a26f","type":"function","z":"97b34efde9c39373","name":"convert_t_to_celsius","func":"msg.topic='Actual Temp';\nmsg.payload=msg.payload/10;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":760,"y":140,"wires":[["fd11bb69297f5a29"]]},{"id":"c389e1d7ecaa6e32","type":"s7 endpoint","transport":"iso-on-tcp","address":"192.168.178.249","port":"102","rack":"0","slot":"2","localtsaphi":"02","localtsaplo":"00","remotetsaphi":"02","remotetsaplo":"00","connmode":"tsap","adapter":"","busaddr":"2","cycletime":"500","timeout":"1500","name":"LOGO!","vartable":[{"addr":"Q0.0","name":"RELAY_0"},{"addr":"Q0.1","name":"RELAY_1"},{"addr":"Q0.2","name":"RELAY_2"},{"addr":"I0.0","name":"INPUT_1"}]},{"id":"c2e6322e.33404","type":"fritz-api","name":"fritzBox","host":"http://fritz.box","strictSSL":true}]

```

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [6 November 2021 22:25 UTC](https://discourse.nodered.org/t/controlling-a-heat-pump-with-two-temperatures-and-a-setpoint-problem-with-or-logic-gate/53309/4 "2021-11-06T22:25:10Z")

</div>

I havent used the **Boolean Logic** node before ..  
here's an example flow merging the status of `dining` and `living` using a Join node (based on the msg.topic .. if you notice i added a topic just for this reason .. to be able to Join)  
and later compared to see if the Heat pump should be true or false

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/b/fb5578e43a3047f91bb687fac745e71cbb76b3bd.png)

```auto
[{"id":"d1ff3ca1d7ea76e4","type":"inject","z":"ce934079785df346","name":"inject heater_id_living","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"099950821892","payloadType":"str","x":120,"y":260,"wires":[["e536dbc64ecf255d"]]},{"id":"baea4fd9a7508973","type":"debug","z":"ce934079785df346","name":"Status living","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":200,"wires":[]},{"id":"19ae5d2787ab8787","type":"inject","z":"ce934079785df346","name":"inject heater_id_dining","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"099950818803","payloadType":"str","x":130,"y":400,"wires":[["2668cefb3a2db545"]]},{"id":"07c7cb26f03b84ed","type":"debug","z":"ce934079785df346","name":"Status dining","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":480,"wires":[]},{"id":"e73990c8ec6a30b5","type":"function","z":"ce934079785df346","name":"TEST_FC_living","func":"let actual_temp = msg.payload.temperature.celsius / 10\nlet comfort_temp = msg.payload.hkr.komfort * 0.5\n\nnode.status({ fill: \"green\", shape: \"dot\", text: `Actual Temp: ${actual_temp} Comfort Temp: ${comfort_temp}` });\n\nif (actual_temp < comfort_temp) {\n return { topic: \"living\", description: 'Current living temp is Less than SP', payload: true } // start Heat Pump\n} else {\n return { topic: \"living\", description: 'Current living temp is Higher than SP', payload: false } // stop Heat Pump\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":600,"y":260,"wires":[["baea4fd9a7508973","f8aa2d2a3f418d02"]]},{"id":"bd2ad885f2d2dc4f","type":"function","z":"ce934079785df346","name":"TEST_FC","func":"let actual_temp = msg.payload.temperature.celsius / 10;\nlet comfort_temp = msg.payload.hkr.komfort * 0.5;\n\nnode.status({ fill: \"green\", shape: \"dot\", text: `Actual Temp: ${actual_temp} Comfort Temp: ${comfort_temp}` });\n\nif (actual_temp < comfort_temp) {\n return { topic: \"dining\", description: 'Current dining temp is Less than SP', payload: true } // start Heat Pump\n} else {\n return { topic: \"dining\", description: 'Current dining temp is Less than SP', payload: false } // stop Heat Pump\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":400,"wires":[["07c7cb26f03b84ed","f8aa2d2a3f418d02"]]},{"id":"f8aa2d2a3f418d02","type":"join","z":"ce934079785df346","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":840,"y":340,"wires":[["9e4ce27153c6c29b","16ac4db03d6eb147"]]},{"id":"768faea5ece2ebf2","type":"inject","z":"ce934079785df346","name":"fake data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"temperature\":{\"celsius\":215},\"hkr\":{\"komfort\":50}}","payloadType":"json","x":360,"y":180,"wires":[["e73990c8ec6a30b5"]]},{"id":"c73f52d419fb90ea","type":"debug","z":"ce934079785df346","name":"to S7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1210,"y":340,"wires":[]},{"id":"e536dbc64ecf255d","type":"fritz-thermostat","z":"ce934079785df346","connection":"3d39dbe6109d6a47","name":"Living","action":"getDevice","x":370,"y":260,"wires":[["e73990c8ec6a30b5"]]},{"id":"2668cefb3a2db545","type":"fritz-thermostat","z":"ce934079785df346","connection":"3d39dbe6109d6a47","name":"Dining","action":"getDevice","x":370,"y":400,"wires":[["bd2ad885f2d2dc4f"]]},{"id":"9e4ce27153c6c29b","type":"function","z":"ce934079785df346","name":"Compare both","func":"// check if living or || dining need HP on \nif (msg.payload.living || msg.payload.dining) {\n msg.payload = true\n}\nelse {\n msg.payload = false\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1020,"y":340,"wires":[["c73f52d419fb90ea"]]},{"id":"dc3b7293037f8d4e","type":"inject","z":"ce934079785df346","name":"fake data","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"temperature\":{\"celsius\":215},\"hkr\":{\"komfort\":40}}","payloadType":"json","x":360,"y":520,"wires":[["bd2ad885f2d2dc4f"]]},{"id":"16ac4db03d6eb147","type":"debug","z":"ce934079785df346","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":980,"y":280,"wires":[]},{"id":"3d39dbe6109d6a47","type":"fritz-api","name":"fritzBox","host":"http://fritz.box","strictSSL":true}]

```

Hope it gives you some insight

---

<div class="post-metadata">

**Author:** ![lale02](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@lale02](https://discourse.nodered.org/u/lale02)\
**Post date:** [7 November 2021 08:35 UTC](https://discourse.nodered.org/t/controlling-a-heat-pump-with-two-temperatures-and-a-setpoint-problem-with-or-logic-gate/53309/5 "2021-11-07T08:35:36Z")

</div>

In this case, status Living is giving me true (Setpoint - comfort is higher than actual temp), but compare node and status CMP is giving mi always false

 ![error](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/8/98666aec6eca492319ca5f2e6d7776ade6d496de.jpeg)

```auto
[{"id":"97b34efde9c39373","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"8e7345938b206492","type":"s7 in","z":"97b34efde9c39373","endpoint":"c389e1d7ecaa6e32","mode":"single","variable":"RELAY_0","diff":true,"name":"","x":1200,"y":440,"wires":[["200bca8328f0b58c"]]},{"id":"200bca8328f0b58c","type":"debug","z":"97b34efde9c39373","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1350,"y":440,"wires":[]},{"id":"72d690b70587cc44","type":"inject","z":"97b34efde9c39373","name":"inject heater_id_living","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"099950821892","payloadType":"str","x":120,"y":260,"wires":[["de04a8c0c2430bb2"]]},{"id":"de04a8c0c2430bb2","type":"fritz-thermostat","z":"97b34efde9c39373","connection":"c2e6322e.33404","name":"Living","action":"getDevice","x":310,"y":260,"wires":[["45ea11ecb6e599dc","f914578db3d0b121"]]},{"id":"45ea11ecb6e599dc","type":"debug","z":"97b34efde9c39373","name":"Device_info","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":490,"y":220,"wires":[]},{"id":"b98d8ffb67ea0fa0","type":"s7 out","z":"97b34efde9c39373","endpoint":"c389e1d7ecaa6e32","variable":"RELAY_0","name":"RELAY","x":1020,"y":380,"wires":[]},{"id":"3f50cb93bbe8a1ef","type":"debug","z":"97b34efde9c39373","name":"Status living","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":590,"y":280,"wires":[]},{"id":"f08decc9892e2c2c","type":"inject","z":"97b34efde9c39373","name":"inject heater_id_dining","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"099950818803","payloadType":"str","x":130,"y":500,"wires":[["4ea197cf60ede151"]]},{"id":"4ea197cf60ede151","type":"fritz-thermostat","z":"97b34efde9c39373","connection":"c2e6322e.33404","name":"Dining","action":"getDevice","x":310,"y":500,"wires":[["c2461bf793a0af97","6410e52f088e4e03"]]},{"id":"c2461bf793a0af97","type":"debug","z":"97b34efde9c39373","name":"Device_info","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":490,"y":560,"wires":[]},{"id":"e41acc6ced0d69ba","type":"debug","z":"97b34efde9c39373","name":"Status dining","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":480,"wires":[]},{"id":"a44982d0621f043a","type":"inject","z":"97b34efde9c39373","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":870,"y":300,"wires":[["b98d8ffb67ea0fa0"]]},{"id":"0b6526ab2f27357f","type":"inject","z":"97b34efde9c39373","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":870,"y":460,"wires":[["b98d8ffb67ea0fa0"]]},{"id":"f914578db3d0b121","type":"function","z":"97b34efde9c39373","name":"TEST_FC_living","func":"let actual_temp = msg.payload.temperature.celsius / 10\nlet comfort_temp = msg.payload.hkr.komfort * 0.5\n\nnode.status({ fill: \"green\", shape: \"dot\", text: `Actual Temp: ${actual_temp} Comfort Temp: ${comfort_temp}` });\n\nif (actual_temp < comfort_temp) {\n return { topic: 'Current temp is Less than SP', payload: true } // start Heat Pump\n} else {\n return { topic: 'Current temp is Higher than SP', payload: false } // stop Heat Pump\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":440,"y":360,"wires":[["3f50cb93bbe8a1ef","e1a30f226c63f4aa"]]},{"id":"6410e52f088e4e03","type":"function","z":"97b34efde9c39373","name":"TEST_FC","func":"let actual_temp = msg.payload.temperature.celsius / 10;\nlet comfort_temp = msg.payload.hkr.komfort * 0.5;\n\nnode.status({ fill: \"green\", shape: \"dot\", text: `Actual Temp: ${actual_temp} Comfort Temp: ${comfort_temp}` });\n\nif (actual_temp < comfort_temp) {\n return { topic: 'Current temp is Less than SP', payload: true } // start Heat Pump\n} else {\n return { topic: 'Current temp is Higher than SP', payload: false } // stop Heat Pump\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":420,"wires":[["e41acc6ced0d69ba","e1a30f226c63f4aa"]]},{"id":"e1a30f226c63f4aa","type":"join","z":"97b34efde9c39373","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":670,"y":380,"wires":[["bfd2883a5d538335","46de46c1a0192f71"]]},{"id":"bfd2883a5d538335","type":"function","z":"97b34efde9c39373","name":"Compare both","func":"// check if living or || dining need HP on \nif (msg.payload.living || msg.payload.dining) {\n msg.payload = true\n}\nelse {\n msg.payload = false\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":840,"y":380,"wires":[["b98d8ffb67ea0fa0","febbe31b66300cba"]]},{"id":"46de46c1a0192f71","type":"debug","z":"97b34efde9c39373","name":"Status Join","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":830,"y":180,"wires":[]},{"id":"febbe31b66300cba","type":"debug","z":"97b34efde9c39373","name":"satus CMP","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1070,"y":180,"wires":[]},{"id":"c389e1d7ecaa6e32","type":"s7 endpoint","transport":"iso-on-tcp","address":"192.168.178.249","port":"102","rack":"0","slot":"2","localtsaphi":"02","localtsaplo":"00","remotetsaphi":"02","remotetsaplo":"00","connmode":"tsap","adapter":"","busaddr":"2","cycletime":"500","timeout":"1500","name":"LOGO!","vartable":[{"addr":"Q0.0","name":"RELAY_0"},{"addr":"Q0.1","name":"RELAY_1"},{"addr":"Q0.2","name":"RELAY_2"},{"addr":"I0.0","name":"INPUT_1"}]},{"id":"c2e6322e.33404","type":"fritz-api","name":"fritzBox","host":"http://fritz.box","strictSSL":true}]

```

Thank you very very much, for your help!

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [7 November 2021 10:50 UTC](https://discourse.nodered.org/t/controlling-a-heat-pump-with-two-temperatures-and-a-setpoint-problem-with-or-logic-gate/53309/6 "2021-11-07T10:50:38Z")

</div>

Hello .. i notice that you didnt include the changes in the TEST\_FC functions  
i had a _unique_ topic for each (living / dining) because thats how the Join node is going to differentiate the messages and merge them accordingly.

```auto
if (actual_temp < comfort_temp) {
    return { topic: "living", description: 'Current living temp is Less than SP', payload: true } // start Heat Pump
} else {
    return { topic: "living", description: 'Current living temp is Higher than SP', payload: false } // stop Heat Pump
}

```

and `topic: "dining"` .. for the dining function

---

<div class="post-metadata">

**Author:** ![lale02](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@lale02](https://discourse.nodered.org/u/lale02)\
**Post date:** [7 November 2021 15:19 UTC](https://discourse.nodered.org/t/controlling-a-heat-pump-with-two-temperatures-and-a-setpoint-problem-with-or-logic-gate/53309/7 "2021-11-07T15:19:09Z")

</div>

Sorry mate, didn't pay attention, it was a middle of the night 😃  
It works now, this is exactly what I needed to complete my home heating system automation...

Thank you very very much.

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [7 November 2021 16:12 UTC](https://discourse.nodered.org/t/controlling-a-heat-pump-with-two-temperatures-and-a-setpoint-problem-with-or-logic-gate/53309/8 "2021-11-07T16:12:25Z")

</div>

> [@lale02](#):
>
> Sorry mate, didn't pay attention, it was a middle of the night

glad it worked .. yea .. it was pretty late for me also.  
so late that i didnt ask you the more important question!  
whether those manual (true/false) Inject nodes just before the S7, triggered the relay correctly ..  
in order to exclude the problem being S7 configuration 😉

---

<div class="post-metadata">

**Author:** ![lale02](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@lale02](https://discourse.nodered.org/u/lale02)\
**Post date:** [7 November 2021 20:47 UTC](https://discourse.nodered.org/t/controlling-a-heat-pump-with-two-temperatures-and-a-setpoint-problem-with-or-logic-gate/53309/9 "2021-11-07T20:47:51Z")

</div>

Those nodes are just for testing purposes and reset (false signal to S7) of relay when my broken code send true :D... and config of S7 and node red is flawless...

Once more thank you, I am sure that I will have a lot more questions in near future 😃

---

<div class="post-metadata">

**Author:** ![lale02](https://avatars.discourse-cdn.com/v4/letter/l/8e8cbc/32.png) [@lale02](https://discourse.nodered.org/u/lale02)\
**Post date:** [10 November 2021 22:47 UTC](https://discourse.nodered.org/t/controlling-a-heat-pump-with-two-temperatures-and-a-setpoint-problem-with-or-logic-gate/53309/10 "2021-11-10T22:47:29Z")

</div>

And here I am with a new problem ...  
I need an ON - OFF Switch  
The problem is that now every time setpoint is higher than Actual temp my boiler starts automatically, and in general that is OK, but last night i almost got cooked, in the room temp was 18 and setpoint was 23, so heating started and I need a ON/OFF switch, and for now i do not need scheduler

```auto
[{"id":"008dfd528f34118c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"806ecf7585607252","type":"inject","z":"008dfd528f34118c","name":"inject heater_id_Living","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"099950821892","payloadType":"str","x":130,"y":200,"wires":[["dab3211cea074ab9"]]},{"id":"dab3211cea074ab9","type":"fritz-thermostat","z":"008dfd528f34118c","connection":"b2f98ff63f15313d","name":"Living","action":"getDevice","x":330,"y":200,"wires":[["64e73e1540a03bd3"]]},{"id":"64e73e1540a03bd3","type":"function","z":"008dfd528f34118c","name":"Living","func":"let actual_temp = msg.payload.temperature.celsius / 10\nlet sp_temp = msg.payload.hkr.tsoll * 0.5\n\nnode.status({ fill: \"green\", shape: \"dot\", text: `Actual Temp: ${actual_temp} SetPoint Temp: ${sp_temp}` });\n\nif (actual_temp < sp_temp && sp_temp < 126.5) {\n return { topic: \"living\", description: 'Current living temp is Less than SP', payload: true } // start Heat Pump\n} else {\n return { topic: \"living\", description: 'Current living temp is Higher than SP', payload: false } // stop Heat Pump\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":200,"wires":[["61f18da9735de85d"]]},{"id":"5cc4fdc911815f65","type":"inject","z":"008dfd528f34118c","name":"inject heater_id_Dining","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"099950818803","payloadType":"str","x":130,"y":320,"wires":[["7096aee1efea4adb"]]},{"id":"7096aee1efea4adb","type":"fritz-thermostat","z":"008dfd528f34118c","connection":"b2f98ff63f15313d","name":"Dining","action":"getDevice","x":330,"y":320,"wires":[["ec709524f10d558e"]]},{"id":"ec709524f10d558e","type":"function","z":"008dfd528f34118c","name":"Dining","func":"let actual_temp = msg.payload.temperature.celsius / 10\nlet sp_temp = msg.payload.hkr.tsoll * 0.5\n\nnode.status({ fill: \"green\", shape: \"dot\", text: `Actual Temp: ${actual_temp} SetPoint Temp: ${sp_temp}` });\n\nif (actual_temp < sp_temp && sp_temp < 126.5) {\n return { topic: \"dining\", description: 'Current dining temp is Less than SP', payload: true } // start Heat Pump\n} else {\n return { topic: \"dining\", description: 'Current dining temp is Higher than SP', payload: false } // stop Heat Pump\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":320,"wires":[["61f18da9735de85d"]]},{"id":"61f18da9735de85d","type":"join","z":"008dfd528f34118c","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":690,"y":260,"wires":[["301a145250ea1fb7"]]},{"id":"301a145250ea1fb7","type":"function","z":"008dfd528f34118c","name":"OR Logic","func":"// check if living or || dining need HP on \nif (msg.payload.living || msg.payload.dining) {\n msg.payload.orlogic = true\n}\nelse {\n msg.payload.orlogic = false\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":840,"y":260,"wires":[["7806f4a093a0e2cf"]]},{"id":"d37c71f230bc835c","type":"debug","z":"008dfd528f34118c","name":"HEAT ON OFF","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1240,"y":260,"wires":[]},{"id":"7806f4a093a0e2cf","type":"function","z":"008dfd528f34118c","name":"","func":"// check if living or || dining need HP on \nif (msg.payload.orlogic && msg.payload) {\n msg.payload.true = true\n}\nelse {\n msg.payload.true = false\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1060,"y":260,"wires":[["d37c71f230bc835c"]]},{"id":"365f0f62c31f2f20","type":"toggle","z":"008dfd528f34118c","name":"","onOffTopic":"","onValue":"true","onType":"bool","offValue":"false","offType":"bool","toggleTopic":"","toggleValue":"","toggleType":"any","passOnOff":"always","x":880,"y":360,"wires":[["7806f4a093a0e2cf","ed5a066a12b17807"]]},{"id":"ae6d6cadd4470a69","type":"inject","z":"008dfd528f34118c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ON","payloadType":"str","x":710,"y":360,"wires":[["365f0f62c31f2f20"]]},{"id":"ed5a066a12b17807","type":"debug","z":"008dfd528f34118c","name":"toggle","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1070,"y":360,"wires":[]},{"id":"b2f98ff63f15313d","type":"fritz-api","name":"fritz","host":"http://fritz.box","strictSSL":true}]

```

Thank you very much

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [10 November 2021 23:04 UTC](https://discourse.nodered.org/t/controlling-a-heat-pump-with-two-temperatures-and-a-setpoint-problem-with-or-logic-gate/53309/11 "2021-11-10T23:04:04Z")

</div>

You can use flow Context to remember the state of the Heat Pump Switch and take that in consideration in your Boolean logic (same function can do both checks .. setpoints and general switch)

```auto
[{"id":"64e73e1540a03bd3","type":"function","z":"008dfd528f34118c","name":"Living","func":"let actual_temp = msg.payload.temperature.celsius / 10\nlet sp_temp = msg.payload.hkr.tsoll * 0.5\n\nnode.status({ fill: \"green\", shape: \"dot\", text: `Actual Temp: ${actual_temp} SetPoint Temp: ${sp_temp}` });\n\nif (actual_temp < sp_temp && sp_temp < 126.5) {\n return { topic: \"living\", description: 'Current living temp is Less than SP', payload: true } // start Heat Pump\n} else {\n return { topic: \"living\", description: 'Current living temp is Higher than SP', payload: false } // stop Heat Pump\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":200,"wires":[["61f18da9735de85d"]]},{"id":"ec709524f10d558e","type":"function","z":"008dfd528f34118c","name":"Dining","func":"let actual_temp = msg.payload.temperature.celsius / 10\nlet sp_temp = msg.payload.hkr.tsoll * 0.5\n\nnode.status({ fill: \"green\", shape: \"dot\", text: `Actual Temp: ${actual_temp} SetPoint Temp: ${sp_temp}` });\n\nif (actual_temp < sp_temp && sp_temp < 126.5) {\n return { topic: \"dining\", description: 'Current dining temp is Less than SP', payload: true } // start Heat Pump\n} else {\n return { topic: \"dining\", description: 'Current dining temp is Higher than SP', payload: false } // stop Heat Pump\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":470,"y":320,"wires":[["61f18da9735de85d"]]},{"id":"61f18da9735de85d","type":"join","z":"008dfd528f34118c","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":690,"y":260,"wires":[["301a145250ea1fb7"]]},{"id":"301a145250ea1fb7","type":"function","z":"008dfd528f34118c","name":"Heat Pump Logic","func":"// check if living OR || dining need HP on\n// AND && HP_Switch true\n\nlet HP_Switch = flow.get(\"HP_Switch\") || false // default to false \n\n\nif ((msg.payload.living || msg.payload.dining) && (HP_Switch === true)) {\n msg.payload = true\n}\nelse {\n msg.payload = false\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":910,"y":260,"wires":[["d37c71f230bc835c"]]},{"id":"d37c71f230bc835c","type":"debug","z":"008dfd528f34118c","name":"HEAT ON OFF","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1160,"y":260,"wires":[]},{"id":"ae6d6cadd4470a69","type":"inject","z":"008dfd528f34118c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":690,"y":420,"wires":[["15f8b3651d85ba94"]]},{"id":"15f8b3651d85ba94","type":"function","z":"008dfd528f34118c","name":"set HP_Switch context","func":"// https://nodered.org/docs/user-guide/writing-functions#storing-data\n\nflow.set(\"HP_Switch\", msg.payload)\n\nreturn null;","outputs":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":900,"y":440,"wires":[]},{"id":"76da6d9d3109305f","type":"inject","z":"008dfd528f34118c","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":690,"y":480,"wires":[["15f8b3651d85ba94"]]}]

```

---

<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:** [24 November 2021 23:04 UTC](https://discourse.nodered.org/t/controlling-a-heat-pump-with-two-temperatures-and-a-setpoint-problem-with-or-logic-gate/53309/12 "2021-11-24T23:04:26Z")

</div>

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