# Turn heating down while window is open

**URL:** <https://discourse.nodered.org/t/turn-heating-down-while-window-is-open/34643>\
**Category:** General\
**Created:** [21 October 2020 17:19 UTC](https://discourse.nodered.org/t/turn-heating-down-while-window-is-open/34643 "2020-10-21T17:19:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![terminus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/terminus/32/38378_2.png) [@terminus](https://discourse.nodered.org/u/terminus)\
**Post date:** [21 October 2020 17:19 UTC](https://discourse.nodered.org/t/turn-heating-down-while-window-is-open/34643/1 "2020-10-21T17:19:38Z")

</div>

Hey Guys, my aim is to turn the heating in my bathroom off, if anybody opens the window. And if the window get's closed, the Heating should restore the Temperature from before.

I put this thing together but unfortunately i have often the problem, that the variable tempsetprevbath is set to 11° which should only be the case while the window is open. It seems that anything in the flow sets the "open-setting" as default temperature.. Can you help me:

```auto
[{"id":"7c2d60d2.04a9a8","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"90ed896d.43723","type":"filter","z":"7c2d60d2.04a9a8","name":"Sensorenfilter?","property":"payload.r","propertyType":"msg","asArray":false,"itemProperty":"","itemPropertyType":"item","rules":[{"t":"eq","v":"sensors","vt":"str","output":1}],"checkall":"true","outputs":1,"x":230,"y":160,"wires":[["b87a9151.edaac8"]]},{"id":"fe150591.914c1","type":"api-current-state","z":"7c2d60d2.04a9a8","name":"Status Badthermostat","server":"89ca3e9d.c3689","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"climate.danfoss_devolo_home_control_radiator_thermostat_heating_1","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1080,"y":200,"wires":[["e941bdff.753838"]]},{"id":"e941bdff.753838","type":"function","z":"7c2d60d2.04a9a8","name":"","func":"var tempsetprevbath=msg.data.attributes.temperature; //Hole aktuell eingestellte Temperatur\nflow.set('tempsetprevbath',tempsetprevbath);\nmsg.payload = tempsetprevbath;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1260,"y":200,"wires":[["53768eb0.e2866"]]},{"id":"a8be5d7f.7a7c58","type":"api-call-service","z":"7c2d60d2.04a9a8","name":"Stelle 11° ein (Heizung off)","server":"89ca3e9d.c3689","version":1,"debugenabled":false,"service_domain":"climate","service":"set_temperature","entityId":"climate.danfoss_devolo_home_control_radiator_thermostat_heating_1","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1649,"y":200,"wires":[[]]},{"id":"6d3dee35.268b6","type":"switch","z":"7c2d60d2.04a9a8","name":"","property":"payload.state.open","propertyType":"msg","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":false,"outputs":2,"x":640,"y":160,"wires":[["265bd25.1fbf42e"],["12a34d96.cdd842"]]},{"id":"265bd25.1fbf42e","type":"template","z":"7c2d60d2.04a9a8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n \"data\":{\"temperature\":\"{{{flow.tempsetprevbath}}}\" }\n }","output":"str","x":770,"y":120,"wires":[["7e6d8a10.7c8da4"]]},{"id":"7e6d8a10.7c8da4","type":"api-call-service","z":"7c2d60d2.04a9a8","name":"restore","server":"89ca3e9d.c3689","version":1,"debugenabled":false,"service_domain":"climate","service":"set_temperature","entityId":"climate.danfoss_devolo_home_control_radiator_thermostat_heating_1","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":900,"y":120,"wires":[["e0171bd7.2431f8"]]},{"id":"b87a9151.edaac8","type":"filter","z":"7c2d60d2.04a9a8","name":"Fensterkontakt Bad (ID:22)","property":"payload.id","propertyType":"msg","asArray":false,"itemProperty":"","itemPropertyType":"item","rules":[{"t":"eq","v":"22","vt":"str","output":1}],"checkall":"true","outputs":1,"x":450,"y":160,"wires":[["6d3dee35.268b6"]]},{"id":"53768eb0.e2866","type":"template","z":"7c2d60d2.04a9a8","name":"Template 12°","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n \"data\":{\"temperature\":\"11\" }\n }","output":"str","x":1439,"y":200,"wires":[["a8be5d7f.7a7c58"]]},{"id":"e0171bd7.2431f8","type":"delay","z":"7c2d60d2.04a9a8","name":"","pauseType":"delay","timeout":"60","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1069,"y":120,"wires":[["245619d2.5e55fe"]]},{"id":"245619d2.5e55fe","type":"api-current-state","z":"7c2d60d2.04a9a8","name":"","server":"89ca3e9d.c3689","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"Bad Heizung Status","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1319,"y":120,"wires":[["5c00c14e.e0a868"]]},{"id":"5c00c14e.e0a868","type":"switch","z":"7c2d60d2.04a9a8","name":"","property":"msg.data.attributes.temperature","propertyType":"msg","rules":[{"t":"eq","v":"11","vt":"num"},{"t":"neq","v":"11","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":1549,"y":120,"wires":[["5fc5063c.a018c8"],[]]},{"id":"5fc5063c.a018c8","type":"template","z":"7c2d60d2.04a9a8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\n \"data\":{\"temperature\":\"{{{flow.tempsetprevbath}}}\" }\n }","output":"str","x":1699,"y":100,"wires":[["ecfe54.3f02b9b"]]},{"id":"ecfe54.3f02b9b","type":"api-call-service","z":"7c2d60d2.04a9a8","name":"restore","server":"89ca3e9d.c3689","version":1,"debugenabled":false,"service_domain":"climate","service":"set_temperature","entityId":"climate.danfoss_devolo_home_control_radiator_thermostat_heating_1","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1829,"y":100,"wires":[[]]},{"id":"12a34d96.cdd842","type":"delay","z":"7c2d60d2.04a9a8","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"10","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":810,"y":200,"wires":[["fe150591.914c1"]]},{"id":"89ca3e9d.c3689","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [21 October 2020 19:47 UTC](https://discourse.nodered.org/t/turn-heating-down-while-window-is-open/34643/2 "2020-10-21T19:47:56Z")

</div>

I cannot test, or even understand, your flow as I don't use HA. However the general debugging strategy with this sort of problem is to put debug nodes in strategic places and when it fails find out why by looking at the debug output. It is a good idea to give the debug nodes names so that it is easier to see which is which in the debug pane.

---

<div class="post-metadata">

**Author:** ![lizzardguki](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lizzardguki/32/103637_2.png) [@lizzardguki](https://discourse.nodered.org/u/lizzardguki)\
**Post date:** [21 October 2020 19:59 UTC](https://discourse.nodered.org/t/turn-heating-down-while-window-is-open/34643/3 "2020-10-21T19:59:38Z")

</div>

My thought on this is to use a flow or global context variable , that will edit to true or false if window is open.  
And then just add an inject node that will trigger every x seconds and if windowopen === true , just send a request to HA to lower the temperature...

I haven't checked out your flow, but this is the way i would start from, and work my way up...

---

<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:** [20 December 2020 19:59 UTC](https://discourse.nodered.org/t/turn-heating-down-while-window-is-open/34643/4 "2020-12-20T19:59:47Z")

</div>

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