Virtuino Forum
How to use a variable's value to create a dynamic MQTT subscription topic? - Printable Version

+- Virtuino Forum (https://virtuino.com/forum)
+-- Forum: Virtuino (https://virtuino.com/forum/forumdisplay.php?fid=1)
+--- Forum: Virtuino IoT (https://virtuino.com/forum/forumdisplay.php?fid=2)
+--- Thread: How to use a variable's value to create a dynamic MQTT subscription topic? (/showthread.php?tid=22333)



How to use a variable's value to create a dynamic MQTT subscription topic? - spidgrou - 09-19-2025

Hello everyone,
I'm trying to create a dynamic MQTT subscription topic that is built using the value from another variable, but I can't seem to find the correct syntax.
Here is my setup:
  1. I have a variable (ID: C2_V0) that successfully reads a device's serial number from an MQTT topic. Let's say the serial number it reads is "MySerialNumber123". This works perfectly.

  2. I have a second variable (e.g., "Charger Current") that needs to subscribe to a topic that includes this serial number. The topic structure I need is: Y/<serial_number>/AC/CHARGER/Current.

To achieve this, I tried to set the subscription topic for my second variable like this:
Y/$C2_V0.value/AC/CHARGER/Current

However, this doesn't work. It seems the app is not replacing $C2_V0.value with the actual serial number ("MySerialNumber123"). It treats it as a literal string.
Is it possible to dynamically build a subscription topic using the value of another variable? If so, what is the correct syntax I should use?
Thank you for your help