# Variables in edit fields

**URL:** <https://discourse.nodered.org/t/variables-in-edit-fields/83281>\
**Category:** General\
**Created:** [29 November 2023 12:25 UTC](https://discourse.nodered.org/t/variables-in-edit-fields/83281 "2023-11-29T12:25:29Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![GretaC](https://avatars.discourse-cdn.com/v4/letter/g/bb73d2/32.png) [@GretaC](https://discourse.nodered.org/u/GretaC)\
**Post date:** [29 November 2023 12:25 UTC](https://discourse.nodered.org/t/variables-in-edit-fields/83281/1 "2023-11-29T12:25:29Z")

</div>

Is there any way to use variables instead of strings in edit fields of a node?  
To make it concrete:  
In case of e.g. MQTT I have some devices of the same type. All devices have a couple of properties.  
In order to access the same property of different devices I have to use the same 'Topic' with one difference, the address of the device. So I wonder if it is possible to replace the cryptic address (e.g. 0001204302303 ) by a more intuitive name like 'tempOffice'.

In general: is it possible to use variables for fields in nodes, for example the 'Name' field. No matter if it is wise here or not. 😉

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [29 November 2023 12:34 UTC](https://discourse.nodered.org/t/variables-in-edit-fields/83281/2 "2023-11-29T12:34:33Z")

</div>

Using Variables in Nodes properties, is well supported, and is dependant on the node supporting it.

Example - the inject node supporting the `global` context

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/1/61b03646588658022e2e5c60979ae18b68482038.png)

The name of a node however, **CAN NOT** be taken from a variable. in all my time using Node RED, the name of a node in your flow, is always a static value.

Other properties, again... Node Dependant, does support variables.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [29 November 2023 12:45 UTC](https://discourse.nodered.org/t/variables-in-edit-fields/83281/3 "2023-11-29T12:45:29Z")

</div>

Regarding the MQTT in node, it does offer dynamic subscriptions, which let you unsubscribe from one topic and subscribe to another.

But in your case of multiple devices of the same type, do they let you change the mqtt topic?

If so use a topic such as `peskysensor/<sensor id>` and subscribe to `peskysensor/#`.

Edit - changed "#" to "+" in the hope of reducing unnecessary message delivery.  
If they don't, I guess a workaround might be to subscribe to `+`, use a switch node to check if msg.topic matches the regex for 13 digits and republish to `peskysensor/<inbound topic>`

Of course your downstream flow has to handle messages from different devices.

---

<div class="post-metadata">

**Author:** ![GretaC](https://avatars.discourse-cdn.com/v4/letter/g/bb73d2/32.png) [@GretaC](https://discourse.nodered.org/u/GretaC)\
**Post date:** [29 November 2023 12:49 UTC](https://discourse.nodered.org/t/variables-in-edit-fields/83281/4 "2023-11-29T12:49:55Z")

</div>

I talk about something like this:

 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/9/19bb2c8461309f8f8d10aeeeb97d9f74be472723.png)  
The 'Topic' doesn't offer it in a generic way.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [29 November 2023 12:51 UTC](https://discourse.nodered.org/t/variables-in-edit-fields/83281/5 "2023-11-29T12:51:52Z")

</div>

Take a look at the section on MQTT wildcards in this page [https://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices/](https://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices/)

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [29 November 2023 12:52 UTC](https://discourse.nodered.org/t/variables-in-edit-fields/83281/6 "2023-11-29T12:52:04Z")

</div>

If there is no dropdown - to switch to using a context variable, then no.  
But as @jbudd said - you can use the dynamic topic features.

Done right, you can combine a change node with your MQTT node to achieve it

---

<div class="post-metadata">

**Author:** ![GretaC](https://avatars.discourse-cdn.com/v4/letter/g/bb73d2/32.png) [@GretaC](https://discourse.nodered.org/u/GretaC)\
**Post date:** [29 November 2023 13:08 UTC](https://discourse.nodered.org/t/variables-in-edit-fields/83281/7 "2023-11-29T13:08:39Z")

</div>

Thank's a lot.  
@jbudd: Not really what I was looking for, but very interesting for this use case.  
I think it will make my life (the 'node-red-life') a little easier.

---

<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:** [29 November 2023 13:13 UTC](https://discourse.nodered.org/t/variables-in-edit-fields/83281/8 "2023-11-29T13:13:23Z")

</div>

Most mqtt devices i have used (shelly, tasmota etc) it is possible to edit the device name/id (0001204302303 ) to a more human readable one. Have you looked at editing the topic device name in the mqqt devices own config?

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [29 November 2023 13:14 UTC](https://discourse.nodered.org/t/variables-in-edit-fields/83281/9 "2023-11-29T13:14:37Z")

</div>

You can still do it.

1. Create a `global` or `flow` variable.  
use that in an `inject` node (as below, **topic** and **action** ) - set it to inject after 1s  

2. Set the MQTT to `dynamic subscription` and connect them together  

This will get you as close as possible to using a variable

---

<div class="post-metadata">

**Author:** ![GretaC](https://avatars.discourse-cdn.com/v4/letter/g/bb73d2/32.png) [@GretaC](https://discourse.nodered.org/u/GretaC)\
**Post date:** [29 November 2023 13:49 UTC](https://discourse.nodered.org/t/variables-in-edit-fields/83281/10 "2023-11-29T13:49:20Z")

</div>

@E1cid: It is not possible in my MQTT device. This makes it very uncomfortable to handle it and to track devices e.g. with MQTT explorers. Human readable information is available on the subscriber side, but it is not forwarded.

@markus-j-davis: The MQTT node has no input, so I don't know how to connect them.

ALL: The wildcard of MQTT is at the end a fairly nice solution. Together with a function node to filter the device coming out of the 'topic' it will be a really good solution. 'good' because it can end up in a structured piece of code and all links between intransparent numbers and transparent names are at one place.

Thank's a lot!!

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [29 November 2023 13:51 UTC](https://discourse.nodered.org/t/variables-in-edit-fields/83281/11 "2023-11-29T13:51:03Z")

</div>

> [@GretaC](#):
>
> The MQTT node has no input, so I don't know how to connect them.

You seem to have a work around now, but for info, the MQTT nodes reveal an input when set to dynamic.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [29 November 2023 14:03 UTC](https://discourse.nodered.org/t/variables-in-edit-fields/83281/12 "2023-11-29T14:03:44Z")

</div>

Be aware that subscribing to a wildcard topic might result in **a lot** of extra message processing.

What are these sensor devices? A link would be interesting.

---

<div class="post-metadata">

**Author:** ![GretaC](https://avatars.discourse-cdn.com/v4/letter/g/bb73d2/32.png) [@GretaC](https://discourse.nodered.org/u/GretaC)\
**Post date:** [29 November 2023 16:38 UTC](https://discourse.nodered.org/t/variables-in-edit-fields/83281/13 "2023-11-29T16:38:42Z")

</div>

... Yes. Really a lot. And these data come in if any value changes.

So I changed my mind: marcus' hint works fine. And in combination with a subflow and drop down menus it's perfect. There is still only one location to map devices an functions and a very good usability.

Learn from the best.

---

<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:** [28 January 2024 16:39 UTC](https://discourse.nodered.org/t/variables-in-edit-fields/83281/14 "2024-01-28T16:39:37Z")

</div>

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