# Deactivate Heating while window is open

**URL:** <https://discourse.nodered.org/t/deactivate-heating-while-window-is-open/34098>\
**Category:** General\
**Created:** [11 October 2020 14:57 UTC](https://discourse.nodered.org/t/deactivate-heating-while-window-is-open/34098 "2020-10-11T14:57:20Z")\
**Posts on this page:** 7\
**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:** [11 October 2020 14:57 UTC](https://discourse.nodered.org/t/deactivate-heating-while-window-is-open/34098/1 "2020-10-11T14:57:21Z")

</div>

Hello Guys,  
this is a beginner question for a node-red beginner as I am 🙂  
What I'm trying to archieve is a flow in which my radiators turning down as the window get's opened. So I'm filtering my DeConz events on that binary window sensor. If the status changes, the flow gets the current state of the heating vave / the temperature setting of it. This is here in the message object:

data.attributes.temperature

So I thought I need a function node which reads this setting, stores it and then reduces the setting to e.g. 12°C. And if the window gets closed again, it restores the previous setting. So I think the scope of my variable has to be flow-wide.

I started to write the following function:

```auto
var tempsetprev=data.attributes.temperature; //Hole aktuell eingestellte Temperatur
flow.set('tempsetprev',temsetprev);
msg.payload = tempsetprev;
return msg;

```

But I get: "ReferenceError: data is not defined (line 1, col 17)"  
Can you help me where I'm wrong?

Regards

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [11 October 2020 15:08 UTC](https://discourse.nodered.org/t/deactivate-heating-while-window-is-open/34098/2 "2020-10-11T15:08:07Z")

</div>

Add a debug set to show complete message and show us what the message really is.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [11 October 2020 15:42 UTC](https://discourse.nodered.org/t/deactivate-heating-while-window-is-open/34098/3 "2020-10-11T15:42:51Z")

</div>

`data` comes from where? Are you sure that is what is being passed to the function? Rather than the standard message object?

---

<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:** [11 October 2020 18:45 UTC](https://discourse.nodered.org/t/deactivate-heating-while-window-is-open/34098/4 "2020-10-11T18:45:58Z")

</div>

this is the data, coming from the current state node:

```auto
msg : Object
object
_msgid: "bcf5b49.6d22348"
payload: "unknown"
topic: ""
data: object
entity_id: "climate.danfoss_devolo_home_control_radiator_thermostat_heating_1"
state: "unknown"
attributes: object
hvac_modes: array[0]
min_temp: 7
max_temp: 35
current_temperature: 21.6
temperature: 20
node_id: 6
value_index: 1
value_instance: 1
value_id: "72057594143883282"
friendly_name: "Heizungsventil Bad"
supported_features: 1
last_changed: "2020-10-10T13:26:13.097704+00:00"
last_updated: "2020-10-11T13:43:54.738486+00:00"
context: object
timeSinceChangedMs: 91665546

```

next to this I added the function node.

---

<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:** [11 October 2020 19:31 UTC](https://discourse.nodered.org/t/deactivate-heating-while-window-is-open/34098/5 "2020-10-11T19:31:34Z")

</div>

Hi, you missed the msg. of the beginning

```auto
msg.data.attributes.temperature

```

When you copy the path it does not add the msg starting object.

---

<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:** [11 October 2020 20:15 UTC](https://discourse.nodered.org/t/deactivate-heating-while-window-is-open/34098/6 "2020-10-11T20:15:16Z")

</div>

thank you, that takes me one step forward 🙂

---

<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:** [10 December 2020 20:15 UTC](https://discourse.nodered.org/t/deactivate-heating-while-window-is-open/34098/7 "2020-12-10T20:15:21Z")

</div>

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