# Trying to set msg.payload.target\_temperature\_c

**URL:** https://discourse.nodered.org/t/trying-to-set-msg-payload-target-temperature-c/4013
**Category:** General
**Created:** [15 October 2018 23:06 UTC](https://discourse.nodered.org/t/trying-to-set-msg-payload-target-temperature-c/4013 "2018-10-15T23:06:14Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![hazymat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hazymat/32/108159_2.png) [@hazymat](https://discourse.nodered.org/u/hazymat)
#### Post date: [15 October 2018 23:06 UTC](https://discourse.nodered.org/t/trying-to-set-msg-payload-target-temperature-c/4013/1 "2018-10-15T23:06:14Z")

</div>

This is clearly a problem with my understanding, but I'm stumped!

I'm basically following the example in [this node red documentation page](https://nodered.org/docs/user-guide/messages), bottom of the section _"Changing message properties"_, except I'm injecting a numerical value.

I am using a change node to 'copy' a value (i.e. msg.payload, received from an inject node) to msg.payload.target\_temperature\_c. However when I attach a debug node to output, it just shows the value I injected in msg.payload of the output, **not** in msg.payload.target\_temperature\_c.

End result: I want to be able to update my Nest thermostat with a value from a slider on dashboard... but this is the bit that's failing.

Here's my node. When I hit the inject button, I am hoping to see msg.payload.target\_temperature\_c as the value 19. (But I'm not)

`[{"id":"d4e6120f.dc4ca","type":"debug","z":"a09201df.15c79","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1230,"y":780,"wires":[]},{"id":"fe5f46b2.f24778","type":"inject","z":"a09201df.15c79","name":"","topic":"","payload":"19","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":730,"y":780,"wires":[["35b88424.9a60dc"]]},{"id":"35b88424.9a60dc","type":"change","z":"a09201df.15c79","name":"","rules":[{"t":"set","p":"payload.target_temperature_c","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":780,"wires":[["d4e6120f.dc4ca"]]}]`

---

<div class="post-metadata">

### Author: ![Urs-Eppenberger](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/urs-eppenberger/32/28_2.png) [@Urs-Eppenberger](https://discourse.nodered.org/u/Urs-Eppenberger)
#### Post date: [16 October 2018 07:17 UTC](https://discourse.nodered.org/t/trying-to-set-msg-payload-target-temperature-c/4013/2 "2018-10-16T07:17:38Z")

</div>

I'm no expert here.  
But the following observations might help.

After the inject node, msg.payload is a string.

In the change node, you act if msg.payload is an object. This seems to fail.

In my local test installation, I expanded your change node the following way:

1. set msg.tmp to msg.payload
2. delete msg.payload
3. set msg.payload.target\_whatever to msg.tmp

This did the trick. But it might not be the most efficient solution. Let's see what the more knowledgeable forum members have to say.

Kind regards,

Urs.

---

<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: [16 October 2018 07:27 UTC](https://discourse.nodered.org/t/trying-to-set-msg-payload-target-temperature-c/4013/3 "2018-10-16T07:27:09Z")

</div>

Modify the Change node so that it Moves msg.payload To msg.payload.target\_temperatue\_c and it will work.

```auto
[{"id":"2a30b5d9.53e5ea","type":"inject","z":"6dc690a3.1abc88","name":"","topic":"","payload":"19","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":445,"wires":[["f866e9.acc5c118"]]},{"id":"45f2ffe4.1fbcf8","type":"debug","z":"6dc690a3.1abc88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":508,"y":444,"wires":[]},{"id":"f866e9.acc5c118","type":"change","z":"6dc690a3.1abc88","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.target_temperature_c","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":302,"y":445,"wires":[["45f2ffe4.1fbcf8"]]}]

```

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [16 October 2018 07:28 UTC](https://discourse.nodered.org/t/trying-to-set-msg-payload-target-temperature-c/4013/4 "2018-10-16T07:28:31Z")

</div>

> [@Urs-Eppenberger](#):
>
> After the inject node, msg.payload is a string.
> 
> In the change node, you act if msg.payload is an object. This seems to fail.

That is correct - strings cannot have properties. JavaScript will let you set them but it will fail silently.

Rather than copy, you can configure the Change node to **move** `msg.payload` to `msg.payload.target_temperature_c` and it will work.

---

<div class="post-metadata">

### Author: ![hazymat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hazymat/32/108159_2.png) [@hazymat](https://discourse.nodered.org/u/hazymat)
#### Post date: [16 October 2018 17:49 UTC](https://discourse.nodered.org/t/trying-to-set-msg-payload-target-temperature-c/4013/5 "2018-10-16T17:49:23Z")

</div>

Thanks all, that helped my understanding.

Aside: how can I post my node code here on this forum to display on a single line, as was done by @Colin?

---

<div class="post-metadata">

### Author: ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)
#### Post date: [16 October 2018 18:04 UTC](https://discourse.nodered.org/t/trying-to-set-msg-payload-target-temperature-c/4013/6 "2018-10-16T18:04:03Z")

</div>

you need to  
start with three backtic's,  
then on the next line put your flow,  
then on the next line three more backtic's

---

<div class="post-metadata">

### Author: ![hazymat](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hazymat/32/108159_2.png) [@hazymat](https://discourse.nodered.org/u/hazymat)
#### Post date: [16 October 2018 18:07 UTC](https://discourse.nodered.org/t/trying-to-set-msg-payload-target-temperature-c/4013/7 "2018-10-16T18:07:43Z")

</div>

@zenofmud Many thanks!

---

<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: [16 October 2018 19:37 UTC](https://discourse.nodered.org/t/trying-to-set-msg-payload-target-temperature-c/4013/8 "2018-10-16T19:37:13Z")

</div>

> [@zenofmud](#):
>
> then on the next line put your flow

In addition, if you want it to just take one line then when you export choose `Compact` down at the bottom right of the export window.
