# Help with inserting number into json

**URL:** <https://discourse.nodered.org/t/help-with-inserting-number-into-json/36890>\
**Category:** General\
**Created:** [2 December 2020 17:30 UTC](https://discourse.nodered.org/t/help-with-inserting-number-into-json/36890 "2020-12-02T17:30:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![SamBozman](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sambozman/32/17606_2.png) [@SamBozman](https://discourse.nodered.org/u/SamBozman)\
**Post date:** [2 December 2020 17:30 UTC](https://discourse.nodered.org/t/help-with-inserting-number-into-json/36890/1 "2020-12-02T17:30:20Z")

</div>

Hi everyone,  
I have a simple problem but unfortunately, I am even more so. I have a flow that I want to use to retrieve the set temperature of my climate system, and then set the new temperature of the furnace to 2 degrees less. I have already learned how to retrieve the 'set temperature' and placed it into the flow as "msg.payload".

```auto
var setTemp = msg.data.attributes.temperature-2;
msg.payload=setTemp;
return msg;

```

As you can see above, I have retrieved the set temperature of the climate control and I have subtracted 2 degrees C from this value and placed it into the msg.payload. This part works fine

Then, I know how to use a 'Call Service' node to set the temperature with data like {"temperature":22};  
However, I do not know how to insert the msg.payload in place of the number (in this case 22)  
Here is the complete flow. Just the last node 'Set Temp' is the problem.

```auto
[{"id":"94492e5d.e42928","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"e56ba6e.21bfad8","type":"debug","z":"94492e5d.e42928","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":610,"y":100,"wires":[]},{"id":"a79705ba.3185d8","type":"inject","z":"94492e5d.e42928","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":160,"wires":[["865e6bcc.52643"]]},{"id":"d257d30b.6fb71","type":"function","z":"94492e5d.e42928","name":"","func":"var setTemp = msg.data.attributes.temperature-2;\nmsg.payload=setTemp;\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":320,"y":160,"wires":[["74bc2b60.be6bbc"]]},{"id":"865e6bcc.52643","type":"api-current-state","z":"94492e5d.e42928","name":"test","server":"1d707c49.07a204","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"climate.thermostat","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":110,"y":100,"wires":[["20092d4f.3f4682"]]},{"id":"20092d4f.3f4682","type":"switch","z":"94492e5d.e42928","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"heat","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":270,"y":100,"wires":[["d257d30b.6fb71"],[]]},{"id":"74bc2b60.be6bbc","type":"api-call-service","z":"94492e5d.e42928","name":"Set Temp","server":"fee4c7b2.b5e188","version":1,"debugenabled":false,"service_domain":"climate","service":"set_temperature","entityId":"climate.thermostat","data":"{\"temperature\":20}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":480,"y":120,"wires":[["e56ba6e.21bfad8"]]},{"id":"1d707c49.07a204","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true},{"id":"fee4c7b2.b5e188","type":"server","name":"Home Assistant","addon":true}]

```

Thanks  
Sam

---

<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:** [2 December 2020 17:43 UTC](https://discourse.nodered.org/t/help-with-inserting-number-into-json/36890/2 "2020-12-02T17:43:04Z")

</div>

Call service is a HA node, none standard, I do not use i. I believe you can create the json in a template node and feed it to the callservice block

---

<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:** [2 December 2020 20:59 UTC](https://discourse.nodered.org/t/help-with-inserting-number-into-json/36890/3 "2020-12-02T20:59:44Z")

</div>

If you mean instead of returning setTemp in the payload you want to return the object `{temperature: 22}` if setTemp is 22 then instead of  
`msg.payload = setTemp`  
use  
`msg.payload = {temperature: setTemp}`  
You don't need the quotes round temperature in javascript when the property name (temperature) does not include any special characters.

---

<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:** [31 January 2021 20:59 UTC](https://discourse.nodered.org/t/help-with-inserting-number-into-json/36890/4 "2021-01-31T20:59:49Z")

</div>

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