# Change variable type?

**URL:** https://discourse.nodered.org/t/change-variable-type/97321
**Category:** General
**Created:** [29 May 2025 10:32 UTC](https://discourse.nodered.org/t/change-variable-type/97321 "2025-05-29T10:32:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![acestu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/acestu/32/90408_2.png) [@acestu](https://discourse.nodered.org/u/acestu)
#### Post date: [29 May 2025 10:32 UTC](https://discourse.nodered.org/t/change-variable-type/97321/1 "2025-05-29T10:32:10Z")

</div>

Hi,

I have some formula nodes which work out temperatures from incoming mqtt messages, in the node they say var temp1, var temp 2 etc, my question is can i change the var to global. so that the information can be harvested to create a file with current temperatures ?

Thanks  
Stuart

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [29 May 2025 10:47 UTC](https://discourse.nodered.org/t/change-variable-type/97321/2 "2025-05-29T10:47:52Z")

</div>

you can store your values in global or flow context using a change node.

`function:calc temp` --\> `change:set global.temp to the value of msg.payload`

You can also do it directly in a function node using `global.set("name", value)`

At some later timed event, you can then grab the value from global context

`inject:every-hour` --\> `change:set msg.payload to value of global.temp` --\> DB node (or file node or whatever)

Context is covered in the recommend playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<div class="post-metadata">

### Author: ![acestu](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/acestu/32/90408_2.png) [@acestu](https://discourse.nodered.org/u/acestu)
#### Post date: [29 May 2025 10:51 UTC](https://discourse.nodered.org/t/change-variable-type/97321/3 "2025-05-29T10:51:18Z")

</div>

Hi Steve,  
Thanks for this I will look at the videos tonight

Stuart

---

<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: [27 August 2025 10:51 UTC](https://discourse.nodered.org/t/change-variable-type/97321/4 "2025-08-27T10:51:33Z")

</div>

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