Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use a variable's value to create a dynamic MQTT subscription topic?
#1
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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)