I have a device with 8 channels I am controlling from Node-Red. I have setup 8 seperate flows called Ch1, Ch2, Ch3...Ch8. In those flows I named all my flow variables somethingCh1, somethingCh2, etc. I manually created the groups to contain the UI nodes from each flow and called those "groupCh1", "groupCh2", etc. I then got the id for each of those groups.
Now I can work on the flow for Ch1 and save it to a file on my laptop and I have a python script go through and find/replace anything "Ch1" and change it to "ChX" and change the corresponding group Ids.
Maybe there is a much better way, I am not sure, but it's pretty quick except for the next part when I have to go and delete all the flows and paste in the code from each flow 7 times (Ch1 is already in there so I have to delete Ch2-8 and paste Ch2-8). My knowledge of working with json is extremely limited, but it must be possible to combine all of these into one file that I can just paste because Node-Red already has the option to export "All Flows" as one file. Also, if I didn't have to manually create the UI groups that would be great, but there are only 8 of them and I only have to do this one time, so no big deal...until I have a device with 100 channels...
On a simpler Node-Red with just two flows, I tried a couple things with Python, but just ended up with an unusable file. Here is my attempt:
import json
import glob
result =
for f in glob.glob("C://Users//Desktop//python_json_practice//*.txt"):
with open(f, "rb") as infile:
result.append(json.load(infile))
with open("C://Users//Desktop//python_json_practice//merged_file.json", "w") as outfile:
json.dump(result, outfile)
When I try to paste this file I get: Error: Input not a valid flow - item 0 missing 'id' property
I really had no expectation the python script would actually work, so if anyone has any hints that would be great! Here is a partial output from my python script. The double brackets is probably the first hint something didn't go right.
[[{"id": "3cd6636b.34b4cc", "type": "tab", "label": "Flow 1", "disabled": false, "info": ""},