change a flow.variable ("device1" or "device2", ...)
be happy
If I use "dynamic subscription", then I have to add a for all 25 info-topics and 12 command-topics for each read or write action. Can I somehow use the "MQTT in"-node with some kinda logic so, that it just replaces the second part of the topic structure?
You can't use devices/$(MY_TOPIC)/# but I think there's nothing to stop you setting MY_TOPIC to "devices/device1/#" Not sure, I don't use environment variables like that.
How many MQTT-in and out nodes do you have - one for each device or one for each topic for each device? Are you using the + and # wildcards?
Just guessing that devices/device1/infoTopicnn is for messages from the device and devices/device1/commandTopicnn is for messages sent to it?
In this case I think your topics are not well structured because an MQTT-in node subscribing to devices/device1/# will get both kinds of message. You will need some way to filter out.
It might be worth considering something like info/device1/01 ... info/device1/25 and command/device1/01 ... command/device1/12
My two Kia EV6 electric cars, same model, same API, same everything
All of which more or less work the same, but (of course) should react to different topics for both info and command. So my thinking was initially simple: copy the flows and have them only differentiate with a variable aka "device name" in the topics. (Regardless the /info/# problem, that's a side quest so to speak! ).
As I can see, the current possibilities within MQTT-nodes are not prepared for this, so I either have to stick with my copied flows and change everything accordingly on ALL the flows. or to built a sophisticated entry for my both use cases, whithin one flow and distinguish the flows there. First one is kinda dull, because in case of changes, I'll have to do them in ALL as I said. Second one is kinda heavy-lifting to avoid changing them all.....
After thinking about it for a moment. I did the following:
added the environment variable for each flow adding the name of the device to the flow
adding a function to build the writing and/or listening topics after each flow start
injecting the names to the "mqtt in"-nodes and used them for the "mqtt out" ones.
So I'm happy... for now, because I noticed, the node-red-contrib-bluelinky nodes for the car don't allow for dynamic subscription of cars ... yet. So, I do have to change each "car action" nevertheless per flow. But my logic is now able to use variables, which is good. No more messing around with JS-code nodes. at least that. Thanks for your help!