# Environment variable in dropdown fields

**URL:** <https://discourse.nodered.org/t/environment-variable-in-dropdown-fields/70144>\
**Category:** General\
**Created:** [6 November 2022 06:24 UTC](https://discourse.nodered.org/t/environment-variable-in-dropdown-fields/70144 "2022-11-06T06:24:17Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![plopp79](https://avatars.discourse-cdn.com/v4/letter/p/7c8e57/32.png) [@plopp79](https://discourse.nodered.org/u/plopp79)\
**Post date:** [6 November 2022 06:24 UTC](https://discourse.nodered.org/t/environment-variable-in-dropdown-fields/70144/1 "2022-11-06T06:24:17Z")

</div>

Hello,

I'm brand new to Node Red and have used fhem and iobroker before. But I'm really excited about the flexibility and possibilities that Node Red has to offer me.

I've already tried around a bit and quickly reached my limits, as I'm still lacking an overview.

I'm currently trying to create my devices and would like to delegate the setting options for this from top to bottom. (It should also be fixed settings)

But I also have components in the subflow that have a dropdown field as a setting option, and I would also like to transfer my environment variables in these settings.

E.g. Google smarthome with the device type or dashboard UI with the tabs and sliders.

Does anyone know of a way to transfer the data from an environment variable into this fields?

Possibly through an extension or are there already integrated commands that allow me to do this?

In case of doubt, probably I could work with the nodes file-read and file-write or with exec and sed, for example. But that wouldn't be the most elegant solution for me.

---

<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:** [6 November 2022 09:07 UTC](https://discourse.nodered.org/t/environment-variable-in-dropdown-fields/70144/2 "2022-11-06T09:07:08Z")

</div>

Welcome to the forum @plopp79

This page in the docs describes the many ways to use env variables in node red. Start by reading through that, then come back if you need further help. [Using environment variables : Node-RED](https://nodered.org/docs/user-guide/environment-variables)

---

<div class="post-metadata">

**Author:** ![plopp79](https://avatars.discourse-cdn.com/v4/letter/p/7c8e57/32.png) [@plopp79](https://discourse.nodered.org/u/plopp79)\
**Post date:** [6 November 2022 14:57 UTC](https://discourse.nodered.org/t/environment-variable-in-dropdown-fields/70144/3 "2022-11-06T14:57:07Z")

</div>

I already know this site. I didn't find a solution to my problem there.

---

<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:** [6 November 2022 15:02 UTC](https://discourse.nodered.org/t/environment-variable-in-dropdown-fields/70144/4 "2022-11-06T15:02:28Z")

</div>

You can specify your env var in the properties of the subflow, then use that inside the subflow when you build the dropdown list.

**[Edit]** Perhaps I misunderstand. What do you mean by

> [@plopp79](#):
>
> components in the subflow that have a dropdown field as a setting option

---

<div class="post-metadata">

**Author:** ![plopp79](https://avatars.discourse-cdn.com/v4/letter/p/7c8e57/32.png) [@plopp79](https://discourse.nodered.org/u/plopp79)\
**Post date:** [7 November 2022 06:16 UTC](https://discourse.nodered.org/t/environment-variable-in-dropdown-fields/70144/5 "2022-11-07T06:16:44Z")

</div>

Hello Colin,

Thank you very much for your help, It's nice to be helped like this here.  
I'll try to explain it with an example. This example has the add-on Dashboard-ui

```auto
[{"id":"8a8858a059602f06","type":"subflow","name":"example (2)","info":"","category":"Shelly http","in":[],"out":[],"env":[{"name":"room or tab","type":"str","value":"Livingroom"},{"name":"slider","type":"str","value":"Buttons"}],"meta":{"module":"shelly_http","license":"Apache-2.0"},"color":"#ff7f24","icon":"node-red-dashboard/ui_switch.png"},{"id":"2e061d1f7e33a836","type":"ui_switch","z":"8a8858a059602f06","name":"","label":"switch","tooltip":"","group":"b861a8386c93496d","order":1,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","animate":false,"className":"","x":530,"y":200,"wires":[[]]},{"id":"b861a8386c93496d","type":"ui_group","name":"Schalter","tab":"3616a722.b89bc8","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"3616a722.b89bc8","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

There's a switch that i want to use the variables to tell which tab to end up in.

And could I give a "Link in" field a name via a variable or maybe also a msg?

---

<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 November 2022 11:25 UTC](https://discourse.nodered.org/t/environment-variable-in-dropdown-fields/70144/6 "2022-11-07T11:25:19Z")

</div>

> [@plopp79](#):
>
> There's a switch that i want to use the variables to tell which tab to end up in.

Enter the env var in the subflow properties and use that in the switch.

---

<div class="post-metadata">

**Author:** ![plopp79](https://avatars.discourse-cdn.com/v4/letter/p/7c8e57/32.png) [@plopp79](https://discourse.nodered.org/u/plopp79)\
**Post date:** [8 November 2022 05:52 UTC](https://discourse.nodered.org/t/environment-variable-in-dropdown-fields/70144/7 "2022-11-08T05:52:57Z")

</div>

Yes, I have already entered the var in the subflow properties, but were and how could I enter the env in the switch? There is only a dropdown menu 🙂

---

<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:** [8 November 2022 09:08 UTC](https://discourse.nodered.org/t/environment-variable-in-dropdown-fields/70144/8 "2022-11-08T09:08:42Z")

</div>

I have just realised fully what you are trying to do. I think you have the bigger problem that you cannot put dashboard nodes in subflows. Not reliably at least.

---

<div class="post-metadata">

**Author:** ![plopp79](https://avatars.discourse-cdn.com/v4/letter/p/7c8e57/32.png) [@plopp79](https://discourse.nodered.org/u/plopp79)\
**Post date:** [10 November 2022 03:26 UTC](https://discourse.nodered.org/t/environment-variable-in-dropdown-fields/70144/9 "2022-11-10T03:26:21Z")

</div>

Hello Colin,

thank you for your support. I've now thought of a different structure. But could you explain your last statement to me why that is?

---

<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:** [9 January 2023 03:26 UTC](https://discourse.nodered.org/t/environment-variable-in-dropdown-fields/70144/10 "2023-01-09T03:26:58Z")

</div>

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