# How does one set a "parameter" via a global variable

**URL:** <https://discourse.nodered.org/t/how-does-one-set-a-parameter-via-a-global-variable/46800>\
**Category:** General\
**Created:** [7 June 2021 09:11 UTC](https://discourse.nodered.org/t/how-does-one-set-a-parameter-via-a-global-variable/46800 "2021-06-07T09:11:34Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![eddee54455](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eddee54455/32/43350_2.png) [@eddee54455](https://discourse.nodered.org/u/eddee54455)\
**Post date:** [7 June 2021 09:11 UTC](https://discourse.nodered.org/t/how-does-one-set-a-parameter-via-a-global-variable/46800/1 "2021-06-07T09:11:34Z")

</div>

Good day learned ones!

I have a need to be able to set a serial port address from an defined variable that I can input via a dashboard....

Particularly these bits (particularly the Port Address, More if possible....)

![screenshot-192.168.0.118_1880-2021.06.07-10_45_26](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/0/b04726f2d57bc38a265e9b97cb3cae9b29b5c00f.png)

I am not sure whether it is possible, but any help would be awesome!

TIA  
Ed

---

<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:** [7 June 2021 10:16 UTC](https://discourse.nodered.org/t/how-does-one-set-a-parameter-via-a-global-variable/46800/2 "2021-06-07T10:16:52Z")

</div>

You might be able to set the port using an env variable but I dont think the other values can be set dynamically.

To use an env var in a config var, see [Using environment variables : Node-RED](https://nodered.org/docs/user-guide/environment-variables#setting-a-node-property)

---

<div class="post-metadata">

**Author:** ![eddee54455](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eddee54455/32/43350_2.png) [@eddee54455](https://discourse.nodered.org/u/eddee54455)\
**Post date:** [7 June 2021 12:37 UTC](https://discourse.nodered.org/t/how-does-one-set-a-parameter-via-a-global-variable/46800/3 "2021-06-07T12:37:56Z")

</div>

Thanks Steve,

I will go through it and give it a go!

Much appreciated!!

Ed

---

<div class="post-metadata">

**Author:** ![EmilWesselink](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/emilwesselink/32/65829_2.png) [@EmilWesselink](https://discourse.nodered.org/u/EmilWesselink)\
**Post date:** [7 June 2021 12:48 UTC](https://discourse.nodered.org/t/how-does-one-set-a-parameter-via-a-global-variable/46800/4 "2021-06-07T12:48:58Z")

</div>

Where I am curious about is, what is the case between it? Maybe you can change your approach and instead of port select the serial device by ID. See /dev/serial/by-id in your linux machine.

---

<div class="post-metadata">

**Author:** ![eddee54455](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eddee54455/32/43350_2.png) [@eddee54455](https://discourse.nodered.org/u/eddee54455)\
**Post date:** [7 June 2021 13:08 UTC](https://discourse.nodered.org/t/how-does-one-set-a-parameter-via-a-global-variable/46800/5 "2021-06-07T13:08:42Z")

</div>

Hi @EmilWesselink

I was previously using by-path, so it should work to use by-id - I just need to wrap my head around selecting this setting from a dashboard and seeing if it can be done...

E

---

<div class="post-metadata">

**Author:** ![EmilWesselink](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/emilwesselink/32/65829_2.png) [@EmilWesselink](https://discourse.nodered.org/u/EmilWesselink)\
**Post date:** [7 June 2021 13:14 UTC](https://discourse.nodered.org/t/how-does-one-set-a-parameter-via-a-global-variable/46800/6 "2021-06-07T13:14:40Z")

</div>

No but if you want to change the input make a flow with a switch that looks to a global variable. And connect all devices on a seperate input node, but let the switch only pass the ones that are selected based on the value of the global variable.

---

<div class="post-metadata">

**Author:** ![eddee54455](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eddee54455/32/43350_2.png) [@eddee54455](https://discourse.nodered.org/u/eddee54455)\
**Post date:** [7 June 2021 13:18 UTC](https://discourse.nodered.org/t/how-does-one-set-a-parameter-via-a-global-variable/46800/7 "2021-06-07T13:18:57Z")

</div>

@EmilWesselink

Ah, got you! - in my "simple terms" - set up a bunch of "default" configuration serial nodes referring to usb0/usb1/usb2 etc and just limit/enable the comms to those nodes via "switch control" ..... that might just work for me!!

Tnx  
E

Edit: I would rather go the "port" route than by name/id - If I can remember, the name/id changes according to the hardware type installed - would make the maintenance a bit easier for me in the long run, especially with my "lightning strike" track history ATM...

---

<div class="post-metadata">

**Author:** ![EmilWesselink](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/emilwesselink/32/65829_2.png) [@EmilWesselink](https://discourse.nodered.org/u/EmilWesselink)\
**Post date:** [7 June 2021 13:48 UTC](https://discourse.nodered.org/t/how-does-one-set-a-parameter-via-a-global-variable/46800/8 "2021-06-07T13:48:23Z")

</div>

That is exactly why I asked you to give some more information about what en why you to achieve something. It can give people more insight to have a alternative solution. For me the id was the best solution because the device in was always the same, only the port changed sometimes.

---

<div class="post-metadata">

**Author:** ![eddee54455](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eddee54455/32/43350_2.png) [@eddee54455](https://discourse.nodered.org/u/eddee54455)\
**Post date:** [7 June 2021 14:25 UTC](https://discourse.nodered.org/t/how-does-one-set-a-parameter-via-a-global-variable/46800/9 "2021-06-07T14:25:13Z")

</div>

@EmilWesselink

Here's the "alternative solution" I have settled on, thanks for the pointer into this direction!

![screenshot-192.168.0.118_1880-2021.06.07-16_22_04](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/9/79ffc45ceb3c9e44ac4d9843cf2204c053534d73.png)

Depending on a global variable written to disk in the parameters, the switch nodes only allow writing to a particular usb port and reading from that same usb port....

Regds  
Ed

---

<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:** [7 June 2021 14:39 UTC](https://discourse.nodered.org/t/how-does-one-set-a-parameter-via-a-global-variable/46800/10 "2021-06-07T14:39:41Z")

</div>

If you only ever have one serial usb device plugged in the you could use a udev rule to map _any_ serial device plugged in to a fixed virtual device to, for example, /dev/serial. Configure node red to use that device and it should work with any device. you might even be able to hot plug them, I am not sure.

---

<div class="post-metadata">

**Author:** ![eddee54455](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/eddee54455/32/43350_2.png) [@eddee54455](https://discourse.nodered.org/u/eddee54455)\
**Post date:** [7 June 2021 14:45 UTC](https://discourse.nodered.org/t/how-does-one-set-a-parameter-via-a-global-variable/46800/11 "2021-06-07T14:45:05Z")

</div>

Wont work for me.... Multiple devices, but might help someone else indeed!

But interestingly, regarding the hotplugging, I don't think it will... It seems that while an i/o can be pointed to the correct usb while "live", Node Red doesn't seem to pick it up until it is restarted with the device in place, or indeed, if node red is redeployed with a change to the usb config made to forcibly redeploy the port...

There probably is a setting/method that can be employed to rescan the ports without redeploying NR, but I will need to look around to see if I can find anything...

E

---

<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:** [21 June 2021 14:45 UTC](https://discourse.nodered.org/t/how-does-one-set-a-parameter-via-a-global-variable/46800/12 "2021-06-21T14:45:20Z")

</div>

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